Related articles |
---|
ANTLR and LEX states akhailtash@gmail.com (Amal) (2007-03-29) |
From: | "Amal" <akhailtash@gmail.com> |
Newsgroups: | comp.compilers |
Date: | 29 Mar 2007 00:56:59 -0400 |
Organization: | Compilers Central |
Keywords: | lex, PCCTS, question |
Posted-Date: | 29 Mar 2007 00:56:59 EDT |
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
Return to the
comp.compilers page.
Search the
comp.compilers archives again.