javacc - Avoid common prefixes without change lookahead -
i'm using javacc make specification recognize language. problem have javacc gives me warning because public common prefix of member() declaration. member() can has attributes() and/or method() must have @ least 1 method, order not matter.
the warning javacc gives me is:
choice conflict in (...)+ construct @ line 66, column 23. expansion nested within construct , expansion following construct have common prefixes, 1 of is: "public". consider using lookahead of 2 or more nested expansion.
the line 66 line of member(). need without change lookahead value.
here code:
void member() : {} { (attribute())* (method())+ (attribute() | method())* } void attribute() : {} { "private" type() <id> [":=" expr()]";" } void method() : {} { methodhead() methodbody() } void methodhead() : {} { ("public")? (<id> | type() | "void") <id> "(" parameter() ")" }
thanks.
the problem regular expression
(method())+ (attribute() | method())*
is ambiguous. let's abbreviate methods m , attributes a. if input mam, there no problem. (method())+
matches first m , (attribute() | method())*
matches remaining am. if input mma, should divide be? either (method())+
matches m , (attribute() | method())*
matches ma or (method())+
matches mm , (attribute() | method())*
matches a. both parses possible. javacc doesn't know parse want, complains.
what can do:
- nothing. ignore warning. default behaviour many methods possible recognized
(method())+
, methods after first attribute recognized(attribute() | method())*
. - suppress warning using lookahead. said don't want add lookahead, completeness, i'll mention change
(method())+
(lookahead(1) method())+
. won't change behaviour of parser, suppress warning. - rewrite grammar.
the offending line rewritten either
(attribute())* method() (attribute() | method())*
or as
(attribute())* (method())+ [attribute() (attribute() | method())*]
Comments
Post a Comment