From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,dab8b3efe76225ae X-Google-Attributes: gid103376,public From: "Samuel T. Harris" Subject: Re: Compilers Date: 1999/08/06 Message-ID: <37AB2D32.81D7473E@hso.link.com>#1/1 X-Deja-AN: 509681776 Content-Transfer-Encoding: 7bit References: <933849270.6792@www.remarq.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Raytheon Training Inc. Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-08-06T00:00:00+00:00 List-Id: 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!"