[antlr-interest] Returning from a sub-parser with no end token.

Remi Koutcherawy remi.koutcherawy at wanadoo.fr
Fri Dec 28 01:50:20 PST 2001


OK, looking at the generated code, I found a solution.
Rather simple, just four added lines of code, works well even with AST.

Nevertheless I feel awkward to reference "parse_AST" which is a variable in the generated code not
declared in the grammar, clumsy also to throw an exception and catch another ;-)

Any other idea ?
Albeit modifying the generator to add a new option to generate such a behavior can be considered.

Rémi Koutcherawy
_____________________

// B parser ------
class B_Parser extends Parser;
options {
 buildAST=true;
}
parse: (B)+ (BBB!)?
  ;
exception catch [antlr.TokenStreamException ex]
 { parse_AST = (AST)currentAST.root; }

// B lexer ------
class B_Lexer extends Lexer;
options {
 filter = WS;
 k =2;
}
BBB: "BBB"
 ;
B: 'b'
 ;
protected
WS: (' ' | '\t' | ('\n' | '\r' |"\r\n") {newline();} )
 { _ttype = Token.SKIP; }
 ;
exception catch [NoViableAltForCharException ex]
 { throw new CharStreamException("EndToken"); }


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list