forked from danigfavero/LAREIRA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jogo.y
122 lines (104 loc) · 2.66 KB
/
jogo.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 "lista.h"
//#include "salas.h"
#include "acoes.h"
//#include "elemento.h"
int yylex();
int yyerror(char *);
%}
/* Declaracoes */
%union {
void *tptr;
char *str;
int direc;
}
%token <tptr> VERBO OBJ LUGAR
/* DESC representa uma palavra desconhecida */
%token <str> DESC
%token NORTE SUL LESTE OESTE VAPARA EOL FIM INVENT
%type <direc> dir
%type <tptr> obj
%defines
%%
/* Gramatica */
input: EOL { printf("Zzzz...\n"); }
| cmd
| VAPARA {
/* movimentação */
printf("Seguindo para ");
}
dir {
atual = atual->def.lugar.saidas[$3];
Examinar(NULL,NULL);
} eol
| dir {
/* movimentação */
Examinar(atual,NULL);
} eol
| INVENT {
/* listagem do inventário */
if (Tvazia(personagem.conteudo))
puts("Você está sem nada no momento...");
else {
puts("Você tem:");
imprimeConteudo(personagem, 4);
}
} eol
| FIM { return 0;}
| DESC { puts("Nada do que você diz está fazendo sentido.");}
| error eol;
;
cmd: VERBO {
//puts("reconheci");
/* Intransitivo */
//Busca o verbo na lista e realiza a acao;
fptr acao = (fptr) LBuscaGlobal(sym_table, $1, 'P');
//puts("encontrei");
acao(NULL, NULL);
} eol
| VERBO obj {
/* Transitivo direto */
//Busca o verbo e o objeto
//puts("verbo obj");
//printf("%s\n", (char*)$1);
fptr acao = (fptr) LBuscaGlobal(sym_table, $1, 'P');
//puts("reconheci acao");
Elemento *e = (Elemento*) LBuscaGlobal(sym_table, $2, 'P');
//printf("peguei o %s\n", e->nome);
acao(e, NULL);
} eol
| VERBO obj obj {
/* Bitransitivo */
//Busca o verbo e os dois objetos
fptr acao = (fptr) LBuscaGlobal(sym_table, $1, 'P');
Elemento *e = (Elemento*) LBuscaGlobal(sym_table, $2, 'P');
Elemento *e2 = (Elemento*) LBuscaGlobal(sym_table, $3, 'P');
acao(e, e2);
} eol
| VERBO DESC {
printf("%s??\n", $2);
} eol
| VERBO obj DESC {
printf("não sei o que é isso: %s\n", $3);
} eol
| VERBO DESC DESC {
printf("Pare de jogar e vá descansar um pouco\n"
"Fazer isso com %s e %s, que coisa\n", $2,$3
);
} eol
;
obj: OBJ { $$ = $1;}
| LUGAR { $$ = $1;}
dir: NORTE { Mover(atual, 0); }
| SUL { Mover(atual, 1); }
| LESTE { Mover(atual, 2); }
| OESTE { Mover(atual, 3); }
| DESC { puts("... (onde é isso?)"); $$=-1;}
;
eol: EOL {return 1;}
%%
int yyerror(char *s) {
puts("Não entendi...");
return 0;
}