Related articles |
---|
The signs of literals lin@cs.monash.edu.au (Hung-Ta Lin) (1997-12-07) |
Re: The signs of literals dlmoore@ix.netcom.com (David L Moore) (1997-12-10) |
Re: The signs of literals clark@quarry.zk3.dec.com (Chris Clark USG) (1997-12-10) |
Re: The signs of literals hbaker@netcom.com (1997-12-12) |
Re: The signs of literals tim@wagner.Princeton.EDU (1997-12-12) |
Re: The signs of literals mtimmerm@microstar.no-spam.com (Matt Timmermans) (1997-12-12) |
Re: The signs of literals dlmoore@ix.netcom.com (David L Moore) (1997-12-13) |
From: | Chris Clark USG <clark@quarry.zk3.dec.com> |
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
alternative.)
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
grammar.
Hope this helps,
-Chris Clark
************************************************************************
Compiler Resources, Inc. email: compres@world.std.com
3 Proctor St. http://world.std.com/~compres
Hopkinton, MA 01748 phone: (508) 435-5016
USA 24hr fax: (508) 435-4847
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.