-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsposv.y
125 lines (110 loc) · 2.57 KB
/
sposv.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
123
124
125
/*Lucas Dhein*/
/*Analisador Sintático*/
%{
#include<stdio.h>
#include "y.tab.h"
int yylex();
int yyerror(char *);
FILE *yyin;
%}
//Deinição dos tokens
%token TYPE
%token ID
%token SC
%token COMMA
%token COLON
%token IF
%token ELSE
%token CLOSE_PARENT
%token OPEN_PARENT
%token CLOSE_BRACE
%token OPEN_BRACE
%token MATH
%token RELATIONAL
%token ATRIB
%token SWITCH
%token BREAK
%token DEFAULT
%token CASE
%token DIGIT_INT
%token DIGIT_FLOAT
%token STRING
%token OPEN_SQ
%token CLOSE_SQ
%token WHILE;
%token FOR;
%token INCRE_DEC_OPERATOR;
%token CARACTERE;
//Inicio da gramatica
%%
start:
|TYPE builtin SC {printf("MATCH REGRA #1\n");} start
|IF OPEN_PARENT condition CLOSE_PARENT OPEN_BRACE commands CLOSE_BRACE opt_else {printf("MATCH REGRA #2\n");} start
|SWITCH OPEN_PARENT ID CLOSE_PARENT OPEN_BRACE case_list opt_default CLOSE_BRACE {printf("MATCH REGRA #3\n");} start
|WHILE OPEN_PARENT condition CLOSE_PARENT OPEN_BRACE commands CLOSE_BRACE {printf("MATCH REGRA #4\n");} start
|FOR OPEN_PARENT ini_variable SC condition SC ID INCRE_DEC_OPERATOR CLOSE_PARENT OPEN_BRACE commands CLOSE_BRACE {printf("MATCH REGRA #5\n");} start
;
builtin:
ID
|builtin COMMA ID
|ID OPEN_SQ DIGIT_INT CLOSE_SQ
|builtin ID OPEN_SQ DIGIT_INT CLOSE_SQ
;
opt_else:
|ELSE OPEN_BRACE commands CLOSE_BRACE
;
condition:
target RELATIONAL target
;
target:
ID
|DIGIT_INT
|DIGIT_FLOAT
;
commands:
ID ATRIB operation SC
|ID ATRIB operation SC commands
;
operation:
target MATH target
|target
;
case_list:
CASE case_option COLON OPEN_BRACE commands BREAK SC CLOSE_BRACE case2
|CASE case_option COLON case2
;
case2:
|CASE case_option COLON OPEN_BRACE commands BREAK SC CLOSE_BRACE case3
|CASE case_option COLON case3
;
case3:
|CASE case_option COLON OPEN_BRACE commands BREAK SC CLOSE_BRACE
;
case_option:
DIGIT_INT
|CARACTERE
;
opt_default:
|DEFAULT COLON OPEN_BRACE commands CLOSE_BRACE
;
ini_variable:
ID ATRIB ID
|ID ATRIB DIGIT_INT
;
%%
//Incio dos comandos em C
int yywrap()
{
return 1;
}
int main(int argc,char **argv)
{
yyin=fopen(argv[1],"r");
yyparse();
fclose(yyin);
}
int yyerror(char *s)
{
fprintf(stderr,"INVALIDO\n");
return -1;
}