Re: Semantics make a grammar ambiguous

Robert Sherry <>
29 Apr 1999 00:44:37 -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: Robert Sherry <>
Newsgroups: comp.compilers
Date: 29 Apr 1999 00:44:37 -0400
Organization: @Home Network
References: 99-04-087
Keywords: C, parse, types


The C compilers that I have worked on kept type names in a
different name space ( symbol table ) then variable names. In
addition, type names and variable names both came back from the
scanner as a token of type ID. I gather that your scanner does the
lookup into the symbol table. This might be the cause of your
problem. 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.

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. The text books say
that this is a bad idea but it might solve your problem. This idea has
another problem. Consider the statement:

register x y;

where x is a typedef. This is a valid statement but

register x, y;

is also valid and declares x and y to be variables for type int. Hence,
as you see after the register keyword you can have either a type name or
a variable name.

I hope this helps. Good Luck.

Robert Sherry

Post a followup to this message

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