Summary Files Commits Branches @commit @diff @stats
path: root / Year 3 / Compilers, Introduction
diff options
context:
space:
mode:
Commitbd45aa8372205e6bb5e06d419f4e355ca7f216ce (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-11-15 19:55:59 +0200
Committer
 Syndamia <kamen@syndamia.com>
2023-11-15 19:55:59 +0200
Files45a90d5b9e1fc970c589a1d563a623935bda601b /Year 3/Compilers, Introduction
uni-projects-bd45aa8372205e6bb5e06d419f4e355ca7f216ce.tar
uni-projects-bd45aa8372205e6bb5e06d419f4e355ca7f216ce.tar.gz
uni-projects-bd45aa8372205e6bb5e06d419f4e355ca7f216ce.zip
Parent369a723ba50fc9520b30f4d18cdb347f8b9496ee (diff)
[CI/PA2] Fixed too good error handling for two cases
1 files changed, 17 insertions, 20 deletions
-rw-r--r--Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa2/cool.y37
diff --git a/Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa2/cool.y b/Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa2/cool.y
index 67dc206..56f0644 100644
--- a/Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa2/cool.y
+++ b/Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa2/cool.y
@@ -125,7 +125,7 @@
/* DON'T CHANGE ANYTHING ABOVE THIS LINE, OR YOUR PARSER WONT WORK */
/**************************************************************************/
- %define parse.error detailed
+ /* %define parse.error detailed */
/* Complete the nonterminal list below, giving a type for the semantic
value of each non terminal. (See section 3.6 in the bison
@@ -164,17 +164,14 @@
;
// [[class;]]+
- class_list: class ';' { $$ = single_Classes($1); parse_results = $$; }
- | error ';' class ';' { $$ = single_Classes($3); }
- | class_list class ';' { $$ = append_Classes($1, single_Classes($2)); parse_results = $$; }
- | class_list error ';' class ';' { $$ = append_Classes($1, single_Classes($4)); }
+ class_list: class { $$ = single_Classes($1); parse_results = $$; }
+ | error { $$ = nil_Classes(); }
+ | class_list class { $$ = append_Classes($1, single_Classes($2)); parse_results = $$; }
;
// class TYPE [inherits TYPE] { [[feature;]]* }
- class: CLASS TYPEID '{' feature_list '}' { $$ = class_($2, idtable.add_string("Object"), $4, stringtable.add_string(curr_filename)); }
- | CLASS TYPEID INHERITS TYPEID '{' feature_list '}' { $$ = class_($2, $4, $6, stringtable.add_string(curr_filename)); }
- | error '{' feature_list '}' {}
- | error '{' error '}' {}
+ class: CLASS TYPEID '{' feature_list '}' ';' { $$ = class_($2, idtable.add_string("Object"), $4, stringtable.add_string(curr_filename)); }
+ | CLASS TYPEID INHERITS TYPEID '{' feature_list '}' ';' { $$ = class_($2, $4, $6, stringtable.add_string(curr_filename)); }
;
// [[feature;]]*
@@ -182,10 +179,10 @@
| feature_list_nonempty { $$ = $1; }
;
- feature_list_nonempty: feature ';' { $$ = single_Features($1); }
- | error ';' { $$ = nil_Features(); }
- | feature_list feature ';' { $$ = append_Features($1, single_Features($2)); }
- | feature_list error ';' { $$ = $1; }
+ feature_list_nonempty: feature { $$ = single_Features($1); }
+ | error { $$ = nil_Features(); }
+ | feature_list feature { $$ = append_Features($1, single_Features($2)); }
+ | feature_list error { $$ = $1; }
;
// ID([formal [[, formal]]*]): TYPE { expr }
@@ -195,16 +192,16 @@
;
// ID : TYPE [ <- expr ]
- attribute: OBJECTID ':' TYPEID { $$ = attr($1, $3, no_expr()); }
- | OBJECTID ':' TYPEID ASSIGN expression { $$ = attr($1, $3, $5); }
- | error expression {}
+ attribute: OBJECTID ':' TYPEID ';' { $$ = attr($1, $3, no_expr()); }
+ | OBJECTID ':' TYPEID ASSIGN expression ';' { $$ = attr($1, $3, $5); }
+ | error expression ';' {}
;
// ID([formal [[, formal]]*]): TYPE { expr }
- method: OBJECTID '(' formal_list ')' ':' TYPEID '{' expression '}' { $$ = method($1, $3, $6, $8); }
- | OBJECTID '(' formal_list ')' ':' TYPEID '{' error '}' {}
- | OBJECTID '(' error ')' ':' TYPEID '{' expression '}' {}
- | OBJECTID '(' error ')' ':' TYPEID '{' error '}' {}
+ method: OBJECTID '(' formal_list ')' ':' TYPEID '{' expression '}' ';' { $$ = method($1, $3, $6, $8); }
+ | OBJECTID '(' formal_list ')' ':' TYPEID '{' error ';' {}
+ | OBJECTID '(' error ')' ':' TYPEID '{' expression ';' {}
+ | OBJECTID '(' error ')' ':' TYPEID '{' error ';' {}
;
// [formal [[, formal]]*]