Posted By:
frigot_eric
Posted On:
Friday, October 12, 2001 03:45 AM
It could be something like that :
class JavaScriptParser extends Parser;
options {
k = 1; // tree
token lookahead
exportVocab = EDIstream; // Call its vocabulary "EDIstream"
defaultErrorHandler = false; // Don't generate parser error handlers
buildAST = true; // uses CommonAST by default
}
stream : (line)* ;
line : TAG (SEP TAG)* ENDLINE ;
class JavaScriptLexer extends Lexer;
options {
charVocabulary = '3'..'377';
exportVocab = EDIstream; // call the vocabulary "EDIstream"
k = 2; // Setting the lookahead deapth of the Lexer
}
// Space
WhiteSpace : ( ' ' | ' ' | 'f'
| ( "
" // DOS.
| '
' // Macintosh.
| '
' // Unix.
)
{ newline(); }
)
{ _ttype = Token.SKIP; } // to skip it.
;
ENDLINE : '~' { System.out.println("ENDLINE"); } ;
SEP : '*' { System.out.print("SEP"); } ;
TAG : ( ~('~' | '*' | ' ' | ' ' | '
' | '
' | 'f' ) )+
{ System.out.print("TAG("+$getText+")"); }
;