help-bison
[Top][All Lists]
Advanced

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

Re: yacc parser


From: Frank Heckenbach
Subject: Re: yacc parser
Date: Fri, 9 Apr 2004 22:44:41 +0200
User-agent: semail 20040101

gavaneh wrote:

> I am working to design an interpreter with
> yacc.Unfortunately I've faced to a problem with the
> action
> of the following rule.
> 
> "repeat  :REPEAT stmt_seq UNTIL exp"
> 
> How can I say to repeat stmt_seq if exp is true.

(I suppose you mean repeat as long as it's false -- until it's
true.)

The nice thing with interpreters is that many constructs map to the
same constructs in the implementation language. If this is C, the
repeat loop corresponds to `do ... while' (with negated condition),
so you'd do something like this:

  do
    evaluate_stmt_seq ($2);
  while (!evaluate_exp ($4));

This assumes, of course, that you have suitable routines to evaluate
statements and expressions (which correspond to the other parts of
the grammar in the same way) and the corresponding rules build the
respective data structures.

Frank

-- 
Frank Heckenbach, address@hidden
http://fjf.gnu.de/
GnuPG and PGP keys: http://fjf.gnu.de/plan (7977168E)




reply via email to

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