help-bison
[Top][All Lists]
Advanced

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

Re: Parsing a strange list


From: Axel Kittenberger
Subject: Re: Parsing a strange list
Date: Tue, 14 Aug 2001 23:04:42 +0200

On Tuesday 14 August 2001 20:16, Joris Esch wrote:
> Hello all:
>
> I have a problem writing a parser for a list.
>
> The list contains the token
> name and the literal character '-'
> Whenever a '-' is seen, the two names should be
> combined.
> E.g.
> a b c d - e f g h - k l

I guess at least one character (name_token) has to be in the list to be legal 
syntax, right?

How about:
token_list:     
         token_list token_list_entry
    |
         token_list_entry
;

token_list_entry:
        name_token '-' name_token
                { action for two combined token}
    |
        name_token
                { action for just a single one}
;

Might create some bison shift/reduce conflicts, but could work. However I 
didn't try it so i can't guarantee.

If so it might help to define the '-' as a %left operator.

- Axel



reply via email to

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