~wattazoum/albert/albert-mod

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
/*******************************************************************/
/***  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"	


/*******************************************************************/
/* MODIFIES:                                                       */
/*     Stack -- Syntax stack.                                      */
/*     Sp_ptr -- Syntax stack pointer.                             */
/* REQUIRES:                                                       */
/*     token -- to be pushed onto the stack.                       */
/* RETURNS: None.                                                  */
/*******************************************************************/ 
void Push_token(Stack,Sp_ptr,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(Stack,Sp)
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(Stack,Sp)
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(Stack,Sp_ptr)
int Stack[];
int *Sp_ptr;
{
    if ((*Sp_ptr >= 0) && (*Sp_ptr < STACK_SIZE))
        return(Stack[(*Sp_ptr)--]);
    else
        printf(" Stack index out of bounds\n");
}


/*******************************************************************/
/* MODIFIES: None.                                                 */
/* REQUIRES:                                                       */
/*     Stack -- Syntax stack.                                      */
/*     Sp    -- Syntax stack pointer.                              */
/* RETURNS: None.                                                  */
/* FUNCTION:                                                       */
/*     Print the tokens stored in the stack.                       */
/*******************************************************************/ 
void Print_syn_stack(Stack,Sp)
int Stack[];
int Sp;
{
    int i;
    for (i=0;i<=Sp;i++)
        printf("Stack[%d] = %d\n",i,Stack[i]);
}