help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: %left and precedence


From: Jonathon Duerig
Subject: Re: %left and precedence
Date: Wed, 4 Dec 2002 16:52:36 -0700 (MST)

-- Bernd Prager --
Hi,
I want words which are combined with a '-' character
interpreted with a higher priority then uncombined words.
So this is the grammar I tried:
-- /Bernd Prager --

A note beforehand. I'm not precisely sure what your grammar is striving
for. There seems to be some ambiguity. Like for instance, if you have a
statement like

word word-word word

Do you want it to be treated as

>word word<->word word<

or

>>>word< >word-word<< word<

or

>>word< >>word-word< word<<

?

I don't believe precedence will affect your grammar as it currently
stands.

This is because precedence only comes into play when there are two tokens,
both of which have a precedence defined relative to one another. Though
I'm by no means an expert in this domain, I'd try something along the
following lines:

%start statement
%%

statement: sequence {/*stuff*/}
    ;

sequence: term sequence {/*stuff*/}
    | term (/*stuff*/}
    ;

term: object '-' object {/*stuff*/}
    | object {/*stuff*/
    ;

object: /*stuff*/

=================

This would give you the third possibility I've outlined above. Open
questions remain, however, about what happens when you have a statement
like

word-word-word

or somesuch.

Hope this helps

-D




reply via email to

[Prev in Thread] Current Thread [Next in Thread]