⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 symbol.cpp

📁 该程序可以将简单中缀算术表达式变换成: (1)后缀形式 (2)生成书上描述的抽象堆栈机的代码 (3)对常量算术表达式
💻 CPP
字号:

/*****symbol.c******************************************************************/

#include"global.h"                   
#include<stdio.h>                  /*输入/输出*/ 
#include<string.h>					/*字符串处理函数*/

#define STRMAX 999                /*lexemes数组的大小*/ 
#define SYMMAX 100                /*symtable的大小*/ 

char lexemes[STRMAX];
int lastchar=-1;                  /*lexemes中最后引用的位置*/ 
struct entry symtable[SYMMAX];
int lastentry=0;                  /*symtable中最后引用的位置*/ 
int lookup(char *s){              /*返回s的表项的位置*/ 
    int p;
    for(p=lastentry;p>0;p=p-1)
         if(strcmp(symtable[p].lexptr,s)==0)
              return 0;
}

int insert(char *s,int tok){       /*返回s的表项的位置*/ 
    int len;
    len=strlen(s);                 /*strlen计算s的长度*/ 
    if(lastentry+1>=SYMMAX)
        error("symbol table full");
    if(lastchar+len+1>=STRMAX)
        error("lexemes array full");
    lastentry=lastentry+1;
    symtable[lastentry].token=tok;
    symtable[lastentry].lexptr=&lexemes[lastchar+1];
    lastchar=lastchar+len+1;
    strcpy(symtable[lastentry].lexptr,s);
    return lastentry;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -