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) |
From: | shirleytemple@my-deja.com |
Newsgroups: | comp.compilers |
Date: | 19 Oct 2000 14:38:21 -0400 |
Organization: | Deja.com - 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
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?
Return to the
comp.compilers page.
Search the
comp.compilers archives again.