Re: LL(1) problem

vbdis@aol.com (VBDis)
5 May 2003 23:39:22 -0400

          From comp.compilers

Related articles
LL(1) problem albert@shqiperia.com (Albert) (2003-04-27)
Re: LL(1) problem cdc25@it.canterbury.ac.nz (Carl Cerecke) (2003-05-05)
Re: LL(1) problem vbdis@aol.com (2003-05-05)
Re: LL(1) problem slk15@earthlink.net (SLK Parsers) (2003-05-06)
| List of all articles for this month |
From: vbdis@aol.com (VBDis)
Newsgroups: comp.compilers
Date: 5 May 2003 23:39:22 -0400
Organization: AOL Bertelsmann Online GmbH & Co. KG http://www.germany.aol.com
References: 03-04-091
Keywords: parse, LL(1)
Posted-Date: 05 May 2003 23:39:22 EDT

  "Albert" <albert@shqiperia.com> schreibt:


>Essentially the problem is that in an expression a factor can be a
>identifier(variable) or can be a field of a class(ident.ident). Please
>can anyone help me to resolve this.


IMO it's a semantic restriction, what (kind of) identifier is
acceptable in any place in a text. E.g. when no identifier named X is
declared in the source text, then both X and X.Y are semantically
invalid. When X identifies an object of a class, with a member Y, then
X.Y will denote a field reference, and X for itself will denote an
object reference, which both are syntactically valid in most
cases. X.Y.Z may be valid as well, when Z is a member of the class of
Y.


Add qualified identifiers to your grammar, and use them instead of simple
identifiers wherever applicable:
    QualId = ident { "." ident }. (* easy to parse *)
or
    QualId = ident [ "." QualId ]. (* equivalent to the preceding *)
or
    QualId = { ident "." } ident. (* better to interpret as <obj>.<member> *)


I'm not sure what restrictions you really want to reflect in your grammar. When
object or field references are valid as arguments or local variables, then a
member selection should be possible also with such identifiers, and multiple
application of member selection, calls etc. also may be acceptable. Then Factor
could be extended by:
    Factor = ... | [ "." ] ident { "." ident | "(" ArgList ")" } | ...


Have a look at the sample grammars which come with CoCo, e.g. at MOD2.ATG and
OBERON.ATG.


DoDi


Post a followup to this message

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