-
Notifications
You must be signed in to change notification settings - Fork 2
/
Po_syn_stack.cpp
105 lines (92 loc) · 4.61 KB
/
Po_syn_stack.cpp
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
/*******************************************************************/
/*** FILE : Po_syn_stack.c ***/
/*** AUTHOR: Sekhar Muddana ***/
/*** PUBLIC ROUTINES: ***/
/*** void Push_token() ***/
/*** int Get_top_token() ***/
/*** int Get_next_to_top_token() ***/
/*** int Pop_token() ***/
/*** void Print_stack() ***/
/*** PRIVARE ROUTINES: None. ***/
/*** MODULE DESCRIPTION: ***/
/*** This module contains routines which manipulate Syntax ***/
/*** stack These routines are called by the module ***/
/*** Po_parse_poly.c while doing the parsing. ***/
/*******************************************************************/
#include <stdio.h>
#include "Po_syn_stack.h"
#include "Po_parse_poly.h"
#if 0
static void Print_syn_stack(int Stack[], int Sp);
#endif
/*******************************************************************/
/* MODIFIES: */
/* Stack -- Syntax stack. */
/* Sp_ptr -- Syntax stack pointer. */
/* REQUIRES: */
/* token -- to be pushed onto the stack. */
/* RETURNS: None. */
/*******************************************************************/
void Push_token(int Stack[], int *Sp_ptr, int Token)
{
if (*Sp_ptr < STACK_SIZE - 1)
Stack[++(*Sp_ptr)] = Token;
else
printf(" Stack full\n");
}
/*******************************************************************/
/* MODIFIES: None. */
/* REQUIRES: */
/* Stack -- Syntax stack. */
/* Sp -- Syntax stack pointer. */
/* RETURNS: */
/* Token at the top of the stack. */
/*******************************************************************/
int Get_top_token(int Stack[], int Sp)
{
return(Stack[Sp]);
}
/*******************************************************************/
/* MODIFIES: None. */
/* REQUIRES: */
/* Stack -- Syntax stack. */
/* Sp -- Syntax stack pointer. */
/* RETURNS: */
/* Token at second from the top of the Stack. */
/*******************************************************************/
int Get_next_to_top_token(int Stack[], int Sp)
{
return(Stack[Sp-1]);
}
/*******************************************************************/
/* MODIFIES: */
/* Stack -- Syntax stack. */
/* Sp_ptr -- Syntax stack pointer. */
/* REQUIRES: None. */
/* RETURNS: */
/* Token popped from the top of the Stack. */
/*******************************************************************/
int Pop_token(int Stack[], int *Sp_ptr)
{
if ((*Sp_ptr >= 0) && (*Sp_ptr < STACK_SIZE))
return(Stack[(*Sp_ptr)--]);
printf(" Stack index out of bounds\n");
return INVALID_TOKEN;
}
#if 0
/*******************************************************************/
/* MODIFIES: None. */
/* REQUIRES: */
/* Stack -- Syntax stack. */
/* Sp -- Syntax stack pointer. */
/* RETURNS: None. */
/* FUNCTION: */
/* Print the tokens stored in the stack. */
/*******************************************************************/
void Print_syn_stack(int Stack[], int Sp)
{
int i;
for (i=0;i<=Sp;i++)
printf("Stack[%d] = %d\n",i,Stack[i]);
}
#endif