Related articles |
---|
2 Yacc Qs zero@istar.ca (1997-03-22) |
Re: 2 Yacc Qs Bronikov@ic.net (Dmitri Bronnikov) (1997-03-23) |
Re: 2 Yacc Qs brianb@microware.com (Brian Bliss) (1997-03-27) |
From: | zero@istar.ca (Barton Jaques) |
Newsgroups: | comp.compilers |
Date: | 22 Mar 1997 23:29:51 -0500 |
Organization: | Compilers Central |
Keywords: | yacc, parse, question, comment |
1. Is there a Yacc FAQ or listserv?
--------------------
2. Specific Yacc Q:
I am building an expression grammar and having problems with associativity
and shift/reduce conflicts. The language I am emulating permits a statement
like this:
set y to items 1 thru 2 of x as string
which should be read as: "set y to (items 1 thru 2 of x) as string"
and not as: "set y to items 1 thru 2 of (x as string)"
My grammar always picks the 2nd path. The relevant rules look like this:
statement:
SET IDENT TO expression
expression:
object_specifier
| IDENT
| expression AS class
object_specifier:
object_container
| object_container of expression
| object_container of object_specifier
object_container:
class
| class expression THRU expression
The order of rules triggered (caps denote tokens passed in from Lex):
set y to item 1 thru 2 of x as string
class: CLASS // "item"
expression: INTEGER
object_container: class expression THRU expression
expression: INTEGER
expression: IDENT // next we'd want "obj_spec: obj_cont of expr" but...
class: CLASS
expression: expression AS class
object_specifier: object_container of expression
expression: object_specifier
statement: SET IDENT TO expression
I have read everything the Levine book has to say about associativity and
precedence, and I have tried all the tricks I know of reordering, defining
explicit case rules, and using %prec (although I'm not sure I use %prec
correctly).
Can anyone offer any hints or help? Thanks very much.
-----------------------------------------------------------------
Barton Jaques Zero Divide Software zero@istar.ca
[These precedence questions drive me crazy, and I have to admit that yacc
doesn't offer much help. -John]
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.