Re: The signs of literals

Chris Clark USG <>
10 Dec 1997 00:41:55 -0500

          From comp.compilers

Related articles
The signs of literals (Hung-Ta Lin) (1997-12-07)
Re: The signs of literals (David L Moore) (1997-12-10)
Re: The signs of literals (Chris Clark USG) (1997-12-10)
Re: The signs of literals (1997-12-12)
Re: The signs of literals tim@wagner.Princeton.EDU (1997-12-12)
Re: The signs of literals (Matt Timmermans) (1997-12-12)
Re: The signs of literals (David L Moore) (1997-12-13)
| List of all articles for this month |

From: Chris Clark USG <>
Newsgroups: comp.compilers
Date: 10 Dec 1997 00:41:55 -0500
Organization: Digital Equipment Corporation - Marlboro, MA
References: 97-12-053
Keywords: syntax

Lin Hung-Ta asked:
> Hi, I am working on a grammar that explicitly treats sign as part of a
> integer literal . . . Would it be okay to change that grammar to:
> . . . or I should treat integer_literal as a lexical token:
> . . . The former disallows expressions such as + - 4; the latter
> requires no space between the sign and the digit sequence.

You have captured the issue correctly in your last question. It
really depends on what your language expects. If you are defining the
language, pick which makes sense. If not, you need to determine what
the language really expects. (I would suspect that the no space
between the sign and the digit sequence is the more likely

If neither restiction is acceptable, I suspect that part of your
problem is that you are parsing it with an LL parser generator--not
that that is necessarily bad. However, it does require more work in
this case to make the grammar acceptable. What you need to do is what
we call "flattening" your grammar. In your case, you hand substitute
exp6 into the exp5 production, as follows, and see if that resolves
the problem.

exp5 ::= [+|-] integer_literal
                            | [+|-] ...

You may need to take it farther. That depends on the rest of your

Hope this helps,
-Chris Clark
Compiler Resources, Inc. email:
3 Proctor St.
Hopkinton, MA 01748 phone: (508) 435-5016
USA 24hr fax: (508) 435-4847

Post a followup to this message

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