comp.lang.ada
 help / color / mirror / Atom feed
From: "Samuel T. Harris" <sam_harris@hso.link.com>
Subject: Re: Compilers
Date: 1999/08/06
Date: 1999-08-06T00:00:00+00:00	[thread overview]
Message-ID: <37AB2D32.81D7473E@hso.link.com> (raw)
In-Reply-To: 933849270.6792@www.remarq.com

Shawn Barber wrote:
> 
>    I have been given the task of adding math functionality
> to a proprietary language we have developed. The compiler we
> wrote uses Aflex and Ayacc to create the parser and lexer. I
> have our compiler processing the math expression, it's just
> not evaluating them. So now to my question, has anyone
> accomplished this, either with Ayacc/Aflex or with a
> different Parser and Lexer generator? Thanks in advance for
> at least reading this.
> 
> Shawn
> 
> * Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
> The fastest and easiest way to search and participate in Usenet - Free!

I have done this many time with ayacc and aflex.
These tools are great for producing recognizers for any but
the simplest formats. I've used them to read in complex data
file formats, a FORTRAN to Ada translator, and various
command parsers and script languages.

To evaluate the expression, your yytype needs to include
a numeric field to hold the value at that node.
Each production involving an operator then must set
the $$ node to the result of the operation on the operands.
Something like ...

item : term d_add term
{ $$.expression := $1 + $2; }
;

... where d_add is a delimiter for '+' returned by the lexer
and expression is the field of yytype which hold expression values.
This assumes you want the operations performed as they
are recognized and are not building a parse tree for later
execution.

If you follow the example of expression syntax used in Ada,
the precedence of operations is naturally represented in the
syntax and no special effort if required to insure that in
1 + 2 * 3, 2 is multiplied with 3 and then 1 is added to the result.

-- 
Samuel T. Harris, Principal Engineer
Raytheon, Scientific and Technical Systems
"If you can make it, We can fake it!"




  reply	other threads:[~1999-08-06  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-05  0:00 Compilers Shawn Barber
1999-08-06  0:00 ` Samuel T. Harris [this message]
  -- strict thread matches above, loose matches on Subject: below --
1994-11-11 21:31 Compilers Dave Jackson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox