grammar formulaGrammar;
options{
backtrack=true;
}
formula : expr ;
expr : atom ( OPERATOR expr )*
| '(' expr ( OPERATOR expr )* ')' ;
atom : ( NUMBER | ID | function ) ;
function: ID '(' ( expr ',' )* expr ')' ;
NUMBER : ( INT | FLOAT );
fragment INT : '0'..'9'+ ;
fragment FLOAT : ('0'..'9')+ '.' ('0'..'9')* ;
ID : ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ;
OPERATOR: ('+'|'-'|'*'|'/'|'^');
WS : ( ' ' | '\t' ) {$channel=HIDDEN;} ;
This grammar is work, but can i do this without backtracking(without
backtracking not compiling)?
sampleinput: func(p1,func2(p1,func4(b)),p3)
And i can not understand why from "sqrt(a)" input grammer return this parse
tree:
-formula
-expr
-atom
-function
|sqrt
|(
-expr
-atom
|a
-expr
-atom
|a
|)
instead:
..
|sqrt
|(
-expr
-atom
|a
|)
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.