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 /8 | |
parent | 30047205e440e9ad8984e1830b8b819b5fe1f9f7 (diff) |
add yacc programs
Diffstat (limited to '8')
-rw-r--r-- | 8/input | 1 | ||||
-rw-r--r-- | 8/main.l | 15 | ||||
-rw-r--r-- | 8/main.y | 28 |
3 files changed, 44 insertions, 0 deletions
@@ -0,0 +1 @@ | |||
aaaab | |||
diff --git a/8/main.l b/8/main.l new file mode 100644 index 0000000..3db9d6d --- /dev/null +++ b/8/main.l | |||
@@ -0,0 +1,15 @@ | |||
1 | %{ | ||
2 | #include "y.tab.h" | ||
3 | extern int yylval; | ||
4 | %} | ||
5 | |||
6 | %% | ||
7 | a return A; | ||
8 | b return B; | ||
9 | . return yytext[0]; | ||
10 | \n return 0; | ||
11 | %% | ||
12 | |||
13 | int yywrap() { | ||
14 | return 1; | ||
15 | } | ||
diff --git a/8/main.y b/8/main.y new file mode 100644 index 0000000..04e98a7 --- /dev/null +++ b/8/main.y | |||
@@ -0,0 +1,28 @@ | |||
1 | %{ | ||
2 | #include <stdio.h> | ||
3 | #include <stdlib.h> | ||
4 | int yyerror(char *); | ||
5 | %} | ||
6 | |||
7 | %token A B | ||
8 | %start S | ||
9 | |||
10 | %% | ||
11 | |||
12 | S: C B | ||
13 | | | ||
14 | ; | ||
15 | C: A C | ||
16 | | A A A A | ||
17 | ; | ||
18 | %% | ||
19 | |||
20 | int main() { | ||
21 | yyparse(); | ||
22 | printf("valid string"); | ||
23 | } | ||
24 | |||
25 | int yyerror(char *s) { | ||
26 | printf("error: %s", s); | ||
27 | exit(0); | ||
28 | } | ||