-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterC3A.l
More file actions
132 lines (126 loc) · 4.44 KB
/
interC3A.l
File metadata and controls
132 lines (126 loc) · 4.44 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
%{
#include "utils/bilquad.h"
#include "utils/environ.h"
#include <string.h>
BILQUAD list;
char *etiq=NULL,*arg1=NULL,*arg2=NULL,*res=NULL;
int op = 0;
int first = 1;
char *copy(char *src){
int len = strlen(src);
char *dst = malloc(sizeof(int)*(len+1));
return strcpy(dst,src);
}
int fileno();
%}
%option nounput noinput
%s Op Arg1 Arg2 Dest
%%
(JMP|ET)[0-9]+ {
BEGIN Op; free(etiq); etiq=copy(yytext);
}
<Op>:[A-Za-z]+ {
BEGIN Arg1;
if(strncmp("Pl",yytext+1,2)==0) {
op = Pl;
} else if (strncmp("Mo",yytext+1,2)==0) {
op = Mo;
} else if (strncmp("Mu",yytext+1,2)==0) {
op = Mu;
} else if (strncmp("Afc",yytext+1,3)==0) {
op = Afc;
} else if (strncmp("Af",yytext+1,2)==0) {
op = Af;
} else if (strncmp("Sk",yytext+1,2)==0) {
op = Sk;
} else if (strncmp("Jp",yytext+1,2)==0) {
op = Jp;
} else if (strncmp("Jz",yytext+1,2)==0) {
op = Jz;
} else if (strncmp("St",yytext+1,2)==0) {
op = St;
}
}
<Arg1>:[A-Za-z0-9]* {
BEGIN Arg2;
free(arg1);
arg1=copy(yytext+1);
}
<Arg2>:[A-Za-z0-9]* {
BEGIN Dest;
free(arg2);
arg2=copy(yytext+1);
}
<Dest>:[A-Za-z0-9]* {
BEGIN INITIAL;
char *dst=NULL;
dst = copy(yytext+1);
if(first) {
first = 0;
list = creer_bilquad(creer_quad(etiq,op,arg1,arg2,dst));
} else {
BILQUAD tmp = creer_bilquad(creer_quad(etiq,op,arg1,arg2,dst));
list = concatq(list,tmp);
}
free(dst);
}
[ \t\n] ;
. {;}
%%
int yywrap(){
return -1;}
int main(int argc, char *argv[]) {
yylex();
ENV env = Envalloc();
QUAD elem = list.debut;
while (elem != NULL) {
/***Afc***/
if (elem->OP == Afc) {
initenv(&env, elem->RES);
affect(env, elem->RES, atoi(elem->ARG1));
elem = elem->SUIV;
}
/***Pl Mu Mo***/
else if (elem->OP == Pl || elem->OP == Mu || elem->OP == Mo) {
initenv(&env, elem->RES);
initenv(&env, elem->ARG1);
initenv(&env, elem->ARG2);
int res = eval(elem->OP, valch(env, elem->ARG1), valch(env, elem->ARG2));
affect(env, elem->RES, res);
elem = elem->SUIV;
}
/***Af***/
else if (elem->OP == Af) {
initenv(&env, elem->ARG1);
initenv(&env, elem->ARG2);
affect(env, elem->ARG1, valch(env, elem->ARG2));
elem = elem->SUIV;
}
/***Jp***/
else if (elem->OP == Jp) {
QUAD listStart = list.debut;
char *dest = elem->RES;
while (strcmp(listStart->ETIQ,dest) != 0)
listStart = listStart->SUIV;
elem=listStart;
}
/***Je***/
else if (elem->OP == Jz) {
QUAD listStart = list.debut;
char *dest = elem->RES;
if(valch(env, elem->ARG1) == 0){
while (strcmp(listStart->ETIQ,dest) != 0){
listStart = listStart->SUIV;
}
elem=listStart;
}else{
elem = elem->SUIV;
}
} else if (elem->OP == St){
break;
} else if (elem->OP == Sk){
elem = elem->SUIV;
}
}
ecrire_env(env);
}