From 8a57bedc04fff7a92ef6d2762cfe5fc17050f021 Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 30 Apr 2021 22:22:13 +0530 Subject: add yacc programs --- 9/input | 1 + 9/main.l | 16 ++++++++++++++++ 9/main.y | 30 ++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 9/input create mode 100644 9/main.l create mode 100644 9/main.y (limited to '9') diff --git a/9/input b/9/input new file mode 100644 index 0000000..01efb5e --- /dev/null +++ b/9/input @@ -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 @@ +%{ +#include "y.tab.h" +extern int yylval; +%} + +%% +a return A; +b return B; +c return C; +. return yytext[0]; +\n return 0; +%% + +int yywrap() { + return 1; +} 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 @@ +%{ +#include +#include +int yylex(); +int yyerror(char *); +%} + +%token A B C + +%% +S: X Y + | + ; +X: A X B + | + ; +Y: B Y C + | + ; +%% + +int main() { + yyparse(); + printf("valid string"); +} + +int yyerror(char *s) { + printf("error: %s", s); + exit(0); +} -- cgit v1.2.3