diff options
[CI/PA2] Fixed classes
1 files changed, 10 insertions, 2 deletions
| -rw-r--r-- | Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa2/cool.y | 12 |
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 40a8a47..74ab0d6 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 @@ -150,10 +150,18 @@ ; /* If no parent is specified, the class inherits from the Object class. */ - class: CLASS TYPEID '{' dummy_feature_list '}' ';' { $$ = class_($2,idtable.add_string("Object"),$4, stringtable.add_string(curr_filename)); } - | CLASS TYPEID INHERITS TYPEID '{' dummy_feature_list '}' ';' { $$ = class_($2,$4,$6,stringtable.add_string(curr_filename)); } + 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_list: feature + | feature ';' feature_list + ; + + feature: attribute + | method + ; + attribute: OBJECTID ':' TYPEID | OBJECTID ':' TYPEID ASSIGN expression ';' ; |
