
www.Usenet.com
| <-- __Chronological__ --> | <-- __Thread__ --> |
I have the following very simple SableCC file:
Helpers
letter = [ '_' + [['a' .. 'z'] + ['A' .. 'Z']]];
digit = ['0' .. '9'];
cr = 13;
lf = 10;
tab = 9;
Tokens
lambda = 'lambda';
ident = letter (letter | digit)*;
blank = (9 | 10 | 13 | ' ')+;
l_par = '(';
r_par = ')';
zero = '0';
one = '1';
plus = '+';
Ignored Tokens
blank;
Productions
unit = exp+;
exp = {identifier} ident
| {lambdaexpr} [first_l]:l_par lambda [second_l]:l_par ident*
[second_r]:r_par exp [first_r]:r_par
| {exprseq} l_par exp+ r_par
| {zero} zero
| {one} l_par plus exp one r_par;
And this is the translation to ANTLR I have so far:
class SubSchemeParser extends Parser;
options {
buildAST=true;
}
unit : (exp)+;
exp : IDENT
| LPAREN "lambda" LPAREN IDENT* RPAREN exp RPAREN
| LPAREN exp+ RPAREN
| ZERO
| LPAREN PLUS exp ONE RPAREN;
class SubSchemeLexer extends Lexer;
DIGIT : '0'..'9';
LPAREN : '(';
RPAREN : ')';
ZERO : '0';
ONE : '1';
PLUS : '+';
IDENT : ID_START_LETTER ( ID_LETTER )*
;
protected
ID_START_LETTER
: '_'
| 'a'..'z'
| 'A'..'Z'
;
protected
ID_LETTER
: ID_START_LETTER
| '0'..'9'
;
// Whitespace -- ignored
WS
: ( ' '
| '\t'
| '\f'
// handle newlines
| ( "\r\n"
| '\r'
| '\n'
)
{ newline(); }
)
{ $setType(Token.SKIP); }
;
However on the seconde option of 'exp' I get these errors:
-rule classDef trapped
-unexpected token: IDENT
And I just cannot figure it out.
Is there anyone who can?
Thanks in advance.
PS if anyone is very good at ANTLR, maybe he/she could help get a good
translation. I need it for testing and comparison.
| <-- __Chronological__ --> | <-- __Thread__ --> |