Skip to content

Instantly share code, notes, and snippets.

@Philhil
Created March 15, 2017 22:47
Show Gist options
  • Save Philhil/77a77a5dbf84ffc793e6de883212787a to your computer and use it in GitHub Desktop.
Save Philhil/77a77a5dbf84ffc793e6de883212787a to your computer and use it in GitHub Desktop.
%{
#include <stdio.h>
extern int yyerror(char* err);
extern int yylex(void);
extern FILE *yyin;
%}
%start seq
%token VAR
%token FUNC
%token PRAEDIKAT
%token ARROW
%token UND
%token KOMMA
%token TRUE
%token FALSE
%token KLAMMERO
%token KLAMMERC
%token NEWLINE
%%
term: VAR {printf("VAR -> term \n");}
| FUNC {printf("FUNC -> term \n");}
| FUNC KLAMMERO params KLAMMERC {printf("FUNC(params) -> term\n");}
params: term {printf("term -> params\n");}
| term KOMMA params {printf("term , params -> params\n");}
atom: PRAEDIKAT {printf("PRAEDIKAT -> atom\n");}
| PRAEDIKAT KLAMMERO params KLAMMERC {printf("PRAEDIKAT(params) -> atom\n");}
formel: body ARROW FALSE {printf("body -> FALSE -> formel\n");}
| body ARROW atom {printf("body -> atom -> formel\n");}
| TRUE ARROW atom {printf("TRUE -> atom -> formel\n");}
body: atom {printf("atom -> body\n");}
| body UND atom {printf("body & atom -> body\n");}
seq: formel NEWLINE {printf("formel NEWLINE -> seq\n");}
| seq NEWLINE formel {printf("seq NEWLINE formel -> seq\n");}
| NEWLINE {printf("NEWLINE -> seq\n");}
%%
int yyerror(char* err)
{
printf("Error: %s\n", err);
return 0;
}
int main( int argc, char **argv )
{
++argv, --argc;
if(argc > 0)
{
yyin = fopen(argv[0], "r");
}
else
{
yyin = stdin;
}
return yyparse();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment