I am writing a microJava compiler and I am currently implementing class logic. So far I have implemented field logic but I am struggling with method access. The code bellow is working properly (for fields)
Designator ::= (DesignatorVar) IDENT
|
(DesignatorPropertyAccess) DesignatorClassName DesignatorClassMore
|
(DesignatorElem) DesignatorArrayName LBRACKET Expr RBRACKET
|
(DesignatorElemPropertyAccess) DesignatorClassElem DesignatorClassMore
;
DesignatorClassMore ::= (DesignatorClassMoreFinal) DOT IDENT
|
(DesignatorClassMoreFinalElem) DOT DesignatorClassArrayName LBRACKET Expr RBRACKET
|
(DesignatorClassMoreNotFinal) DesignatorClassMore DOT IDENT
|
(DesignatorClassMoreNotFinalElem) DesignatorClassMore DOT DesignatorClassArrayName LBRACKET Expr RBRACKET
;
DesignatorClassElem ::= (DesignatorClassElem) DesignatorArrayName LBRACKET Expr RBRACKET ;
DesignatorClassName ::= (DesignatorClassName) IDENT;
DesignatorClassArrayName ::= (DesignatorClassArrayName) IDENT;
DesignatorArrayName ::= (DesignatorArrayName) IDENT;
The problem appears when I try to apply class method calls, I am doing it like this
DesignatorClassMore ::= (DesignatorClassMoreFinal) DOT IDENT OptCall
|
(DesignatorClassMoreFinalElem) DOT DesignatorClassArrayName LBRACKET Expr RBRACKET OptCall
|
(DesignatorClassMoreNotFinal) DesignatorClassMore DOT IDENT OptCall
|
(DesignatorClassMoreNotFinalElem) DesignatorClassMore DOT DesignatorClassArrayName LBRACKET Expr RBRACKET OptCall
;
OptCall ::= DesignatorFuncCall
|
/* epsilon */
;
DesignatorFuncCall ::= LPAREN StackInitialize RPAREN
|
LPAREN StackInitialize ActPars RPAREN
;
Designator function call logic is correct because I have tested it on the simple methods (not class methods) so I believe the problem is shift/reduce conflict but I can't resolve it. What should I do?
For parser generation I am using cup_v10k.jar and I can provide link to this library.
The problem is, as I was doing project (I am at semantic analysis) I realised that I haven't implemented class method invocation in my syntax rules. And I am stuck with grammar problem (probably shift/reduce conflict). I have tried many modifications, and I have one observation but I can't figure why is it the thing. I can successfully compile DOT IDENT | DOT IDENT LBRACKET ... but when I add DOT IDENT LPAREN ... i have error which is basic and doesn't tell me anything.
DOT IDENT OptCallis not the same thing, especially given the production list forOptCall. Please ensure that the code presented aligns with the prose, and that both accurately reflect the issue you are asking about.