PA3 seems to be ok

This commit is contained in:
ridethepig 2023-03-23 04:37:49 +00:00
parent 54e92e49a4
commit dcff1387d9
3 changed files with 49 additions and 4 deletions

View File

@ -78,7 +78,7 @@ clean-compile:
TESTCASE = good.cl TESTCASE = good.cl
comparetest: parser comparetest: parser
./stdparser ${TESTCASE} > std.out -./stdparser ${TESTCASE} > std.out 2>&1
./myparser ${TESTCASE} > my.out -./myparser ${TESTCASE} > my.out 2>&1
diff std.out my.out diff std.out my.out
rm std.out my.out rm std.out my.out

View File

@ -6,6 +6,8 @@
* execute "myparser bad.cl" to see the error messages that your parser * execute "myparser bad.cl" to see the error messages that your parser
* generates * generates
*) *)
-- lex_error
*)
(* no error *) (* no error *)
class A { class A {
@ -24,6 +26,40 @@ Class D inherts A {
}; };
(* error: closing brace is missing *) (* error: closing brace is missing *)
Class E inherits A { Class E inherits A }
; ;
class A {
F(x : Int) : Object {
self
};
};
class B {
Y : Int;
};
Class F inherits A {
scheisse: wrongtype ;
WrongType: scheisse;
scheisse <- "no type";
err_method1(id1: t1);
err_method2(id1:T1, );
err_method3(id1:T1):t1;
err_method4(id1:T1):T1;
err_method5();
good_method() : T { hallo <- 2 };
err_method6() { hallo <- 2 };
err_block() : T {
let a:Int <- Broken in {
error(s:T);
hello;
err_(s:T);
wow();
}
};
err_let() : T {
{
let a:Int<-Bork, b:Int<-5, c:Int<-6 in a + B;
}
}
};

View File

@ -181,6 +181,8 @@
{ $$ = append_Classes($1,single_Classes($2)); { $$ = append_Classes($1,single_Classes($2));
parse_results = $$; } parse_results = $$; }
/* TODO: I guess `parse_results` is only needed in the top-most class_list*/ /* TODO: I guess `parse_results` is only needed in the top-most class_list*/
| error ';'
{ }
; ;
/* If no parent is specified, the class inherits from the Object class. */ /* If no parent is specified, the class inherits from the Object class. */
@ -192,7 +194,6 @@
{ $$ = class_($2,$4,$6,stringtable.add_string(curr_filename)); } { $$ = class_($2,$4,$6,stringtable.add_string(curr_filename)); }
| CLASS TYPEID INHERITS TYPEID '{' '}' ';' | CLASS TYPEID INHERITS TYPEID '{' '}' ';'
{ $$ = class_($2,$4,nil_Features(),stringtable.add_string(curr_filename)); } { $$ = class_($2,$4,nil_Features(),stringtable.add_string(curr_filename)); }
| CLASS error '{' error '}' ';'
; ;
/* Feature list may be empty, but no empty features in list. */ /* Feature list may be empty, but no empty features in list. */
@ -200,6 +201,8 @@
{ $$ = single_Features($1); } { $$ = single_Features($1); }
| feature_list feature ';' | feature_list feature ';'
{ $$ = append_Features($1, single_Features($2)); } { $$ = append_Features($1, single_Features($2)); }
| error ';'
{ }
; ;
feature : OBJECTID ':' TYPEID feature : OBJECTID ':' TYPEID
@ -241,6 +244,8 @@
{ $$ = single_Expressions($1); } { $$ = single_Expressions($1); }
| expression_list_colon expression ';' | expression_list_colon expression ';'
{ $$ = append_Expressions($1, single_Expressions($2)); } { $$ = append_Expressions($1, single_Expressions($2)); }
| error ';'
{ }
; ;
expression : OBJECTID ASSIGN expression expression : OBJECTID ASSIGN expression
@ -336,6 +341,10 @@
{ $$ = let($1, $3, no_expr(), $5); } { $$ = let($1, $3, no_expr(), $5); }
| OBJECTID ':' TYPEID ASSIGN expression IN expression %prec LETEXPR | OBJECTID ':' TYPEID ASSIGN expression IN expression %prec LETEXPR
{ $$ = let($1, $3, $5, $7); } { $$ = let($1, $3, $5, $7); }
| error ',' nested_let
{ $$ = $3; }
| error IN expression %prec LETEXPR
{ $$ = $3; }
; ;
/* end of grammar */ /* end of grammar */
%% %%