|

楼主 |
发表于 2015-1-22 08:15:29
|
显示全部楼层
本帖最后由 584768970 于 2015-1-22 08:23 编辑
- char *p, *lp, // current position in source code
- *data; // data/bss pointer
- int *e, *le, // current position in emitted code
- *id, // currently parsed identifier
- *sym, // symbol table (simple list of identifiers)
- tk, // current token
- ival, // current token value
- ty, // current expression type
- loc, // local variable offset
- line, // current line number
- src, // print source and assembly flag
- debug; // print executed instructions
- // tokens and classes (operators last and in precedence order)
- enum {
- Num = 128, Fun, Sys, Glo, Loc, Id,
- Char, Else, Enum, If, Int, Return, Sizeof, While,
- Assign, Cond, Lor, Lan, Or, Xor, And, Eq, Ne, Lt, Gt, Le, Ge, Shl, Shr, Add, Sub, Mul, Div, Mod, Inc, Dec, Brak
- };
- // opcodes
- enum { LEA ,IMM ,JMP ,JSR ,BZ ,BNZ ,ENT ,ADJ ,LEV ,LI ,LC ,SI ,SC ,PSH ,
- OR ,XOR ,AND ,EQ ,NE ,LT ,GT ,LE ,GE ,SHL ,SHR ,ADD ,SUB ,MUL ,DIV ,MOD ,
- OPEN,READ,CLOS,PRTF,MALC,MSET,MCMP,EXIT };
- // types
- enum { CHAR, INT, PTR };
- // identifier offsets (since we can't create an ident struct)
- enum { Tk, Hash, Name, Class, Type, Val, HClass, HType, HVal, Idsz };
复制代码
这里是全局变量和枚举
- if ((tk >= 'a' && tk <= 'z') || (tk >= 'A' && tk <= 'Z') || tk == '_') {
- pp = p - 1;
- while ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p >= '0' && *p <= '9') || *p == '_')
- tk = tk * 147 + *p++;
- tk = (tk << 6) + (p - pp);
- id = sym;
- while (id[Tk]) {
- if (tk == id[Hash] && !memcmp((char *)id[Name], pp, p - pp)) { tk = id[Tk]; return; }
- id = id + Idsz;
- }
- id[Name] = (int)pp;
- id[Hash] = tk;
- tk = id[Tk] = Id;
- return;
- }
复制代码
这是68行到82行 该函数是多个if-else-if-else-if 组成的 这里是一中if情况 |
|