[antlr-interest] generated code not compilable.
praveen_c
praveen_c at yahoo.com
Tue Oct 29 08:36:37 PST 2002
For some reason when I use the charVocabulary option in the following
grammar, I get code that CANNOT be compiled. When I remove it, I get
compilable code. Is there something wrong in the grammar?
Any help would be greatly appreciated. Comments on the grammar are
welcome.
---------------------------GRAMMAR FILE-------------------------------
header { package tom; }
class SimpleParser extends Parser;
template: (TEXT | TAG)+;
class SimpleLexer extends Lexer;
options {
k=2;
testLiterals=false;
charVocabulary = '\3'..'\377' | '\u1000'..'\u1fff';
}
{
public boolean isEndOfText() throws antlr.CharStreamException {
char char1 = LA(1);
if (char1 == '<') {
char char2 = LA(2);
if (char2 == '@') { // "<@"
return true;
} else if (char2 == '/') { // "</"
//ignore any white space
int i = forwardToNonWhiteSpace(3);
if (
(LA(i++) == 'l') &&
(LA(i++) == 'o') &&
(LA(i++) == 'o') &&
(LA(i++) == 'p')
) {
//match whitespace.
i = forwardToNonWhiteSpace(i);
if (LA(i++) == '>') { // "</loop>"
return true;
} else {
return false;
}
} else {
return false;
}
} else { // it began with '<' but doesn't have anything
meaningful after that.
return false;
}
} else if (char1 == EOF_CHAR) { //End-of-file reached, can't
proceed further.
return true;
} else { //doesn't begin with '<', so it's a normal char, not
a special one.
return false;
}
}
public int forwardToNonWhiteSpace(int i) throws
antlr.CharStreamException {
char c = LA(i);
while ( (c==' ') || (c == '\t') || (c == '\n') ) {
i++;
c = LA(i);
}
return i;
}
}
protected
WS : ( ' ' | '\t' | '\n' )* ;
TAG: (options
{
generateAmbigWarnings=false;
}:
"<@"
(
("include") => INCLUDE { $setType(INCLUDE); } |
("loop") => LOOP { $setType(LOOP); } |
TEXT
)
'>'
);
protected
INCLUDE: "include" ;
protected
LOOP: "loop" ;
protected
END_LOOP: "</" LOOP '>';
TEXT: (END_LOOP) => END_LOOP { $setType(END_LOOP); } |
(
options
{
generateAmbigWarnings=false;
}:
( { !isEndOfText() }? . )*
);
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list