-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSymtab.h
More file actions
101 lines (80 loc) · 2.06 KB
/
Symtab.h
File metadata and controls
101 lines (80 loc) · 2.06 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* @Copyright: minic
* @Author: linmaosen
* @Description: 定义符号表的结构体以及查询、插入符号表的函数
* @LastEditors: linmaosen
* @LastEditTime: 2020-06-01
* @FilePath: /minic/Symtab.h
*/
#pragma once
#include <stdio.h>
#include<string>
// #include"main.h"
using namespace std;
#define SIZE 211
#define MAX_SCOPE 8
/**
* @description: 定义行的结构体
* @param {}
* @return:
*/
typedef struct LineListRec
{
int lineno; // 行号
struct LineListRec *next; // next指针
} * LineList;
/**
* @description: 定义bucket结构体
* @param {}
* @return:
*/
typedef struct BucketListRec
{
string name; // 变量或者函数名字
LineList lines; // 行结构体
int memloc; // 内存位置
int scope; // 归属范围
int isArray; // 是否是数组
int isParam; // 是否是参数
int fun_start;
struct BucketListRec *next;
} * BucketList;
/**
* @description: 定义scope的结构体
* @param {}
* @return:
*/
static struct ScopeList
{
BucketList hashTable[SIZE]; // 定义多个哈希表
} Scope[MAX_SCOPE];
/**
* @description: 插入符号表,如果哈希值对应的位置不存在,则在头部插入,如果哈希值对应的位置存在,则在尾部连上
* @param {string, int, int, int, int}
* @return: void
*/
void st_insert(string name, int lineno, int loc, int scope, int isparam, int arr);
/**
* @description: 查询符号在符号表中的位置
* @param {string, int}
* @return: int
*/
int st_lookup(string name, int scope);
/**
* @description: 查询函数名在符号表中的位置
* @param {string, int}
* @return: BucketList
*/
BucketList fun_lookup(string name, int sp1);
/**
* @description: 查询变量在符号表中的位置
* @param {string, int}
* @return: BucketList
*/
BucketList var_lookup(string name, int sp1);
/**
* @description: 在指定文件中输出符号表
* @param {FILE}
* @return: void
*/
void printSymTab(FILE *listing);