📄 symbol.c
字号:
#include <math.h>
#include <malloc.h>
#include <string.h>
#include "stkmach.h"
#include "symbol.h"
#include "cc_tab.h"
struct bltin arith_fncts[]
= {
"sin", sin,
"cos", cos,
"atan", atan,
"ln", log,
"exp", exp,
"sqrt", sqrt,
0,0
};
struct cnst consts[]
= {
"PI", 3.1415926535897932846,
"E", 2.718281845904523536,
"GAMMA", 0.57721566490153286060,
"DEG", 57.29577951308232087680,
"PHI", 1.61803398874989484820,
0,0
};
struct kword kwords[]
= {
"proc", PROC,
"func", FUNC,
"return", RETURN,
"if", IF,
"else", ELSE,
"while", WHILE,
"print", PRINT,
"read", READ,
0,0,
};
static symrec *sym_table = (symrec *)0;
init_table()
{
int i;
symrec *ptr;
for (i = 0; arith_fncts[i].fname != 0; i++)
{
ptr = putsym(arith_fncts[i].fname, BLTIN, 0);
ptr->value.fnctptr = arith_fncts[i].bltin;
}
for (i = 0; consts[i].name != 0; i++)
{
ptr = putsym(consts[i].name, CONST, 0);
ptr->value.val = consts[i].val;
}
for (i = 0; kwords[i].name; i++)
{
ptr = putsym(kwords[i].name, kwords[i].kval, 0);
}
}
symrec* putsym(char *sym_name, int sym_type, double val)
//insert the new symbol at the begining of the sym_table
{
symrec *ptr;
ptr = (symrec *) malloc(sizeof(symrec));
ptr->name = (char *)malloc(strlen(sym_name)+1);
strcpy(ptr->name,sym_name);
ptr->type = sym_type;
ptr->value.val = val;
ptr->next = (symrec *)sym_table;
sym_table = ptr;
return ptr;
}
symrec* getsym(char *sym_name)
{
symrec *ptr;
for (ptr = sym_table; ptr != 0; ptr = (symrec *)ptr->next)
if (strcmp(ptr->name, sym_name) == 0)
return ptr;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -