java parsing problem
19 Oct 2000 14:38:21 -0400

          From comp.compilers

Related articles
java parsing problem (2000-10-19)
Re: java parsing problem (2000-10-22)
Re: java parsing problem (Joachim Durchholz) (2000-10-22)
Re: java parsing problem (Ivan Naumov) (2000-10-22)
| List of all articles for this month |

Newsgroups: comp.compilers
Date: 19 Oct 2000 14:38:21 -0400
Organization: - Before you buy.
Keywords: Java, parse, question

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

I am having difficulty with the following part of the specification:



    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

This has the same problem and what I usually do is to mentally rewrite
it as:

    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.