Why is this nondeterminism?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   claudia_sion
Posted On:   Monday, March 28, 2005 11:57 AM

I simply don't understand why this is nondeterminism: class MyParser extends Parser; options{k=1;} startRule: (DATATYPE n:NAME LPARAN (args)? RPARAN {System.out.println("("+ n.getText()+ ")");} ) ; args : arg (COMA args)*; // <-?why nondeterminism arg : datatype NAME; datatype : "void"; class MyLexer extends Lexer; LPARAN : '(' ; RPARAN : ')' ; COMA : ',' ; NAME : ('a'..'z')+ ; This    More>>

I simply don't understand why this is nondeterminism:




class MyParser extends Parser;


options{k=1;}


startRule: (DATATYPE n:NAME LPARAN (args)? RPARAN


{System.out.println("("+ n.getText()+ ")");}
) ;



args : arg (COMA args)*; // <-?why nondeterminism



arg : datatype NAME;



datatype : "void";



class MyLexer extends Lexer;




LPARAN : '('
;



RPARAN : ')'
;



COMA : ','
;



NAME : ('a'..'z')+
;




This is what ANTLR generates:





try { // for error handling



arg();




{




_loop6:




do {




if ((LA(1)==COMA)) {



match(COMA);



args();



}



else {//isn't LA(1)!=COMA a condition to exit the loop!!!!



break _loop6;



}




} while (true);



}

   <<Less
About | Sitemap | Contact