-
Notifications
You must be signed in to change notification settings - Fork 0
/
pilha.y
94 lines (82 loc) · 954 Bytes
/
pilha.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
%{
#include <stdio.h>
#include <string.h>
#include "pilha.h"
void yyerror(const char *str)
{
fprintf(stderr, "erro r: %s\n",str);
}
int yywrap()
{
return 1;
}
main()
{
last = 0;
yyparse();
}
%}
%token TOKPOP OPENP NUMBER CLOSEP TOKPUSH TOKLIST
%union
{
int number;
}
%token <number> NUMBER
%%
commands: /* EMPTY */
| commands command
;
command:
pop
|
push
|
list
;
pop:
TOKPOP OPENP NUMBER CLOSEP
{
int popeado = pop($3);
printf("\tPop value %d\n",popeado);
}
|
TOKPOP NUMBER
{
int popeado = pop($2);
printf("\tPop value %d\n",popeado);
}
;
push:
TOKPUSH
{
if(last > 0)
{
int pusheado = push();
printf("\tPop value %d\n",pusheado);
}
else
{
printf("\tEmpty\n");
}
}
;
list:
TOKLIST
{
if(last > 0)
{
int j;
printf("[ ");
for (j = 0; j < last; j++ )
{
printf("%d ", pilha[j] );
}
printf("]\n");
}
else
{
printf("[ ]\n");
}
}
;
%%