clex.h
资源名称:parse.tar.Z [点击查看]
上传用户:hbdengju
上传日期:2007-01-06
资源大小:11k
文件大小:2k
源码类别:
编译器/解释器
开发平台:
C/C++
- #ifndef INCLUDED_CLEX
- #define INCLUDED_CLEX 1
- #ifndef INCLUDED_STDIO
- #include <stdio.h>
- #endif
- enum Boolean { FALSE, TRUE };
- #include "clex_sym.h"
- class Clex
- {
- friend class Cparse;
- enum Clex_mode
- { CL_NONE=0, CL_COMMENT=1, CL_QUOTE=2, CL_POUND=4, CL_BRACK=8 };
- protected:
- short look; // a one-char lookahead
- FILE* fp;
- Boolean block_brack; // if TRUE, treat contents of "[]" as a string
- long line_num; // line number in original source file
- char filename[256]; // name of original source file
- short bufsiz; // number of chars currently in buf
- char buf[256];
- void eat_one() { look = short(getc(fp)); }
- void put_in_buf(char c) { if (bufsiz < sizeof(buf)-1) buf[bufsiz++] = c; }
- void buf_one() { put_in_buf(look); eat_one(); }
- Clex_sym terminate(Clex_sym s) { buf[bufsiz] = ' '; return s; }
- Clex_sym eat_return(Clex_sym);
- Clex_sym num(char);
- Clex_sym ident(char);
- Clex_sym lbrack(Clex_mode);
- Clex_sym quote(char, Clex_sym, Clex_mode);
- void block_comment(Clex_mode);
- void line_comment();
- void eoln(Clex_mode);
- virtual Boolean pound(Clex_mode, char*, short len);
- public:
- Clex_sym next();
- const char* str() { return buf; }
- short strlen() { return bufsiz; }
- long line_no() { return line_num; }
- const char* fname() { return filename; }
- const char* debug(Clex_sym);
- Clex(FILE*, Boolean block_brack);
- };
- #endif