mageran / node-xsyn

Extensible syntax for nodejs - under construction
0 stars 1 forks source link

Defining associativity and precedence #4

Open MandyxGill opened 8 years ago

MandyxGill commented 8 years ago

Can we write rules to define associativity and precedence in node-xsyn or do we have to write explicit grammar rules to achieve this ?

mageran commented 8 years ago

There is no support for precedence or associativity currently; you would have to code it into the grammar rules. I tried to keep the grammar language as simple as possible, sometimes for the cost of missing these kinds of features. But the tool is still evolving and I will take that as a feature request for future versions.

For arithmetic expressions it would look something like this:

ArithmeticExpression : ArithmeticExpression AddSub Term {% $$ = { operation : $2, operands : [$1,$3] }; %} | Term ;

Term : Term MultDiv Factor {% $$ = { operation : $2, operands : [$1,$3] }; %} | Factor ;

MultDiv : '*' | '/' ; AddSub : '+' | '-' ;

Factor : ident {% $$ = { ref : $1 }; %} | number {% $$ = { number : $1 }; %} | string {% $$ = { string : $1 }; %} | '(' ArithmeticExpression ')' {% $$ = $2 %} ;

On Tue, Dec 15, 2015 at 9:27 PM, mandeep6ill notifications@github.com wrote:

Can we write rules to define associativity and precedence in node-xsyn or do we have to write explicit grammar rules to achieve this ?

— Reply to this email directly or view it on GitHub https://github.com/mageran/node-xsyn/issues/4.