@@ -50,8 +50,8 @@ public Program program() {
5050 this .match ("main" );
5151 this .match ("{" );
5252 Program p = new Program ();
53- p .decpart = this . declarations ();
54- p .body = this . statements ();
53+ p .decpart = declarations ();
54+ p .body = statements ();
5555 this .match ("}" );
5656 return p ;
5757 }
@@ -79,11 +79,11 @@ private Type type() {
7979 // Type --> integer | bool
8080 Type t = null ;
8181 if (token .getValue ().equals ("integer" ))
82- t = new Type (token . getValue () );
82+ t = new Type (Type . INTEGER );
8383 else if (token .getValue ().equals ("bool" ))
84- t = new Type (token . getValue () );
84+ t = new Type (Type . BOOLEAN );
8585 else
86- throw new RuntimeException (SyntaxError ("integer | bool " ));
86+ throw new RuntimeException (SyntaxError ("integer | boolean " ));
8787 token = input .nextToken (); // pass over the type
8888 return t ;
8989 }
@@ -131,7 +131,7 @@ else if (token.getValue().equals("while")) { // WhileStatement
131131 } else if (token .getType ().equals ("Identifier" )) { // Assignment
132132 // TODO TO BE COMPLETED
133133 s = assignment ();
134- match (";" );
134+ // match(";");
135135 } else
136136 throw new RuntimeException (SyntaxError ("Statement" ));
137137 return s ;
@@ -151,13 +151,13 @@ private Assignment assignment() {
151151 Assignment a = new Assignment ();
152152 if (token .getType ().equals ("Identifier" )) {
153153 // TODO TO BE COMPLETED
154- Variable target = new Variable ();
155- target .id = token .getValue ();
156- a .target = target ;
154+ Variable v = new Variable ();
155+ v .id = token .getValue ();
156+ a .target = v ;
157157 token = input .nextToken ();
158-
159158 match (":=" );
160159 a .source = expression ();
160+ match (";" );
161161 } else
162162 throw new RuntimeException (SyntaxError ("Identifier" ));
163163 return a ;
@@ -278,7 +278,7 @@ private Expression factor() {
278278 } else if (token .getType ().equals ("Literal" )) {
279279 Value v = null ;
280280 if (isInteger (token .getValue ()))
281- v = new Value ((new Integer (token .getValue ())). intValue ( ));
281+ v = new Value ((Integer . parseInt (token .getValue ())));
282282 else if (token .getValue ().equals ("True" ))
283283 v = new Value (true );
284284 else if (token .getValue ().equals ("False" ))
@@ -307,7 +307,7 @@ private Conditional ifStatement() {
307307 c .thenbranch = statement ();
308308
309309 if (token .getValue ().equals ("else" )){
310- match ( "else" );
310+ token = input . nextToken ( );
311311 c .elsebranch = statement ();
312312 } else {
313313 c .elsebranch = null ;
0 commit comments