aboutsummaryrefslogtreecommitdiff
path: root/7
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-04-30 17:55:19 +0100
committerAkshay <[email protected]>2021-04-30 17:55:19 +0100
commitda1764a9f839e1d29b2bee12d35534f71f05c6ff (patch)
treed410c2191e571f9e6945ed88afd3faa1175675b3 /7
parent9ff0cec8b507d9164d8828dcb2a87012e140fdf5 (diff)
law & order
Diffstat (limited to '7')
-rw-r--r--7/main.l21
-rw-r--r--7/main.y34
2 files changed, 0 insertions, 55 deletions
diff --git a/7/main.l b/7/main.l
deleted file mode 100644
index 2f98161..0000000
--- a/7/main.l
+++ /dev/null
@@ -1,21 +0,0 @@
1%{
2extern int yylval;
3%}
4
5%%
6[0-9]+ {
7 yylval = atoi(yytext);
8 return NUM;
9}
10"+" return ADD;;
11"-" return SUB;
12"*" return MUL;
13"/" return DIV;
14"(" return LPAR;
15")" return RPAR;
16\n return 0;
17%%
18
19int yywrap() {
20 return 1;
21}
diff --git a/7/main.y b/7/main.y
deleted file mode 100644
index 26a2007..0000000
--- a/7/main.y
+++ /dev/null
@@ -1,34 +0,0 @@
1%{
2#include <stdio.h>
3#include <stdlib.h>
4int yylex();
5int yyerror(char *);
6%}
7
8%token NUM ADD SUB MUL DIV LPAR RPAR
9%left ADD SUB MUL DIV
10%right NEG
11
12%%
13
14S:
15 E { printf("\n"); };
16E:
17 E ADD E { printf("+ "); }
18 | E MUL E { printf("* "); }
19 | E SUB E { printf("- "); }
20 | E DIV E { printf("/ "); }
21 | LPAR E RPAR
22 | SUB E %prec NEG { printf("- "); }
23 | NUM { printf("%d ", yylval); }
24 ;
25%%
26
27int main() {
28 yyparse();
29}
30
31int yyerror(char *s) {
32 printf("error: %s", s);
33 exit(0);
34}