Greetings!

On Thu, 2011-08-25 at 16:00 +0400, Романов Артем wrote:
> 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)

try these:

expr    :       atom ( OPERATOR expr )? ;
atom    :       NUMBER | ID | function
        |       '(' expr ')' ;
function:       ID '(' ( expr (',' expr)* )? ')' ;

Note that in the above I have added the capability for functions to have
zero parameters......

> 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
>     |)
> 

do not know about this. does not happen with the above changes. sorry.

hope this helps...
   -jbb



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.

Reply via email to