-
Notifications
You must be signed in to change notification settings - Fork 0
/
syn.y
74 lines (63 loc) · 1.11 KB
/
syn.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
%{
#include<stdio.h>
#include<stdlib.h>
int yylex(void);
void yyerror(char *s);
%}
%token IDENTIFIER REM PRINT CLS DIM READ DATA RUN
%token WHILE WEND FOR TO NEXT IF ELSE THEN GOTO INPUT
%token NOT AND OR XOR EQV IMP
%token LTE GTE NE LT GT EQ MOD
%token INTEGER FLOAT STRING STRINGV INTEGERV SPV DBV
%nonassoc IFX
%nonassoc ELSE
%left GTE LTE EQ NE GT LT
%left '+' '-'
%left '*' '/'
%%
program:
stmts
;
stmts:
stmts stmt
| stmt
;
stmt:
expr '\n'
| PRINT expr '\n'
| WHILE expr '\n' stmts WEND
| INPUT expr ';' IDENTIFIER '\n'
| FOR IDENTIFIER EQ expr TO expr '\n' stmts NEXT IDENTIFIER '\n'
| stmt_list RUN '\n'
| IF expr THEN stmt stmt1
;
stmt1: ELSE stmt
|'\n'
;
stmt_list: stmt_list INTEGER stmt
| INTEGER stmt
;
expr:
INTEGER
| IDENTIFIER
| STRING
| expr '+' expr
| expr '-' expr
| expr '*' expr
| expr '/' expr
| expr GT expr
| expr LT expr
| expr GTE expr
| expr LTE expr
| expr NE expr
| expr EQ expr
;
%%
void yyerror(char *s) {
printf("%s\n", s);
}
void main()
{
printf("enter expr\n");
yyparse();
}