Re: java parsing problem

"Ivan Naumov" <Ivan_Ivan_Ivan@yahoo.com>
22 Oct 2000 01:28:43 -0400

          From comp.compilers

Related articles
java parsing problem shirleytemple@my-deja.com (2000-10-19)
Re: java parsing problem LLkParsing@aol.com (2000-10-22)
Re: java parsing problem joachim_d@gmx.de (Joachim Durchholz) (2000-10-22)
Re: java parsing problem Ivan_Ivan_Ivan@yahoo.com (Ivan Naumov) (2000-10-22)
| List of all articles for this month |

From: "Ivan Naumov" <Ivan_Ivan_Ivan@yahoo.com>
Newsgroups: comp.compilers
Date: 22 Oct 2000 01:28:43 -0400
Organization: St.Petersburg University
References: 00-10-146
Keywords: parse, Java

By substitutions you will get:


Primary:
    PrimaryNoNewArray | ArrayCreationExpression | Primary . Identifier |
...


After that you can make the same as you did in second example and get:


Primary:
    (PrimaryNoNewArray | ArrayCreationExpression | ...) (. Identifier)*


This is the same as:
Primary:
    PrimaryNoNewArray (. Identifier)*
    ArrayCreationExpression (. Identifier)*
    ... (. Identifier)*




<shirleytemple@my-deja.com> wrote in message
> I am hand-writing a recursive-descent parser for a subset of java. I
> decided to follow the standard BNF provided in the JLS (java language
> specification).
>
> I am having difficulty with the following part of the specification:
>
> Primary:
> PrimaryNoNewArray
> ArrayCreationExpression
>
> PrimaryNoNewArray
> ...
> FieldAccess
> ...
>
> FieldAccess
> Primary . Identifier
> ...
>
> Assuming the simple approach of writing each right hand side as a
> method, i would have something (in pseudocode) like:
>
> parsePrimary(scanner) {
> exp = parsePrimaryNoNewArray(scanner);
> if (exp != null) return exp;
> // try arrayCreationExpression
> }
>
> parsePrimaryNoNewArray(scanner) {
> // other rules
> exp = parseFieldAccess(scanner);
> if (exp != null) return exp;
> ...
> }
> parseFieldAccess(scanner) {
> p = parsePrimary(scanner);
> // look for . Identifier etc
> }
>
> Obviously this is a loop. I dont really know what I'm talking about
> here, but is this because the BNF is LR and I am using an LL approach?
> Is this left-recursion?
>
> For that matter what about specifications such as:
>
> AndExpression:
> EqualityExpression
> AndExpression & EqualityExpression
>
> This has the same problem and what I usually do is to mentally rewrite
> it as:
>
> AndExpression:
> EqualityExpression (& EqualityExpression)*
>
> where ()* = 0 or more of.
>
> I'd appreciate any help. What would be the correct way to change the
> above example to handle the recursion on Primary?


Post a followup to this message

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