grammar question

saleem@synopsys.com (Saleem Haider)
14 Mar 1996 17:26:43 -0500

          From comp.compilers

Related articles
Grammar question feingold@avette.zko.dec.com (1994-09-20)
Re: Grammar question euambn@eua.ericsson.se (1994-09-22)
Re: Grammar question clark@zk3.dec.com (Chris Clark USG) (1994-09-26)
Re: Grammar question umrigar@cs.binghamton.edu (Zerksis D. Umrigar) (1994-09-28)
grammar question saleem@synopsys.com (1996-03-14)
| List of all articles for this month |

From: saleem@synopsys.com (Saleem Haider)
Newsgroups: comp.compilers
Date: 14 Mar 1996 17:26:43 -0500
Organization: Synopsys, Inc.
Keywords: yacc, parse, question

I need some pointers on how to write the grammar for expressions
that allow implied products, e.g. "a + b c + d" is "a + b*c +d"
and "(a + b) !c" is "(a + b) * (!c)". The regular cases are
handled by


%left '+'
%left '*'
exp: '(' exp ')'
| exp '+' exp
| exp '*' exp
;


I'd like to be able to add a rule like "| exp exp %prec MUL"
but that doesn't work.


I'd appreciate any pointers. I can use either yacc or bison.


Saleem
[Try this:


%left '+'
%left '*'
%token TOKEN
%%
bigexp:
exp | bigexp exp ;


exp: '(' exp ')'
| exp '+' exp
| exp '*' exp
                | TOKEN
;


-John]


--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.