Merge branch 'josh_lab4' into 'main'

Josh lab4

See merge request lustje/language-interpreter-lab!7
This commit is contained in:
Joshua Garbi 2024-10-31 10:17:46 -07:00
commit 5cd370420c
2 changed files with 31 additions and 2 deletions

View File

@ -43,9 +43,9 @@ UTEST(parser, missing_semi_colon) {
ASSERT_EQ(result, 1);
}
UTEST(parser, sample) {
UTEST(parser, hello) {
// Read sample file as input
yyin = fopen("samples/program.c", "r");
yyin = fopen("samples/hello-world.cbl", "r");
yyrestart(yyin);
ASSERT_TRUE(yyin);
@ -55,3 +55,31 @@ UTEST(parser, sample) {
// Assert the result to test correctness
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);
}

View File

@ -77,6 +77,7 @@ sect_data : TOKEN_PROGRAM_ID TOKEN_DOT TOKEN_IDENT TOKEN_DOT
type : TOKEN_IDENTIFICATION
| TOKEN_PROCEDURE
| TOKEN_STOP
| TOKEN_KEYWORD_DATA
;
simple_stmt : function
;