Semantic actions in Yacc ?

frazerw@dseg.ti.com (Frazer Worley, #909980 DAD)
Thu, 2 Mar 1995 14:11:12 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: frazerw@dseg.ti.com (Frazer Worley, #909980 DAD)
Keywords: yacc, question
Organization: Texas Instruments
Date: Thu, 2 Mar 1995 14:11:12 GMT

First up, I have a limited knowledge of compilers and so please
forgive me if this is a dumb question.


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
the grammar, as I do not yet know where I'll need semantic checks and
where I won't.


eg. Consider a binary grammar.


grammar : { SemanticBlk1() ; } digits { SemanticBlk2() ; }
                                  ;


digits : /* empty */
                                  | {} digits {} digit {}
                                  ;


digit : {} ZERO_TOK {}
                                  | {} ONE_TOK {}
                                  ;


    Now this causes reduce/reduce conflicts in Yacc. Is there a way to
avoid this ? Or is there a better way to add semantic actions ?


    I think I can translate this defn. into LL1 and generate a recursive
descent parser - which won't have problems with the semantic actions.
However - this would be a real undertaking for my target language
[>300 productions] - so I was wondering whether an application exists
to do this already - yacc2rdp or something ?


    Or, is there another compiler generator which I could use instead
of Yacc which would enable me to do what I want ?


    Any suggestions welcome,


Thanks,


    Frazer


---


---------------------------------------------------------------------
Phone: 214-997-5557 Email: frazerw@daldd.sc.ti.com
Address: MS 8316, TI_MSGID: FJ
                    Texas Instruments,
                    8330 LBJ Freeway, 75243
                    Dallas, Tx.
--


Post a followup to this message

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