-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrammar.y
122 lines (100 loc) · 2.32 KB
/
grammar.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
%{
#include <stdio.h>
#include "data.h"
extern int yyerror(char* err);
extern int yylex(void);
extern FILE *yyin;
lst_formel* lstformel = NULL;
int varcounter = 0;
%}
%start seq
%token VAR
%token FUNC
%token PRAEDIKAT
%token ARROW
%token UND
%token KOMMA
%token TRUE
%token FALSE
%token KLAMMERO
%token KLAMMERC
%token NEWLINE
%union {
term *t;
atom *a;
formel *f;
lst_term *lt;
lst_atom *la;
lst_formel *lf;
char* text;
}
%%
term: VAR {
term *_term = (term*) malloc(sizeof(term));
char* _var = (char*) malloc(sizeof($<text>1));
strcpy(_var, $<text>1);
append_char(_var, (char)(varcounter+ 48));
_term->varorfunc = _var;
_term->isvar = true;
_term->liste = NULL;
$<t>$ = _term;
}
| FUNC {
term *_term = (term*) malloc(sizeof(term));
_term->varorfunc = $<text>1;
_term->isvar = false;
_term->liste = NULL;
$<t>$ = _term;
}
| FUNC KLAMMERO params KLAMMERC {
term *_term = (term*) malloc(sizeof(term));
_term->varorfunc = $<text>1;
_term->isvar = false;
_term->liste = $<lt>3;
$<t>$ = _term;
}
//params = liste von termen
params: term { $<lt>$ = create_lst_term($<t>1);}
| term KOMMA params { $<lt>$ = append_lst_term($<lt>3, $<t>1);}
atom: PRAEDIKAT { $<a>$ = create_atom($<text>1, NULL);}
| PRAEDIKAT KLAMMERO params KLAMMERC {$<a>$ = create_atom($<text>1, $<lt>3);}
//body == liste von atomen
body: atom {$<la>$ = create_lst_atom($<a>1);}
| body UND atom {$<la>$ = append_lst_atom($<la>1, $<a>3);}
formel: body ARROW atom { $<f>$ = create_formel($<a>3, $<la>1); varcounter++;}
| body ARROW FALSE { $<f>$ = create_formel(NULL, $<la>1); varcounter++;}
| TRUE ARROW atom { $<f>$ = create_formel($<a>3, NULL); varcounter++;}
seq: formel { lstformel = append_lst_formel(lstformel, $<f>1);}
| formel NEWLINE seq { lstformel = append_lst_formel(lstformel, $<f>1);}
| formel NEWLINE { lstformel = append_lst_formel(lstformel, $<f>1);}
%%
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;
}
yyparse();
print_lst_formel(lstformel);
printf("\n\n START RESULUTION\n\n");
if(satisfiable(lstformel,lstformel))
{
printf("\n\nunsatisfiable\n\n");
return 1;
}
else
{
printf("\n\nsatisfiable\n\n");
}
return 0;
}