This project has moved and is read-only. For the latest updates, please go here.

expression grammar that differentiates variables and parameters

Jan 16, 2014 at 7:38 AM
Edited Jan 16, 2014 at 9:12 AM

I would like to modify the expression grammar that comes with irony.

I would like to specialize it for linear expressions.
This means that expressions should be linear expressions with respect to the "variables".
However, the expressions do not need to be linear with respect to "parameters".
The identifiers for parameters and for variables would be known at run time, when parsing.
Typically, parameters would be defined by some assignment statement while variables would not appear in an assignment.

Is it possible to describe this in a grammar?
How can I specialize the expression grammar to linear expressions?
How could I distinguish between variables and parameters?

Jan 22, 2014 at 6:50 PM
what is 'linear expressions'?
now, at what point you need to distinguish between vars and parameters? during parsing, or after parsing in AST tree, or during execution at runtime? The easiest would be at runtime (I guess, not knowing what exactly you need). At runtime you can mark assigned values as 'parameters' in some way (save them in dictionary); you'll have to modify the language runtime and related classes for this. At parse time - have no idea, based on info you provided. Please give an example, sample source and what kind of different treatment you want (and at which stage) for vars vs params.
Jan 22, 2014 at 7:53 PM
Thanks Roman.
I realized that I could resolve parameters before parsing.
Therefore, I would enjoy to make sure that the expressions being parsed are in the form a1x1+a2x2+...
where a1 and the like would be numbers and x1 and the like would be named variables.
Of course, the expression could also be created as a11*x1a12 or a11/a12x1/a12 and so on.
Maybe this should be resolved after parsing.
Thanks again for this nice package.