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
|
/*
implementation of two stacks used in xetal,
Copyright (C) 1991 Raphael Cerf (e-mail: cerf@ens.ens.fr)
This file is part of xetal.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "proto.h"
#include "stack.h"
/*
* file stack
*/
char *fich_name(e)
fich_t *e;
{
return(e->name);
}
FILE *fich_fd(e)
fich_t *e;
{
return(e->fd);
}
long fich_line(e)
fich_t *e;
{
return(e->line);
}
fich_t f_stack[F_MAX];
int f_top=0;
int is_f_stack_empty() {
return(f_top==0);
}
int is_f_stack_full() {
return(f_top==F_MAX-1);
}
fich_t *f_pop() {
return( &(f_stack[--f_top]) );
}
void f_push(e)
fich_t *e;
{
f_stack[f_top++]=*e;
}
fich_t *f_read()
{
if (f_top==0) return((fich_t *)0);
else return(f_stack+f_top-1);
}
void f_display() {
int i;
printf("%d elements\n", f_top);
for (i=0; i<f_top; i++)
printf("%s : %d", fich_name(f_stack+i), fich_line(f_stack+i));
printf("\n");
}
/*
* LEX states stack
*/
int S_stack[S_MAX];
int S_top=0;
int empty_S_stack() {
while(S_top>0) S_pop();
}
int is_S_stack_empty() {
return(S_top==0);
}
int is_S_stack_full() {
return(S_top==S_MAX-1);
}
int is_S_in_stack(e)
int e;
{
int i;
for (i=0; i<S_top; i++) {
if (S_stack[i]==e) break;
}
if (i<S_top) return 1;
else return 0;
}
int S_pop() {
return( S_stack[--S_top] );
}
void S_push(e)
int e;
{
S_stack[S_top++]=e;
}
int S_read()
{
if (S_top==0) return(0);
else return(*(S_stack+S_top-1));
}
void S_display() {
int i;
printf("%d elements\n", S_top);
for (i=0; i<S_top; i++)
printf("%d", *(S_stack+i));
printf("\n");
}
|