Merge branch 'josh_lab4' into 'main'
Josh lab4 See merge request lustje/language-interpreter-lab!7
This commit is contained in:
commit
5cd370420c
|
|
@ -43,9 +43,9 @@ UTEST(parser, missing_semi_colon) {
|
||||||
ASSERT_EQ(result, 1);
|
ASSERT_EQ(result, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
UTEST(parser, sample) {
|
UTEST(parser, hello) {
|
||||||
// Read sample file as input
|
// Read sample file as input
|
||||||
yyin = fopen("samples/program.c", "r");
|
yyin = fopen("samples/hello-world.cbl", "r");
|
||||||
yyrestart(yyin);
|
yyrestart(yyin);
|
||||||
ASSERT_TRUE(yyin);
|
ASSERT_TRUE(yyin);
|
||||||
|
|
||||||
|
|
@ -55,3 +55,31 @@ UTEST(parser, sample) {
|
||||||
// Assert the result to test correctness
|
// Assert the result to test correctness
|
||||||
ASSERT_EQ(result, 0);
|
ASSERT_EQ(result, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UTEST(parser, print) {
|
||||||
|
// Must include the null character to terminate input
|
||||||
|
char string[] = "DISPLAY 'Hello World!'\0";
|
||||||
|
YY_BUFFER_STATE buffer = yy_scan_buffer(string, sizeof(string));
|
||||||
|
|
||||||
|
yylineno = 1;
|
||||||
|
int result = yyparse();
|
||||||
|
|
||||||
|
yy_delete_buffer(buffer);
|
||||||
|
|
||||||
|
// Assert the result to test correctness
|
||||||
|
ASSERT_EQ(result, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
UTEST(parser, branching) {
|
||||||
|
// Must include the null character to terminate input
|
||||||
|
char string[] = "IF A > B THEN DISPLAY 'A is greater than B' ELSE DISPLAY 'B is greater than A'\0";
|
||||||
|
YY_BUFFER_STATE buffer = yy_scan_buffer(string, sizeof(string));
|
||||||
|
|
||||||
|
yylineno = 1;
|
||||||
|
int result = yyparse();
|
||||||
|
|
||||||
|
yy_delete_buffer(buffer);
|
||||||
|
|
||||||
|
// Assert the result to test correctness
|
||||||
|
ASSERT_EQ(result, 0);
|
||||||
|
}
|
||||||
|
|
@ -77,6 +77,7 @@ sect_data : TOKEN_PROGRAM_ID TOKEN_DOT TOKEN_IDENT TOKEN_DOT
|
||||||
type : TOKEN_IDENTIFICATION
|
type : TOKEN_IDENTIFICATION
|
||||||
| TOKEN_PROCEDURE
|
| TOKEN_PROCEDURE
|
||||||
| TOKEN_STOP
|
| TOKEN_STOP
|
||||||
|
| TOKEN_KEYWORD_DATA
|
||||||
;
|
;
|
||||||
simple_stmt : function
|
simple_stmt : function
|
||||||
;
|
;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue