[antlr-interest] Cannot find symbol stuff
Herumor
herumor at fastwebnet.it
Wed Aug 2 09:47:16 PDT 2006
Hello, since my professor wants the lexer into a file and the parser
into another one I did so.
I added importVocab = "EasyJava" in the parser and exportVocab =
"EasyJava" in the lexer.
I read at some tutorials to learn how changing the type of a token or an
expression just for that rule, but when I do so I get this error.
/
C:\Documents and
Settings\spotted\Documenti\grammatica\codice_generato>javac *.j
ava
EasyJavaLexer.java:485: cannot find symbol
symbol : variable DOT
location: class EasyJavaLexer
_ttype = DOT;
^
EasyJavaLexer.java:500: cannot find symbol
symbol : variable DEC_NUMBERS
location: class EasyJavaLexer
_ttype = DEC_NUMBERS;
^
2 errors
C:\Documents and Settings\spotted\Documenti\grammatica\codice_generato>
/The following is the lexer:
/*************************************************
*
*
* EASY JAVA
LEXER *
*
*
*************************************************/
class EasyJavaLexer extends Lexer;
options {
charVocabulary='\3'..'\377';
exportVocab=EasyJava; // call the vocabulary "EasyJava"
testLiterals=false; // don't automatically test for literals
k=5; // lookahead
}
IDENTIFIER
options {testLiterals=true; generateAmbigWarnings=false;}
: ('a'..'z'|'A'..'Z'|'_'|'$') ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'$')*
;
NUMBERS : ('0' | '1'..'9' ('0'..'9')*) ('.' {_ttype = DOT;} ('0'..'9')+
{$setType(DEC_NUMBERS);})? ;
// OPERATORS
QUESTION options { paraphrase="?"; } : '?' ;
LRBRACK options { paraphrase="("; } : '(' ;
RRBRACK options { paraphrase=")"; } : ')' ;
LSBRACK options { paraphrase="["; } : '[' ;
RSBRACK options { paraphrase="]"; } : ']' ;
LCBRACK options { paraphrase="{"; } : '{' ;
RCBRACK options { paraphrase="}"; } : '}' ;
COLON options { paraphrase=":"; } : ':' ;
COMMA options { paraphrase=","; } : ',' ;
LNOT options { paraphrase="!"; } : '!' ;
INC options { paraphrase="++"; } : "++" ;
DEC options { paraphrase="--"; } : "--" ;
MOD options { paraphrase="%"; } : '%' ;
SEMI options { paraphrase=";"; } : ';' ;
// ARITHMETIC OPERATORS
DIV : '/' ;
PLUS : '+' ;
MINUS : '-' ;
MUL : '*' ;
// LOGICAL OPERATORS
LAND options { paraphrase="&&"; } : "&&" ;
LOR options { paraphrase="||"; } : "||" ;
// RELATIONAL OPERATORS
LTE options { paraphrase="<="; } : "<=" ;
LT options { paraphrase="<;"; } :
'<' ;
GTE options { paraphrase=">="; } : ">=" ;
GT options { paraphrase=">"; } : '>'
;
// ASSIGN OPERATORS
ASSIGN options { paraphrase="="; } : '=' ;
BAND_ASSIGN options { paraphrase="&="; } : "&=" ;
BOR_ASSIGN options { paraphrase="|="; } : "|=" ;
BXOR_ASSIGN options { paraphrase="^="; } : "^=" ;
SL_ASSIGN options { paraphrase="<<="; } : "<<=" ;
BSR_ASSIGN options { paraphrase=">>>="; } : ">>>=" ;
SR_ASSIGN options { paraphrase=">>="; } : ">>=" ;
MOD_ASSIGN options { paraphrase="%="; } : "%=" ;
MUL_ASSIGN options { paraphrase="*="; } : "*=" ;
DIV_ASSIGN options { paraphrase="/="; } : "/=" ;
MINUS_ASSIGN options { paraphrase="-="; } : "-=" ;
PLUS_ASSIGN options { paraphrase="+="; } : "+=" ;
// BITWISE OPERATORS
BXOR options { paraphrase="^"; } : '^' ;
BOR options { paraphrase="|"; } : '|' ;
BAND options { paraphrase="&"; } : '&' ;
BNOT options { paraphrase="~"; } : '~' ;
// EQUALITY OPERATORS
EQUAL options { paraphrase="=="; } : "==" ;
NOT_EQUAL options { paraphrase="!="; } : "!=" ;
// SHIFT
SR options { paraphrase=">>"; } : ">>" ;
BSR options { paraphrase=">>>"; } : ">>>" ;
SL options { paraphrase="<<"; } : "<<" ;
// Whitespace -- ignored
WS : ( ' '
| '\t'
| '\f'
// handle newlines
| ( options {generateAmbigWarnings=false;}
: "\r\n" // Evil DOS
| '\r' // Macintosh
| '\n' // Unix (the right way)
)
{ newline(); }
)+
{ _ttype = Token.SKIP; }
;
// Single-line comments
SL_COMMENT
: "//"
(~('\n'|'\r'))* ('\n'|'\r'('\n')?)
{$setType(Token.SKIP); newline();}
;
// multiple-line comments
ML_COMMENT
: "/*"
(
options {
generateAmbigWarnings=false;
}
:
{ LA(2)!='/' }? '*'
| '\r' '\n' {newline();}
| '\r' {newline();}
| '\n' {newline();}
| ~('*'|'\n'|'\r')
)*
"*/"
{$setType(Token.SKIP);}
;
// character literals
CHAR_LITERAL
: '\'' ( ESC | ~('\''|'\n'|'\r'|'\\') ) '\''
;
// string literals
STRING_LITERAL
: '"' (ESC|~('"'|'\\'|'\n'|'\r'))* '"'
;
// Sequenza di escape -- viene utilizzato il flag protected in modo
che questa regola sia visibile solo all'interno del lexer
protected
ESC
: '\\'
( 'n'
| 'r'
| 't'
| 'b'
| 'f'
| '"'
| '\''
| '\\'
| '0'..'3'
(
options {
warnWhenFollowAmbig = false;
}
: '0'..'7'
(
options {
warnWhenFollowAmbig = false;
}
: '0'..'7'
)?
)?
| '4'..'7'
(
options {
warnWhenFollowAmbig = false;
}
: '0'..'7'
)?
)
;
----------------------------------------------------------------
I get the problem either using $settype or _ttype.
Thanks forward for help.
More information about the antlr-interest
mailing list