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

📄 token.c

📁 语法分析程序,使用是递归子程序法.自己写的程序,学习
💻 C
字号:
/*
 * Author: zhangdi
 * Date: 2008-11-10
 * Description: token table, it has it's method add a token to the store
 */
#include <string.h>
#include "global.h"
#include "error.h"

char tokenstr[STRMAX];
int lasttokenchar = -1;
struct node tokens[ARRAYMAX];
int lastnode = 0;

/* add a token to token table  */
int addtoken(char tok[], int position)
{
    int length;
    length = strlen(tok);
    if (lastnode + 1 >= ARRAYMAX)
        error("symbol table full");
    if (lasttokenchar + length + 1 >= STRMAX)
        error("lexemes array for symbol full");
    lastnode += 1;
    tokens[lastnode].position = position;
    tokens[lastnode].tok = &tokenstr[lasttokenchar + 1];
    lasttokenchar = lasttokenchar + length + 1;
    strcpy(tokens[lastnode].tok, tok);
    return lastnode;
}

/* output token table to a txt file */
int tokensdisplay()
{
    int i;
    FILE *fwp;

    if ((fwp = fopen("tokes.txt", "wt")) == NULL)
    {
        fprintf(stderr, "can't create tokes.txt\n");
        exit(-1);
    }

    // output all the nodes of token table to txt file
    for (i=1; i<=lastnode; i++)
    {
        fprintf(fwp, "%s\t%d\n", tokens[i].tok, tokens[i].position);
    }
    fclose(fwp);
    return 0;
}

⌨️ 快捷键说明

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