fix sample

This commit is contained in:
vel 2024-11-13 17:12:09 -08:00
parent 1802175103
commit a089fe73db
Signed by: velvox
GPG Key ID: 59D9762F674151DF
3 changed files with 34 additions and 6 deletions

View File

@ -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.

View File

@ -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.

View File

@ -1,9 +1,35 @@
%{
#define YYDEBUG 1
#include <stdio.h>
extern int yylineno;
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#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