From 4aa1f0d045a8940f4d3015737d56f2bdc5debb67 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 8 Nov 2023 19:43:34 +0200 Subject: [CI/PA2] Fixed classes --- .../coolc-spim/my-code/coursework/pa2/cool.y | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 ';' ; -- cgit v1.3.1-23-gd82d