[antlr-interest] Lexer Problem: Double meaning of single quot
e character
mzukowski at yci.com
mzukowski at yci.com
Tue May 7 09:21:34 PDT 2002
Maybe the easiest way would be to add a lookback buffer. Something like the
class below. It works for k=1. If you need k=2 or higher then let me look
at the complete lexer to see if it will work. At k=2 antlr was ignoring the
synpred because it had stuff in LA(2) to disambiguate with, but I'm not sure
if it was a bug or artifact of having this tiny toy grammar.
class MatlabLexer extends Lexer;
options
{
k = 1;
}
{
int lastMatched=null;
protected Token makeToken(int t)
{
if ( t != Token.SKIP) {
lastMatched=t;
}
Token tok = (Token) super.makeToken(t);
return tok;
}
protected bool transposePrefixMatched()
{
return lastMatched=RPAREN | lastMatched=IDENT;//etc.
}
}
RPAREN : ')' ;
STRING_LITERAL
: ('\'')=>{transposePrefixMatched()}? '\'' {$setType(TRANSPOSE);}
| '\'' (~'\'')* '\''
;
Monty
www.codetransform.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list