-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.l
156 lines (123 loc) · 5.06 KB
/
main.l
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
%{
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "y.tab.h"
//Declaração de variáveis
char nova_str[200];
void yyerror(char *);
char entrada[200], saida[200];
int tam_str;
int k; //indice da saida
//Funções
void retirar_maiorque_e_menorque(char *entrada, char *saida, int numeroDeTags){
//Declaração de variáveis
int tam_str, k, tagsEncontradas;
//Limpando a saida
for (int j=0; j<200; j++){
saida[j] = '\0';
}
//Inicializando as variáveis
tagsEncontradas = 0;
tam_str = strlen(entrada);
//Varre a entrada
for (int i=0; i<tam_str; i++){
//Se encontra o fim de uma tag
if (entrada[i] == '>'){
tagsEncontradas++;
//Se já abriu tags o suficiente pra pegar o conteúdo
if(tagsEncontradas == numeroDeTags){
i++;
k = 0;
//Copia o conteúdo até achar a abertura da tag de fechar
while (entrada[i] != '<'){
saida[k] = entrada[i];
i++;
k++;
}
break;
}
}
}
return;
}
%}
PALAVRA [0-9a-zA-ZÇÃ\-\ ]+
NUMERO [0-9]+[,]*[.]*[0-9]*
EMAIL [a-zA-Z0-9.]*@[a-zA-Z0-9.]*
%%
(<TOMADOR_CIDADE>{PALAVRA}<\/TOMADOR_CIDADE>) { //BELÉM
retirar_maiorque_e_menorque(yytext, nova_str, 1);
yylval.string=strdup(nova_str);
return CIDADE_TOMADOR;
}
(<ns3:OrgaoGerador>[ \t\r\n]+<ns3:CodigoMunicipio>{NUMERO}<\/ns3:CodigoMunicipio>) { //CORUMBÁ
retirar_maiorque_e_menorque(yytext, nova_str, 2);
yylval.string=strdup(nova_str);
return CIDADE_TOMADOR;
}
(<CodigoMunicipio>{NUMERO}<\/CodigoMunicipio><Uf>{PALAVRA}<\/Uf><Cep>{NUMERO}<\/Cep><\/Endereco><Contato><Telefone>{NUMERO}<\/Telefone><Email>{EMAIL}<\/Email><\/Contato><\/Tomador>) { //JOAO MOLENVADE_1
(<ns3:PrestadorServico>[ \t\r\n]*<ns3:IdentificacaoPrestador>[ \t\r\n]*<ns3:CpfCnpj>[ \t\r\n]*(<ns3:Cnpj>{NUMERO}<\/ns3:Cnpj>[ \t\r\n]*)*(<ns3:Cpf>{NUMERO}<\/ns3:Cpf>[ \t\r\n]*)*<\/ns3:CpfCnpj>[ \t\r\n]*<ns3:InscricaoMunicipal>{NUMERO}<\/ns3:InscricaoMunicipal>[ \t\r\n]*<\/ns3:IdentificacaoPrestador>[ \t\r\n]*<ns3:RazaoSocial>{PALAVRA}<\/ns3:RazaoSocial>[ \t\r\n]*<ns3:NomeFantasia>{PALAVRA}<\/ns3:NomeFantasia>[ \t\r\n]*<ns3:Endereco>[ \t\r\n]*<ns3:Endereco>{PALAVRA}<\/ns3:Endereco>[ \t\r\n]*<ns3:Numero>{NUMERO}<\/ns3:Numero>[ \t\r\n]*<ns3:Complemento>{PALAVRA}<\/ns3:Complemento>[ \t\r\n]*<ns3:Bairro>{PALAVRA}<\/ns3:Bairro>[ \t\r\n]*[ \t\r\n]*<ns3:CodigoMunicipio>{NUMERO}<\/ns3:CodigoMunicipio>) { //CORUMBÁ
retirar_maiorque_e_menorque(yytext, nova_str, 23);
yylval.string=strdup(nova_str);
return CIDADE_PRESTADOR;
}
(<ns3:PrestadorServico>[ \t\r\n]*<ns3:IdentificacaoPrestador>[ \t\r\n]*<ns3:CpfCnpj>[ \t\r\n]*(<ns3:Cnpj>{NUMERO}<\/ns3:Cnpj>[ \t\r\n]*)*(<ns3:Cpf>{NUMERO}<\/ns3:Cpf>[ \t\r\n]*)*<\/ns3:CpfCnpj>[ \t\r\n]*<ns3:InscricaoMunicipal>{NUMERO}<\/ns3:InscricaoMunicipal>[ \t\r\n]*<\/ns3:IdentificacaoPrestador>[ \t\r\n]*<ns3:RazaoSocial>{PALAVRA}<\/ns3:RazaoSocial>[ \t\r\n]*<ns3:NomeFantasia>{PALAVRA}<\/ns3:NomeFantasia>[ \t\r\n]*<ns3:Endereco>[ \t\r\n]*<ns3:Endereco>{PALAVRA}<\/ns3:Endereco>[ \t\r\n]*<ns3:Numero>{NUMERO}<\/ns3:Numero>[ \t\r\n]*<ns3:Complemento>{PALAVRA}<\/ns3:Complemento>[ \t\r\n]*<ns3:Bairro>{PALAVRA}<\/ns3:Bairro>[ \t\r\n]*[ \t\r\n]*<ns3:CodigoMunicipio>{NUMERO}<\/ns3:CodigoMunicipio>) { //CORUMBÁ
retirar_maiorque_e_menorque(yytext, nova_str, 23);
yylval.string=strdup(nova_str);
return CIDADE_PRESTADOR;
}
(<CodigoMunicipio>{NUMERO}<\/CodigoMunicipio><Uf>{PALAVRA}<\/Uf><Cep>{NUMERO}<\/Cep><\/Endereco><Contato><Telefone>{NUMERO}<\/Telefone><\/Contato><\/Tomador>) { //JOAO MOLENVADE_2
retirar_maiorque_e_menorque(yytext, nova_str, 1);
yylval.string=strdup(nova_str);
return CIDADE_TOMADOR;
}
(<PRESTADOR_CIDADE>{PALAVRA}<\/PRESTADOR_CIDADE>) { //BELÉM
retirar_maiorque_e_menorque(yytext, nova_str, 1);
yylval.string=strdup(nova_str);
return CIDADE_PRESTADOR;
}
(<CodigoMunicipio>{NUMERO}<\/CodigoMunicipio><Uf>{PALAVRA}<\/Uf><Cep>{NUMERO}<\/Cep><\/Endereco><Contato><Telefone>{NUMERO}<\/Telefone><Email>{EMAIL}<\/Email><\/Contato><\/PrestadorServico>) { //JOAO MOLENVADE
retirar_maiorque_e_menorque(yytext, nova_str, 1);
yylval.string=strdup(nova_str);
return CIDADE_PRESTADOR;
}
(<VALOR_SERVICO>{NUMERO}<\/VALOR_SERVICO>) { //BELÉM
retirar_maiorque_e_menorque(yytext, nova_str, 1);
yylval.string=strdup(nova_str);
return VALOR_SERVICO;
}
(<ns3:ValorServicos>{NUMERO}<\/ns3:ValorServicos>) { //CORUMBÁ
retirar_maiorque_e_menorque(yytext, nova_str, 1);
yylval.string=strdup(nova_str);
return VALOR_SERVICO;
}
(<ValorServicos>{NUMERO}<\/ValorServicos>) { //JOAO MONLEVADE
retirar_maiorque_e_menorque(yytext, nova_str, 1);
yylval.string=strdup(nova_str);
return VALOR_SERVICO;
}
(<VALOR_ISS_RET>{NUMERO}<\/VALOR_ISS_RET>) { //BELÉM
retirar_maiorque_e_menorque(yytext, nova_str, 1);
yylval.string=strdup(nova_str);
return VALOR_ISS_RET;
}
(<ns3:IssRetido>{NUMERO}<\/ns3:IssRetido>) { //CORUMBÁ
retirar_maiorque_e_menorque(yytext, nova_str, 1);
yylval.string=strdup(nova_str);
return VALOR_ISS_RET;
}
(<IssRetido>{NUMERO}<\/IssRetido>) { //JOAO MONLEVADE
retirar_maiorque_e_menorque(yytext, nova_str, 1);
yylval.string=strdup(nova_str);
return VALOR_ISS_RET;
}
. ;
[ \t\r\n] ;
<<EOF>> {
return EOL;
}
%%
int yywrap() {
return 1;
}