From a089fe73dbb481ab903180a3233b10c0c3b96239 Mon Sep 17 00:00:00 2001 From: Riley Smith Date: Wed, 13 Nov 2024 17:12:09 -0800 Subject: [PATCH] fix sample --- lab-4/samples/sorting-snippet.cbl | 2 +- lab-5/Makefile | 2 +- lab-5/parser.bison | 36 +++++++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lab-4/samples/sorting-snippet.cbl b/lab-4/samples/sorting-snippet.cbl index 07b2ebd..7019d00 100644 --- a/lab-4/samples/sorting-snippet.cbl +++ b/lab-4/samples/sorting-snippet.cbl @@ -48,7 +48,7 @@ PROCEDURE DIVISION. PERFORM VARYING WS-INDEX FROM 1 BY 1 UNTIL WS-INDEX > WS-SORT-MAX DISPLAY "Element " WS-INDEX ": " WS-SORT-ROW(WS-INDEX) - END-PERFORM. + END-PERFORM STOP RUN. \ No newline at end of file diff --git a/lab-5/Makefile b/lab-5/Makefile index dfc7723..0361623 100644 --- a/lab-5/Makefile +++ b/lab-5/Makefile @@ -20,7 +20,7 @@ scanner.c: scanner.flex parser.h flex -oscanner.c scanner.flex parser.c parser.h: parser.bison - bison --defines=parser.h --output=parser.c -v parser.bison -Wconflicts-sr -Wcounterexamples + bison --defines=parser.h --output=parser.c -v parser.bison # clean causes all intermediate files to be deleted. diff --git a/lab-5/parser.bison b/lab-5/parser.bison index dfeb38e..f51f45c 100644 --- a/lab-5/parser.bison +++ b/lab-5/parser.bison @@ -1,9 +1,35 @@ %{ #define YYDEBUG 1 #include -extern int yylineno; +#include +#include +#include +#include "expr.h" + +/* +YYSTYPE is the lexical value returned by each rule in a bison grammar. +By default, it is an integer. In this example, we are returning a pointer to an expression. +*/ + +#define YYSTYPE struct expr * + +/* +Clunky: Manually declare the interface to the scanner generated by flex. +*/ + +extern char *yytext; +extern int yylex(); void yyerror(const char*); -int yylex(); + +/* +Clunky: Keep the final result of the parse in a global variable, +so that it can be retrieved by main(). +*/ + +struct expr * parser_result = 0; + + +extern int yylineno; %} %debug @@ -63,7 +89,9 @@ int yylex(); %% -file : statements +program : statements + { parser_result = $1; return 0;} + ; statements : statement_list ; statement_list : statement_list statement @@ -91,7 +119,7 @@ simple_stmt : cbl_func_stmt | perform_stmt ; cbl_func_stmt : cbl_function - | cbl_function op_parms + | cbl_function op_parms | cbl_function assignment_stmt | cbl_function op_parm assignment_stmt ;