?? token.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 + -