| Refresh | Home EGTry.com

tree of a function and its argments



Input example

 function(arg1,arg2,arg3)


expected output tree



Approach 1. Tree construction by operators

grammar TreeConstruct;
options 
{
  output=AST;
}



prog: 
   'function'^ '('! argv ')'!;

argv:
  ARG (','! ARG)*;

ARG:
   'arg' ('1'|'2'|'3'|'4');


WS: (' '|'\r'|'\n') {$channel=HIDDEN;};



Approach 2. Tree construction by rewrite

grammar TreeConstruct;
options 
{
  output=AST;
}



prog: 
   'function' '(' argv ')'-> ^('function' argv);

argv:
  ARG (',' ARG)* -> (ARG)+;

ARG:
   'arg' ('1'|'2'|'3'|'4');


WS: (' '|'\r'|'\n') {$channel=HIDDEN;};