-
Notifications
You must be signed in to change notification settings - Fork 0
/
SBM.y
51 lines (49 loc) · 1.03 KB
/
SBM.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
%{
#include <stdio.h>
#include <string.h>
#include <math.h>
int yylex();
void yyerror(const char *message);
%}
%union {
int ival;
}
%token ADD
%token SUB
%token MUL
%token MOD
%token LOAD
%token INC
%token DEC
%token DELETE
%token SWITCH
%token COPY
%token END_OF_FILE;
%token <ival> INUMBER
%type <ival> exp
%type <ival> cpy
%%
input : line {return 0; }
;
line : exp /*END_OF_FILE*/ { printf ("%d\n", $1); }
;
exp : LOAD INUMBER { $$ = $2; }
| exp exp ADD { $$ = $2 + $1; }
| exp exp SUB { $$ = $2 - $1; }
| exp exp MUL { $$ = $2 * $1; }
| exp exp MOD { $$ = $2 % $1; }
| exp INC { $$ = $1 + 1 ; }
| exp DEC { $$ = $1 - 1 ; }
| exp exp DELETE { $$ = $1; }
| exp COPY { $2 = $1; } // Have no idea how to impliment!
| exp exp SWITCH { int tmp=$1; $1=$2; $2=tmp; }
;
%%
void yyerror (const char *message)
{
printf ("Invalid format\n");
}
int main(int argc, char *argv[]) {
yyparse();
return(0);
}