|
| How do you rewrite/convert lex grammars that include states to ANTLR?
There is a simple example in the ANTLR documentation, but it is not
clear to me how to convert a grammar similar to the following.
This is a snippet from VCD parser from Maarten Ditzel.
%x text
%{
%}
s [[:space:]]
%%
<INITIAL>{s}+ { /* skip whitespace */ }
\$comment { BEGIN(text); return TK_COMMENT; }
\$version { BEGIN(text); return TK_VERSION; }
<text>\$end { BEGIN(INITIAL); return TK_END; }
<text>. { yylineno--; yymore(); }
<text>\n { yylineno--; yymore(); }
<text>./\$end { sval = yytext; return TK_TEXT; }
<text>\n/\$end { sval = yytext; return TK_TEXT; }
Basically I am trying to parse something like:
$comment
any character here
including CR/LF
$end
$version
any character here
including CR/LF
$end
There are a lot more states in this grammar, but it would be
appreciated if anyone has hints for converting this snippet of the
grammar.
Thanks,
-- Amal
|
|