-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparser.h
More file actions
78 lines (63 loc) · 1.68 KB
/
parser.h
File metadata and controls
78 lines (63 loc) · 1.68 KB
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
#ifndef _parser
#define _parser
#include "parserDef.h"
#include "lexerDef.h"
typedef enum _tag
{
TERMINAL, NON_TERMINAL
} nodeTag ;
typedef union _TNT {
token* term ;
tokenID nonTerm ;
} TNT ;
struct _astNode ;
typedef struct _astNode astNode;
typedef struct treeNode
{
nodeTag tag ;
TNT tnt ;
astNode *syn, *inh ;
int gcode ; // which rule was used
int syntax_error ;
struct treeNode *child ;
struct treeNode *next ;
struct treeNode *parent ;
} treeNode ;
typedef struct _stacknode{
int key;
struct _stacknode* next;
} stacknode;
#define SIZE 200
#define TNTLENGTH 40
#define isTerminal(x) x>=TK_EPS && x<=TK_RNUM
#define isNonTerminal(x) x>=program && x<=idL
#define endl printf("\n")
#define allRules rule
extern Rule rule[SIZE];
extern node* firsts[SIZE];
extern node* follows[SIZE];
extern location heads[SIZE];
extern int parsetable[150][150];
extern int rule_count;
extern char utility_array[150][40] ;
static int counter = 0 ;
char* nodeSymbol (treeNode* node) ;
char* isLeafNode (treeNode* node) ;
char* tokenIDToSting (tokenID id) ;
void init_parser() ;
treeNode* create_root () ;
treeNode* create_node (nodeTag tag, TNT tnt) ;
void add_child (treeNode *parent, treeNode *node) ;
void print_node (treeNode *node) ;
void print_siblings (treeNode *node) ;
stacknode * initStack() ;
stacknode * push(stacknode * stc , tokenID token) ;
stacknode * pop(stacknode * stc) ;
stacknode * pushRule(stacknode * stc,Rule *allRules, int rule_index) ;
void printSL(stacknode * stc) ;
void test_tree () ;
void addRulesParseTree (treeNode *parent, Rule *allRules, int rule_index) ;
treeNode * nextTreeNode(treeNode* current_node) ;
treeNode* parse (FILE *fp) ;
void deletePT (treeNode *node) ;
#endif