Skip to content

Commit

Permalink
Fixed ALL CONFLICTS (but still has runtime errors + field method orde…
Browse files Browse the repository at this point in the history
…ring ambiguity
  • Loading branch information
MichaelZhao21 committed Oct 27, 2022
1 parent 370c4ae commit 169b52b
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions grammar.cup
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,29 @@ precedence left TYPECAST;
precedence right PREFIXPLUS, PREFIXMINUS, COMPLEMENT, INCREMENT, DECREMENT;

program ::= CLASS ID:i LCURLY memberDeclerations:m
{: RESULT = new Program(s); :}
{: RESULT = new Program(new Name(i), m); :}
;

memberDeclerations ::= fieldList:f methodList:m
{: RESULT = new MemberDeclerations(f, m):}
memberDeclerations ::= FINAL type:t ID:i EQ expression:e SEMI memberDeclerations:m
{: RESULT = null; :}
|
type:t ID:i EQ expression:e SEMI memberDeclerations:m
{: RESULT = null; :}
|
FINAL type:t ID:i SEMI memberDeclerations:m
{: RESULT = null; :}
|
type:t ID:i SEMI memberDeclerations:m
{: RESULT = null; :}
|
type:t ID:i LBRACKET INTEGER_LITERAL:in RBRACKET SEMI memberDeclerations:m
{: RESULT = null; :}
|
type:t ID:i LPAREN argumentList:a RPAREN LCURLY fieldList:f statements:s RCURLY SEMI memberDeclerations:md
{: RESULT = null; :}
|
VOID ID:i LPAREN argumentList:a RPAREN LCURLY fieldList:f statements:s RCURLY SEMI memberDeclerations:md
{: RESULT = null; :}
;

fieldList ::= fieldDecleration:f fieldList:ff
Expand All @@ -120,20 +138,7 @@ fieldDecleration ::= FINAL type:t ID:i EQ expression:e SEMI
{: RESULT = new Field(t, new Name(i), false); :}
|
type:t ID:i LBRACKET INTEGER_LITERAL:in RBRACKET SEMI
{: RESULT = new Field(t, new Name(i, in), false) :}
;

methodList ::= methodDecleration:m methodList:mm
{: RESULT = mm.prepend(m); :}
|
{: RESULT = new MethodList(); :}
;

methodDecleration ::= returnType:t ID:i LPAREN argumentList:a RPAREN LCURLY fieldList:f statements:s RCURLY SEMI
{: RESULT = new Method(t, i, a, f, s, true); :}
|
returnType:t ID:i LPAREN argumentList:a RPAREN LCURLY fieldList:f statements:s RCURLY
{: RESULT = new Method(t, i, a, f, s, false); :}
{: RESULT = null; :}
;

statements ::= statement:s statements:ss
Expand Down Expand Up @@ -260,13 +265,6 @@ type ::= INT
{: RESULT = new Type("float"); :}
;

returnType ::= VOID
{: RESULT = new Type("void"); :}
|
type:t
{: RESULT = t; :}
;

expression ::= binaryExpression:b
{: RESULT = b; :}
|
Expand Down

0 comments on commit 169b52b

Please sign in to comment.