[antlr-interest] [antlr v3]: literal problem
chen jw
chen.hit at gmail.com
Fri Mar 9 18:18:17 PST 2007
HI All,
I am trying to implement a MiniJava compiler and meet trouble when I get
started with antlr v3.
rule:
exp: INTEGER_LITERAL;
INTEGER_LITERAL: '0' | '1'..'9' ('0'..'9')*;
INT : ('0' | '1'..'9' '0'..'9'*) ;
...
when I use a number that greater than 9, it's fine, but complain "no viable
alternative at input '1' " (if I use 1)
another problem is as follow:
rule:
program : mainClassDecl (classDecl)*;
mainClassDecl
: 'class' id '{'
'public' 'static' 'void' 'main' '(' 'String' '[' ']' id ')' '{'
statement
'}'
'}'
;
when I use the file below:
class Factorial {
public static void main(String[] args) {
System.out.println(new Fac().CompuFac(9));
}
}
the parser will complain: mismatched char 'F' expecting 'b'; ( I found it
want to find 'public' but not an id)
if I use CompFac instead of CompuFac, the parser won't complain.
so, I want to ask what the problem is.
Thanks,
James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070310/702c774f/attachment.html
More information about the antlr-interest
mailing list