diff options
author | Akshay <[email protected]> | 2021-04-30 17:52:13 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2021-04-30 17:52:13 +0100 |
commit | 8a57bedc04fff7a92ef6d2762cfe5fc17050f021 (patch) | |
tree | 192ea2a1bd2eec0c0f84a9cb7adc9b10d005e1db /9 | |
parent | 30047205e440e9ad8984e1830b8b819b5fe1f9f7 (diff) |
add yacc programs
Diffstat (limited to '9')
-rw-r--r-- | 9/input | 1 | ||||
-rw-r--r-- | 9/main.l | 16 | ||||
-rw-r--r-- | 9/main.y | 30 |
3 files changed, 47 insertions, 0 deletions
@@ -0,0 +1 @@ | |||
aaabbbbc | |||
diff --git a/9/main.l b/9/main.l new file mode 100644 index 0000000..04c6bf0 --- /dev/null +++ b/9/main.l | |||
@@ -0,0 +1,16 @@ | |||
1 | %{ | ||
2 | #include "y.tab.h" | ||
3 | extern int yylval; | ||
4 | %} | ||
5 | |||
6 | %% | ||
7 | a return A; | ||
8 | b return B; | ||
9 | c return C; | ||
10 | . return yytext[0]; | ||
11 | \n return 0; | ||
12 | %% | ||
13 | |||
14 | int yywrap() { | ||
15 | return 1; | ||
16 | } | ||
diff --git a/9/main.y b/9/main.y new file mode 100644 index 0000000..0db29c1 --- /dev/null +++ b/9/main.y | |||
@@ -0,0 +1,30 @@ | |||
1 | %{ | ||
2 | #include <stdio.h> | ||
3 | #include <stdlib.h> | ||
4 | int yylex(); | ||
5 | int yyerror(char *); | ||
6 | %} | ||
7 | |||
8 | %token A B C | ||
9 | |||
10 | %% | ||
11 | S: X Y | ||
12 | | | ||
13 | ; | ||
14 | X: A X B | ||
15 | | | ||
16 | ; | ||
17 | Y: B Y C | ||
18 | | | ||
19 | ; | ||
20 | %% | ||
21 | |||
22 | int main() { | ||
23 | yyparse(); | ||
24 | printf("valid string"); | ||
25 | } | ||
26 | |||
27 | int yyerror(char *s) { | ||
28 | printf("error: %s", s); | ||
29 | exit(0); | ||
30 | } | ||