move over files again
This commit is contained in:
parent
9ed9e72ad2
commit
58dad1f505
|
|
@ -1,41 +1,14 @@
|
||||||
%{
|
%{
|
||||||
#define YYDEBUG 1
|
#define YYDEBUG 1
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#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();
|
|
||||||
extern int yylineno;
|
extern int yylineno;
|
||||||
void yyerror(const char*);
|
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;
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%debug
|
%debug
|
||||||
%define parse.error detailed
|
%define parse.error detailed
|
||||||
|
|
||||||
|
|
||||||
%token TOKEN_EOF
|
%token TOKEN_EOF
|
||||||
%token TOKEN_KEYWORD_IDENTIFICATION
|
%token TOKEN_KEYWORD_IDENTIFICATION
|
||||||
%token TOKEN_KEYWORD_DIVISION
|
%token TOKEN_KEYWORD_DIVISION
|
||||||
|
|
@ -102,6 +75,7 @@ statement : section
|
||||||
| data_space
|
| data_space
|
||||||
| data_declaration
|
| data_declaration
|
||||||
;
|
;
|
||||||
|
|
||||||
section : type TOKEN_KEYWORD_DIVISION TOKEN_DOT
|
section : type TOKEN_KEYWORD_DIVISION TOKEN_DOT
|
||||||
| type TOKEN_RUN TOKEN_DOT
|
| type TOKEN_RUN TOKEN_DOT
|
||||||
;
|
;
|
||||||
|
|
@ -119,43 +93,53 @@ simple_stmt : cbl_func_stmt
|
||||||
cbl_func_stmt : cbl_function
|
cbl_func_stmt : cbl_function
|
||||||
| cbl_function op_parms
|
| cbl_function op_parms
|
||||||
| cbl_function assignment_stmt
|
| cbl_function assignment_stmt
|
||||||
| cbl_function op_parms assignment_stmt
|
| cbl_function op_parm assignment_stmt
|
||||||
;
|
;
|
||||||
assignment_stmt : TOKEN_EQUAL ext_function
|
assignment_stmt : TOKEN_EQUAL ext_function
|
||||||
| TOKEN_EQUAL function
|
| TOKEN_EQUAL op_parms
|
||||||
| TOKEN_KEYWORD_TO op_parms
|
| TOKEN_KEYWORD_TO op_parms
|
||||||
;
|
;
|
||||||
op_parms : op_parms TOKEN_ADD op_parms
|
op_parms : op_parm
|
||||||
| op_parms TOKEN_SUB op_parms
|
| op_parms op_parm
|
||||||
| op_parms TOKEN_MULTIPLY op_parms
|
|
||||||
| op_parms TOKEN_DIVIDE op_parms
|
|
||||||
| op_parms TOKEN_EXPONENTIAL op_parms
|
|
||||||
| op_parms TOKEN_LESS_THAN op_parms
|
|
||||||
| op_parms TOKEN_GREATER_THAN op_parms
|
|
||||||
| op_parms TOKEN_EQUAL op_parms
|
|
||||||
| TOKEN_SUB op_parms
|
|
||||||
| TOKEN_LEFT_PARENTHESIS op_parms TOKEN_RIGHT_PARENTHESIS
|
|
||||||
| expr
|
|
||||||
| op_parms op_parms
|
|
||||||
;
|
;
|
||||||
expr : TOKEN_IDENT
|
op_parm : mathmaticalexpr
|
||||||
|
| booleanexpr
|
||||||
|
| type_expr
|
||||||
|
;
|
||||||
|
mathmaticalexpr : type_expr
|
||||||
|
| mathmaticalexpr TOKEN_ADD mathmaticalexpr
|
||||||
|
| mathmaticalexpr TOKEN_SUB mathmaticalexpr
|
||||||
|
| mathmaticalexpr TOKEN_MULTIPLY mathmaticalexpr
|
||||||
|
| mathmaticalexpr TOKEN_DIVIDE mathmaticalexpr
|
||||||
|
| mathmaticalexpr TOKEN_EXPONENTIAL mathmaticalexpr
|
||||||
|
| container_expr
|
||||||
|
| type_expr container_expr
|
||||||
|
;
|
||||||
|
container_expr : TOKEN_LEFT_PARENTHESIS op_parms TOKEN_RIGHT_PARENTHESIS
|
||||||
|
;
|
||||||
|
booleanexpr : mathmaticalexpr TOKEN_LESS_THAN mathmaticalexpr
|
||||||
|
| mathmaticalexpr TOKEN_GREATER_THAN mathmaticalexpr
|
||||||
|
| mathmaticalexpr TOKEN_EQUAL mathmaticalexpr
|
||||||
|
;
|
||||||
|
type_expr : TOKEN_IDENT
|
||||||
| TOKEN_INTEGER
|
| TOKEN_INTEGER
|
||||||
| TOKEN_STRING
|
| TOKEN_STRING
|
||||||
| TOKEN_SPACE
|
| TOKEN_SPACE
|
||||||
;
|
| TOKEN_SUB TOKEN_IDENT
|
||||||
function : op_parms
|
|
||||||
;
|
;
|
||||||
ext_function : TOKEN_KEYWORD_FUNCTION TOKEN_IDENT TOKEN_LEFT_PARENTHESIS TOKEN_IDENT TOKEN_RIGHT_PARENTHESIS
|
ext_function : TOKEN_KEYWORD_FUNCTION TOKEN_IDENT TOKEN_LEFT_PARENTHESIS TOKEN_IDENT TOKEN_RIGHT_PARENTHESIS
|
||||||
;
|
;
|
||||||
cbl_function : TOKEN_DISPLAY
|
cbl_function : TOKEN_DISPLAY
|
||||||
| TOKEN_MOVE
|
| TOKEN_MOVE
|
||||||
| TOKEN_KEYWORD_COMPUTE
|
| TOKEN_KEYWORD_COMPUTE
|
||||||
| TOKEN_PERFORM
|
|
||||||
;
|
;
|
||||||
if_branch : TOKEN_IF op_parms
|
if_branch : if_start statements else_parts
|
||||||
| TOKEN_ELSE_IF op_parms
|
;
|
||||||
| TOKEN_ELSE statement
|
if_start : TOKEN_IF booleanexpr
|
||||||
| TOKEN_END_IF
|
;
|
||||||
|
else_parts :
|
||||||
|
| TOKEN_ELSE_IF booleanexpr statements else_parts
|
||||||
|
| TOKEN_ELSE statements
|
||||||
;
|
;
|
||||||
perform_stmt : TOKEN_PERFORM TOKEN_VARYING TOKEN_IDENT TOKEN_KEYWORD_FROM TOKEN_INTEGER TOKEN_KEYWORD_BY TOKEN_INTEGER TOKEN_UNTIL op_parms
|
perform_stmt : TOKEN_PERFORM TOKEN_VARYING TOKEN_IDENT TOKEN_KEYWORD_FROM TOKEN_INTEGER TOKEN_KEYWORD_BY TOKEN_INTEGER TOKEN_UNTIL op_parms
|
||||||
| TOKEN_END_PERFORM
|
| TOKEN_END_PERFORM
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,10 @@
|
||||||
DISPLAY "The equation has two distinct real roots: "
|
DISPLAY "The equation has two distinct real roots: "
|
||||||
DISPLAY "Root 1: " root1
|
DISPLAY "Root 1: " root1
|
||||||
DISPLAY "Root 2: " root2
|
DISPLAY "Root 2: " root2
|
||||||
|
|
||||||
ELSE IF discriminant = 0
|
ELSE IF discriminant = 0
|
||||||
COMPUTE root1 = -b / (2 * a)
|
COMPUTE root1 = -b / (2 * a)
|
||||||
DISPLAY "The equation has one real root: "
|
DISPLAY "The equation has one real root: "
|
||||||
DISPLAY "Root: " root1
|
DISPLAY "Root: " root1
|
||||||
ELSE
|
ELSE
|
||||||
DISPLAY "The equation has no real roots."
|
DISPLAY "The equation has no real roots."
|
||||||
|
|
||||||
STOP RUN.
|
STOP RUN.
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ PROCEDURE DIVISION.
|
||||||
MOVE WS-SORT-ROW(WS-J) TO WS-TEMP-ROW
|
MOVE WS-SORT-ROW(WS-J) TO WS-TEMP-ROW
|
||||||
MOVE WS-SORT-ROW(WS-J + 1) TO WS-SORT-ROW(WS-J)
|
MOVE WS-SORT-ROW(WS-J + 1) TO WS-SORT-ROW(WS-J)
|
||||||
MOVE WS-TEMP-ROW TO WS-SORT-ROW(WS-J + 1)
|
MOVE WS-TEMP-ROW TO WS-SORT-ROW(WS-J + 1)
|
||||||
END-IF
|
|
||||||
END-PERFORM
|
END-PERFORM
|
||||||
END-PERFORM
|
END-PERFORM
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
%{
|
%{
|
||||||
#include "parser.h"
|
#include "token.h"
|
||||||
%}
|
%}
|
||||||
NAME [a-zA-Z]([a-zA-Z0-9_-]*[a-zA-Z0-9])?
|
NAME [a-zA-Z]([a-zA-Z0-9_-]*[a-zA-Z0-9])?
|
||||||
DIGIT [0-9]+
|
DIGIT [0-9]+
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue