Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] A util for expression evaluation in CDT?

Hi all, 

A quick update. I ended up using the javascript engine for expression evaluation that is part of the JDK1.6

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
Double d = (Double)engine.eval("1+2*3");

Hope it is portable across platforms.

Thanks,
Andrey

-----Original Message-----
From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Ayupov, Andrey
Sent: Tuesday, May 06, 2014 8:29 AM
To: CDT General developers list.
Subject: Re: [cdt-dev] A util for expression evaluation in CDT?

Hi Nathan, 

It is the former of the two you suspected. I am writing a plugin that creates a special purpose data model from C++ code and I need to create an array representation of a C++ array in that data model. An array size in C++ can be represented by a constant expression, but in my data model, I actually need to create objects for every element of the array, so I need to evaluate its size. 

There are a few suggestions you guys already sent - I'll take a look at those now. Thanks a lot!

Andrey

-----Original Message-----
From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Nathan Ridge
Sent: Monday, May 05, 2014 9:14 PM
To: CDT Mailing List
Subject: Re: [cdt-dev] A util for expression evaluation in CDT?

Hi Andrey,

> I need to evaluate a constant expression that is used to specify a 
> size of an array in C. I have variable substitutions with constant 
> values done and have a string of form "1+2*3". Is there a utility in 
> CDT I can use to evaluate the result of such expression?

It's not clear to me what you are asking.

Are you writing a plugin, and asking how to evaluate an expression using the CDT API?

Or are you asking how can you, as a user of CDT, evalaute an expression in the editor?

Regards,
Nate
 		 	   		  
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev


Back to the top