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: Wed, 6 Feb 2002 12:46:16 +0100

[Also see the reply by "Anthony DeRobertis" <address@hidden>.

At 11:48 +0100 2002/02/06, Matthew Tedder wrote:
>The main thing I'm looking for is how the designers of lex and yacc intended
>one to design a compiler/interpreter that has looping constructs such as
>while, for, and goto/labels?

This we have already told: Let the Bison actions build a closure that later
can be executed.

>Other than using an intermediate code, how can one make the execution of
>statements jump to a specified point?

You can't using Bison. So if you want to do that, do not use Bison/Yacc or
something like that.

But one is not using your approach, because it is inefficient: It is much
more efficient to first parse the whole loop statement, build a closure for
that and then execute it. Even in the seventies, when I had a Basic
interpreter for my 6800 SWTPC micro-computer, it built an intermediate
representations of the Basic code. So I am not sure one ever builds what
you try to do.

In addition, you get the chance of catching any errors before the
evaluation takes place. With your approach, if the statement is
syntactically wrong in the midst of the loop, it would start execute, and
leave the program in a wrongful state (if it manipulates some global,
program independent variables).

  Hans Aberg





reply via email to

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