help-bison
[Top][All Lists]
Advanced

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

Re: Semantic parsing


From: Hans Aberg
Subject: Re: Semantic parsing
Date: Sat, 20 Apr 2002 11:12:49 +0200

At 23:17 -0400 2002/04/19, REFSTRUP,JACOB (HP-Vancouver,ex1) wrote:
>I'm working on some parsing project that currently utilizes a hand written
>parser for some semantic parsing. Since that's hard to maintain I'd like to
>move to bison so I have the following questions:

First, please describe somewhat better what you mean by "semantic parsing":

>1) I understand that bison does have semantic parsing (via %semantic_parser)
>but also noticed that there's some concern as to whether that code should be
>used or not.

The Bison's "semantic parser" was part of Corbett's thesis work (who
originally wrote Bison). It is currently broken, and the research at
Berkeley in the area has since moved beyond that. Corbett himself removed
this semantic parser about a decade ago in the Berkeley version of Bison.
It has remained in the GNU version only because it looked important nobody
dared removing it.

>2) If I can use %semantic_parser then what's the syntax? I've been looking
>around but haven't found anything.

So nobody has a clue to that.

>3) If I shouldn't use %semantic_parser then how do I go about it?

Neither that. :-)

> My
>semantic "conflicts" are relatively simple so perhaps someone can just point
>out to me how to approach it.
>
>name:
>       IDENT
>       ;
>
>keyword:
>       IDENT
>       ;
>
>color:
>       IDENT
>       ;
>
>combination:
>         name
>       | keyword
>       | color
>       ;
>
>Current the strings for names, keywords and colors are non-overlapping but
>they may be in the future. I need to enable productions suchs as
>
>complex:
>         keyword [ limit to certain keywords ] color
>       | color keyword
>       ;
>
>This is not an exact grammar but I think you get the point - I need to
>reject rules and backup a number of tokens.

Your conflicts do not have anything with Bisons semantic parsing to do, but
are typical when constructing a computer language. If you do not get help
enough here, or some other such list, you may also try the newsgroup
comp.compilers.

As for your type of problem, you have to simply put the semantic
information needed to resolve the ambiguities into the grammar.

One way to do it is to let the lexer (scanner) have a lookup table that
determines the type of the scanned string, and then returns a suitable
token. Thus, your .y grammar might look like:
%token name, keyword, color
%%
  combination:
      name
    | keyword
    | color
  ;

  Hans Aberg





reply via email to

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