[antlr-interest] pls help with Non-determinism error!
Sharon Li
hushlee83 at yahoo.com.sg
Sun Mar 23 16:23:43 PST 2003
Hi can someone pls help me with this non-determinism error coz Im really stuck! :P Thanks!
class LParser extends Parser;
options { k=2; }
number returns [String num=""]
: (MINUS {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();}))
;
digit_or_alpha returns [String result="";]
: (d:DIGIT {result = d.getText();}) | (a:ALPHA {result=a.getText();})
;
symbol returns [String sym] {sym = null;}
: ((sym = digit_or_alpha)
| (DOT {sym=".";}) | (COMMA {sym=",";})| (SEMI {sym=";";}) | (PLUS {sym="+";}) | (MINUS{sym="-";})
| (NOT{sym="!";}) | (DIVIDE{sym="/";}) | (POW{sym="^";}) | (MOD{sym="%";})
| (AND{sym="&";}) | (DRAW {sym="@";}) | (HEX {sym="#";}) | (QUESTION{sym="?";})
| (UNDERSCORE{sym="_";}) | (ASSIGN{sym="=";}) | (OR{sym="|";}) | (NEG{sym="~";})
| (LBRACK{sym="[";}) | (RBRACK{sym="]";})
| (LBRACE{sym="{";}) | (RBRACE{sym="}";})
| (DOLLAR{sym="$";}))
;
formalModule returns [FormalModule fm = null] {String fsymbol=""; ArrayList paramList = null;}
: (fsymbol = symbol) (LPAREN (paramList=formalParameters) RPAREN)?
;
formalModules returns [ArrayList fmList = new ArrayList()] {FormalModule fm = null;}
: (fm = formalModule {fmList.add(fm);})+ //line 67
;
formalParameter returns [String formalParam=""]
: formalParam = word
;
formalParameters returns [ArrayList params=new ArrayList()] {String fp=""; String temp="";}
: (fp = formalParameter {params.add(fp);}) ((COMMA) ((temp = formalParameter){params.add(temp);}))*
;
productions : (production)+; //line 78
production : strictPred ;
strictPred {ArrayList fms = null;}
: fms = formalModules ;
class LLexer extends Lexer;
options{
charVocabulary='\0'..'\377';
k = 2;
}
ALPHA : ( 'a'..'z' | 'A'..'Z' );
DIGIT : ('0'..'9')
;
NUMERIC : ((DIGIT)+ ('.'|'e'|'E'))=> (DIGIT)+ ('.' (DIGIT)* (EXPONENT)? | EXPONENT)
| (DIGIT) (DIGIT)+
| '.' ((DIGIT)+ (EXPONENT)?)
;
NAME : (ALPHA) (ALPHA|DIGIT|UNDERSCORE)+ ;
protected EXPONENT : ('e'|'E') ('+'|'-')? (DIGIT)+ ;
STRING_LITERAL : '"'! ('"' '"'! | ~('"'))* '"'!
;
The error that I got is :
test.g.txt:67: warning: nondeterminism upon
test.g.txt:67: k==1:MINUS,DIGIT,ALPHA,DOT,COMMA,SEMI,PLUS,NOT,DIVIDE,POW,MOD,AN
D,DRAW,HEX,QUESTION,UNDERSCORE,ASSIGN,OR,NEG,LBRACK,RBRACK,LBRACE,RBRACE,DOLLAR
test.g.txt:67: k==2:EOF,MINUS,DIGIT,ALPHA,DOT,COMMA,SEMI,PLUS,NOT,DIVIDE,POW,MO
D,AND,DRAW,HEX,QUESTION,UNDERSCORE,ASSIGN,OR,NEG,LBRACK,RBRACK,LBRACE,RBRACE,DOL
LAR,LPAREN
test.g.txt:67: between alt 1 and exit branch of block
test.g.txt:78: warning: nondeterminism upon
test.g.txt:78: k==1:MINUS,DIGIT,ALPHA,DOT,COMMA,SEMI,PLUS,NOT,DIVIDE,POW,MOD,AN
D,DRAW,HEX,QUESTION,UNDERSCORE,ASSIGN,OR,NEG,LBRACK,RBRACK,LBRACE,RBRACE,DOLLAR
test.g.txt:78: k==2:EOF,MINUS,DIGIT,ALPHA,DOT,COMMA,SEMI,PLUS,NOT,DIVIDE,POW,MO
D,AND,DRAW,HEX,QUESTION,UNDERSCORE,ASSIGN,OR,NEG,LBRACK,RBRACK,LBRACE,RBRACE,DOL
LAR,LPAREN
test.g.txt:78: between alt 1 and exit branch of block
Thanks in advance for any help rendered!
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/20030324/7bd4dda9/attachment.html
More information about the antlr-interest
mailing list