help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loops using flex/bison..


From: Hans Aberg
Subject: Re: Loops using flex/bison..
Date: Tue, 5 Feb 2002 15:24:24 +0100

At 15:45 -0500 2002/02/05, Matthew Tedder wrote:
>  I wrote a little interpreter that's like a bucket with a big hole in the
>bottom.  I connected a flex-based lexer with a bison-based parser but don't
>know how this combination is supposed to be able to support loops?

The Bison generated parser does not back-track (ever), and in addition may
apply reductions before an error is detected, so if your idea is to step
through the text one token at a time and interpret it as you go along,
Bison is not at all suitable for that approach. -- But this is not a very
efficient approach:

>  It's a little BASIC interpreter.

A more efficient approach for Basic is to scan through the whole code, and
translate it into some intermediate binary representation that can be
interpreted.

Then you might keep track of the lines changed, and only re-compile those.
I recall a HP compiler that worked like this. -- But computers are so fast
nowadays, it may not be worth it.

>  I have some great ideas for enhancing it.
> I also thought about using flex to translate BASIC to C.

But this seems like a simple approach if you want to produce efficient
output code.

>  Would it be
>possible to turn such a thing easily into a gcc front-end?

I am not sure what you mean by "gcc front-end" here: Note however, that the
Haskell compiler GHC <http://haskell.org/> produces C as output. I write on
a compiler of my own OOPL that produces C++ as output.

The GHC compiler is tied to GCC only because it uses special GCC compiler
features. If you produce standard C/C++ as output, which I figure would be
possible with Basic, then that would not be needed.

I am not sure why you are doing this: Do you want to learn writing it, or
do want to have a Basic compiler? -- For the latter, I think it might be
already available.

You could post to the Usenet newsgroup comp.compilers, or check its FAQ (in
its monthly message). It says about Basic:

  * Where can I get a Basic grammar in yacc?

  Take a look at ftp://ftp.uu.net:/usenet/comp.sources.unix/volume2/basic/
  which contains a Basic interpreter with yacc parser.

  * Where can I get a QBasic compiler?

  Probably nowhere.  The "official" QBasic compilers were QuickBasic 4.5
  and the Microsoft Professional Development System, sometims called "QBX".
  You might still find copies at the big mail-order houses, but Microsoft
  has discontinued them.

  A shareware compiler ASIC is available from simtel mirrors such as
  ftp://ftp.simtel.net/pub/simtelnet/msdos/basic/asic500.zip, which
  handles a large subset of Qbasic.  Also see
  http://www.users.uswest.net/~sdiggins/basm.html for another freeware
  Basic compiler.

  PowerBasic and FirstBasic, commercial and shareware, respectively, from
  http://www.powerbasic.com resembles an extended QBasic.

  There's a Qbasic mailing list; send "info qbasic" to
  address@hidden for details.

  Hans Aberg





reply via email to

[Prev in Thread] Current Thread [Next in Thread]