[antlr-interest] help needed with nondeterminism errors. Thanks in advance!

Sharon Li hushlee83 at yahoo.com.sg
Wed Feb 19 23:46:05 PST 2003


the error occured at the modules rule 
*apologies*
 Sharon Li <hushlee83 at yahoo.com.sg> wrote:
sorry guys I just realized to my horror that I've not stated the error : 
ANTLR Parser Generator   Version 2.7.0   1989-2000 MageLang's jGuru.com
lfile.g.txt:426: warning: nondeterminism upon
lfile.g.txt:426: k==1:DIGIT,SEMI,COMMA,ASSIGN,ALPHA,PLUS,MINUS,DIVIDE,MOD
,POW,NOT,LOGOR,LOGAND,EQUAL,QUESTION,DOT,AND,UNDERSCORE,OYIELD,YIELD
lfile.g.txt:426: k==2:DIGIT,SEMI,COMMA,ASSIGN,LPAREN,ALPHA,PLUS,MINUS,DIV
IDE,MOD,POW,NOT,LOGOR,LOGAND,EQUAL,QUESTION,DOT,AND,UNDERSCORE,OYIELD,YIELD
lfile.g.txt:426: between alt 1 and exit branch of block 
Cheers,
Sharon 
 Sharon Li <hushlee83 at yahoo.com.sg> wrote: 
Hello all,

Could anyone please help me with some nondeterminism errors?
Thanks in advance!

/******** fraction of parser *********************/
/**NOTE: Pls ignore the returning of values coz thats already handled *****/
/**Sorry for pasting in such a huge chunk of code =P **/

productions : (production)+;

production : strictPred conditional (YIELD | OYIELD) successor;

strictPred : formalModules;

formalModules: formalModule+;

formalModule : ((symbol)  (LPAREN formalParameters RPAREN)) => (symbol)  (LPAREN formalParameters RPAREN)
                   | symbol ;

formalParameters : formalParameter (COMMA formalParameter)*;

formalParameter : NAME;

conditional : COLON condition;

condition : (TIMES) => TIMES
            | expression
            ;
successor : modules
                | (TIMES) => TIMES ; 

symbol returns [String sym] {sym = null;} 
   : d:DIGIT
   {
    System.out.println("Symbol is: "+d.getText());
    sym = d.getText();
   }
   | a:ALPHA
   {
    System.out.println("Symbol is: "+a.getText());
    sym = a.getText();
   }
   | (DOT {sym=".";}) | (COMMA {sym=",";})| (SEMI {sym=";";})
   | (PLUS {sym="+";}) | (MINUS{sym="-";}) | (NOT{sym="!";}) | (DIVIDE{sym="/";}) | (POW{sym="^";}) 
   | (MOD{sym="%";}) | (LOGOR{sym="||";}) | (AND{sym="&";}) | (LOGAND{sym="||";}) | (EQUAL{sym="==";}) 
   | (QUESTION{sym="?";}) | (UNDERSCORE{sym="_";}) | (ASSIGN{sym="=";}) 
   | (OYIELD{sym="-o>";}) | (YIELD{sym="-->";})
   ;

modules : (module)+;

module : (smbol) LPAREN (parameters) RPAREN ; 

parameters returns [String params="";]{String exp=""; String subexp="";}
     : (exp = expression {arrayCount++;}) ((COMMA{exp+=",";}) ((subexp = expression){exp+=subexp; arrayCount++;}))* 
     {
      params = exp;
      System.out.println("in parameters rule, parameters : "+params);
     }; 


number returns [String num="";]
  : ((n:NUMERIC {num = n.getText();}) | (d:DIGIT {num = d.getText();}));

word returns [String word="";]
  : ((name:NAME {word = name.getText();}) | (a:ALPHA {word = a.getText();}));


exp1 returns [String e1] {e1="";String exp="";String numb=""; String w="";}
  : (numb = number)
  {
   e1 = numb;
  }
  | (w = word)
  {
   System.out.println("name is : "+w);
   e1 = w;
  }
  | (lit : STRING_LITERAL)
  {
   String literal = lit.getText();
   e1 = literal;
   System.out.println("string literal: "+literal);
   
  }
  | (e1=function)
   {
   System.out.println("function is : "+e1);
  }
  | LPAREN (exp=expression) RPAREN
   {
   e1 = "("+ exp +")";
  }
  | /* empty */
  ;
  exception
    catch[RecognitionException e]{
   System.out.println("error occured in rule exp1 !!");
    }
  
exp2 returns [String e2="";] {String strg="";}
  : (
  ( PLUS {System.out.println("operator +"); e2 += "+";}
  | MINUS {System.out.println("operator -"); e2 += "-";}
  | TIMES {System.out.println("operator *"); e2 += "*";}
  | DIVIDE {System.out.println("operator /"); e2 += "/";}
  | MOD {System.out.println("operator %"); e2 += "%";}
  | POW {System.out.println("operator ^"); e2 += "^";}
  | (NOT {System.out.println("operator !"); e2 += "!";}) (ASSIGN{System.out.println("operator !="); e2 = "!=";} )?
  | LOGOR {System.out.println("operator ||"); e2 += "||";}
  | LOGAND {System.out.println("operator &&"); e2 += "&&";}
  | EQUAL {System.out.println("operator =="); e2 += "==";}
  | LT {System.out.println("operator <"); e2 += "<";}
  | GT {System.out.println("operator >"); e2 += ">";}
  | LTE {System.out.println("operator <="); e2 += "<=";}
  | GTE {System.out.println("operator >="); e2 += ">=";}
  | QUESTION {System.out.println("operator ?"); e2 += "?";})  
  (strg=exp1{e2+=strg;}) ((COLON{e2 += ":";}) (strg=exp1{e2 += strg;}))? (strg=exp2{e2 += strg;}))* ;
  exception
    catch[RecognitionException e]{
   System.out.println("error occured in rule exp2 !!");
    }

expression returns [String expression="";]{String expre1=""; String expre2="";}
  : (expre1=exp1) (expre2=exp2) 
  {
   expression = expre1 + expre2;
  };
  exception
    catch[RecognitionException e]{
   System.out.println("error occured in rule expression !!");
    }

/**** fraction of lexer ****/

ALPHA  : ( 'a'..'z' | 'A'..'Z' ); 

DIGIT : ('0'..'9');

NUMERIC : DIGIT ((DIGIT)+ | ((DOT) (d:DIGIT)+)) ;

NAME : (ALPHA) (ALPHA|DIGIT|UNDERSCORE)+ ;

STRING_LITERAL : '"'! ('"' '"'! | ~('"'))* '"'!


 

 

 Yahoo! Biztools
- Promote your business from just $5 a month! 
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 


 Yahoo! Biztools
- Promote your business from just $5 a month! 
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 


 Yahoo! Biztools
- Promote your business from just $5 a month!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20030220/aececfc7/attachment.html


More information about the antlr-interest mailing list