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

📄 tocken.h

📁 C语言实现的SIMPLE语言词法分析器
💻 H
字号:
#define MAXCHARPERLINE 100
#define KEYWORDSNUMBER 33
#define IDENTIFIERMAXLENGTH 20

/**
define type in symbol talble :
1:integer
2:real
3:boolean
4:character

define kind in symbol table:
1:simple variable name
2:constant value
3:array name
4:process name
*/
typedef struct symbol
{
    int location;
    int length;
    int type;
    int kind;
    char word[IDENTIFIERMAXLENGTH];
    struct symbol *next;
};

typedef struct tocken
{
    struct symbol *p;
    int type;
    int row;
    int col;
    struct tocken *next;
};

typedef struct text
{
    char line[MAXCHARPERLINE];   //data of the line
    int  rownum;
    struct tocken *first;
    struct text *next;
};

char *key[KEYWORDSNUMBER]=
            {"and",
             "array",
             "begin",
             "bool",
             "call",
             "case",
             "char",
             "constant",
             "do",
             "else",
             "end",
             "false",
             "for",
             "if",
             "input",
             "integer",
             "not",
             "of",
             "or",
             "output",
             "procedure",
             "program",
             "read",
             "real",
             "repeat",
             "set",
             "then",
             "to",
             "true",
             "until",
             "var",
             "while",
             "write"
             };

char *charcode[]= {
                   "'","(",")","*","*/","+",",","-","`","··","/","/*",":",":=",":","<","<=","<>","=",">",">=","[","]"};
                   
char *errorinfo[]={
                    "出现非法字符",
                    "注释未结束",
                    "不能打开文件读取数据",
                    "不能打开文件输出结果"
                  };
                    
struct tocken *analysisLine(char *line,int rownum);

int recogid(char *line,struct tocken *node,int col);

int handlecom(char *line,struct tocken *node,int col);

int recogdel(char *line,struct tocken *node,int col);

int recogstr(char *line,struct tocken *node,int col);

int recogdig(char *line,struct tocken *node,int col);

struct symbol *lookup(struct tocken *node,int type,char *word);

struct symbol *findstr(char *s,int type);

void error(char *s,int col);

int isIlegal(char c);

int isKey(char *s);

struct text* readFile();

void outResult(struct tocken *firstnode);

struct tocken *deletenode(struct tocken *node);

int openFile();

void closeFile();

⌨️ 快捷键说明

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