Re: Semantic actions in Yacc ?

C.A.Elliott@dcs.warwick.ac.uk (Charles Elliott)
Mon, 6 Mar 1995 13:43:53 GMT

          From comp.compilers

Related articles
Semantic actions in Yacc ? frazerw@dseg.ti.com (1995-03-02)
Re: Semantic actions in Yacc ? c1veeru@WATSON.IBM.COM (Virendra K. Mehta) (1995-03-03)
Re: Semantic actions in Yacc ? parrt@parr-research.com (Terence John Parr) (1995-03-04)
Re: Semantic actions in Yacc ? C.A.Elliott@dcs.warwick.ac.uk (1995-03-06)
Re: Semantic actions in Yacc ? clark@quarry.zk3.dec.com (1995-03-06)
Re: Semantic actions in Yacc ? caibmnfx@ibmmail.com (Parag V. Tijare) (1995-03-08)
| List of all articles for this month |

Newsgroups: comp.compilers
From: C.A.Elliott@dcs.warwick.ac.uk (Charles Elliott)
Keywords: yacc
Organization: Department of Computer Science, Warwick University, England
References: 95-03-023
Date: Mon, 6 Mar 1995 13:43:53 GMT

frazerw@dseg.ti.com writes:
>I want to add semantic actions to a Yacc parser. The way I'd considered
>of doing this is to add actions before and after each nonterminal in
>digit : {} ZERO_TOK {}
> | {} ONE_TOK {}
> ;


I'll just leave this one example. The problem that occurs is due to the
way that Bison actually creates this rule. A seperate nonterminal is created
for the first semantic action in the rule. Now before it has read any input,
(but a digit is expected), Bison has to execute a semantic action, as it is
placed before the rule. However, either one of these is possible, and a
reduce/reduce conflict is created.


To avoid this
1) Don't put semantic actions before rules -- BEST METHOD
2) Do something like this


digit : { semantic action } digit2
digit2 : ZERO_TOK { }
| ONE_TOK { }


but of course this only works if the initial semantic action is the same.


Cheers,


Charles
---
cae@dcs.warwick.ac.uk
--


Post a followup to this message

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