-
Notifications
You must be signed in to change notification settings - Fork 0
/
UGL.H
108 lines (93 loc) · 1.87 KB
/
UGL.H
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 <stdlib.h>
#include <stdio.h>
#define MAX 100
#define TOK_OP_ADD_EQ 300
typedef enum
{
TOK_OP, TOK_NUM, TOK_NAME, TOK_KEYW, TOK_SYMBOL
} TOKID;
typedef enum
{
KW_IF, KW_ELSE, KW_WHILE, KW_PRINT
} KEYWORDS;
typedef enum
{
OP_UNAR = '@',
OP_PLUS = '+',
OP_MINUS = '-',
OP_MULT = '*',
OP_DIV = '/',
OP_POW = '^',
OP_MOD = '%',
OP_LT = '<',
OP_GT = '>',
OP_EQ = '=' + TOK_OP_ADD_EQ,
OP_NE = '!' + TOK_OP_ADD_EQ,
OP_GE = '>' + TOK_OP_ADD_EQ,
OP_LE = '<' + TOK_OP_ADD_EQ,
} OPERS;
typedef struct
{
TOKID Id;
OPERS Op;
double Num;
char Name[MAX];
KEYWORDS KeyW;
} TOK;
typedef struct tagLIST LIST;
struct tagLIST
{
TOK Data;
LIST *Next;
};
typedef struct
{
LIST *Head, *Tail;
} QUEUE;
typedef struct
{
LIST *Top;
} STACK;
typedef enum
{
CMD_EXPR, CMD_IF, CMD_WHILE, CMD_PRINT
} CMDID;
typedef struct tagCMD CMD;
struct tagCMD
{
CMDID Id;
LIST *Expr;
CMD *C1, *C2, *Next;
};
CMD *Proga;
extern STACK StackEval;
extern QUEUE QRes;
extern QUEUE TokList;
extern TOK TokCurrent;
void DisplayList( LIST *L );
void ClearList( LIST **L );
void Put( QUEUE *Q, TOK NewData );
int Get( QUEUE *Q, TOK *OldData );
void Push( STACK *S, TOK NewData );
int Pop( STACK *S, TOK *OldData );
void DisplayStack( STACK *S );
void DisplayQueue( QUEUE *Q );
void ClearStack( STACK *S );
void ClearQueue( QUEUE *Q );
void PrintTok( TOK T );
void Scanner( QUEUE *Q, char *S );
void Error( char *Str, ... );
double Eval( LIST *Expr );
void DropOpers( OPERS Op );
extern QUEUE Queue1;
extern STACK Stack2;
int GetPrior( OPERS Op );
void ParseExpr( LIST **Expr );
int CheckAssoc( OPERS Op1, OPERS Op2);
void SetValue( char *Name, double Value );
double GetValue( char *Name );
void DisplayVarTable( void );
void UpdateKeyword( TOK *T );
void DoCmd( CMD *C );
void ParseCmd( CMD **C );
void ParseProgram( void );