Re: Writing an interpreter with Flex?
24 May 2004 00:20:49 -0400

          From comp.compilers

Related articles
Writing an interpreter with Flex? (2004-05-16)
Re: Writing an interpreter with Flex? (2004-05-24)
| List of all articles for this month |

Newsgroups: comp.compilers
Date: 24 May 2004 00:20:49 -0400
Organization: Compilers Central
References: 04-05-048
Keywords: interpreter, lex
Posted-Date: 24 May 2004 00:20:49 EDT

On Sun, May 16, 2004 at 11:34:33PM -0400, wrote:
> Hi Every1

> please help me.
> Actually i'm writing a convertor for SystemC to verilog. And i'm using
> FLEX for the same. The problem i'm facing is:
> to create disable block. how can i go back into source code if
> FLEX find the TOKEN "break"[ \t]";" . And please suggest me how to
> handle nested loops. As i have to convert first '{' to begin and last
> '}' to end for every loop/switch case.

Frankly, though I'm not quite sure what exactly it is you're trying to
do, I'm getting the feeling that you're trying to do the impossible.
Flex (I assume you're talking of Flex the GNU Lex), can only recognize
regular languages. That means that block structures, such as your
nested loops, are impossible for it to recognize on its own. You need
to go at least one rung up the Chomsky hierarchy and use something
like a CFG at the very least, and for that you need Bison or Yacc.

My advice is learn how to use Bison in addition to Flex. The task
you're doing is impossible for Flex by itself, unless you write your own
recursive descent parser that reads tokens that Flex gives you. Most of
the time it would be easier to just use Bison or Yacc instead.

Post a followup to this message

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