Re: Semantics make a grammar ambiguous

"Bill A." <>
30 Apr 1999 22:59:23 -0400

          From comp.compilers

Related articles
Semantics make a grammar ambiguous (Bill A) (1999-04-26)
Re: Semantics make a grammar ambiguous (Robert Sherry) (1999-04-29)
Re: Semantics make a grammar ambiguous (1999-04-30)
Re: Semantics make a grammar ambiguous (Bill A.) (1999-04-30)
Re: Semantics make a grammar ambiguous (Tzvetan Mikov) (1999-05-03)
Re: Semantics make a grammar ambiguous (1999-05-07)
| List of all articles for this month |

From: "Bill A." <>
Newsgroups: comp.compilers
Date: 30 Apr 1999 22:59:23 -0400
Organization: Posted via RemarQ Communities, Inc.
References: 99-04-087 99-04-099
Keywords: C, parse

Hi Robert,

Robert Sherry wrote in message 99-04-099...
>I gather that your scanner does the lookup into the symbol table.

Yes, it does.

>However, if you were to switch to having it return ID for all
>variables and type names you might introduce shift/reduce conflicts in
>your grammar.

:) You're right again! I did this and got exactly what you describe - many

> I had a problem like this when I was trying to write a parser
>for a spice like language. Spice is a language for describing analog
>circuits. I solved the problem by having the parser feed information
>back to the scanner about what to expect. Knows the scanner would know
>whether it should expect a type or a identifier.

This is quite clever - thanks! Never quite thought of using the
parser to tell the scanner what it can and can't output. I will do
this - I can see already that this is what I can do and I can leave
the grammer alone.

>The text books say that this is a bad idea but it might solve your problem.

A bad idea that solves a nasty problem...Isn't that a good idea? :)

>This idea has
>another problem. Consider the statement: <snip>

Yes, it does. But I've heard the not long ago that Standard C
practice was to disallow a default int type. I guess I have the
situation now that register <id OR typedef_name> <id>; always sees the
typedef because my scanner does a lookup and changes an ID token to
<typedef> token when a <typedef> is present (the whole reason for my

> I hope this helps. Good Luck.

Very much so. Thanks Robert for your feedback and idea!

Bill Auerbach

Post a followup to this message

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