ANTLR and LEX states

"Amal" <>
29 Mar 2007 00:56:59 -0400

          From comp.compilers

Related articles
ANTLR and LEX states (Amal) (2007-03-29)
| List of all articles for this month |

From: "Amal" <>
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:

    any character here
    including CR/LF

    any character here
    including CR/LF

There are a lot more states in this grammar, but it would be
appreciated if anyone has hints for converting this snippet of the

-- Amal

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.