scanner.h
上传用户:kalinte
上传日期:2013-04-07
资源大小:127k
文件大小:1k
- /****************************************************/
- /* File: scanner.h */
- /* The scanner implementation for the C- compiler */
- /* Xiang Cui (sean) */
- /* 230030782 */
- /****************************************************/
- #include <iostream>
- #include <iomanip.h>
- #include <string>
- #include <map>
- #include <fstream>
- #include "stdlib.h"
- #include "stdio.h"
- #include "string.h"
- #include "ctype.h"
- typedef enum
- /* book-keeping tokens */
- {ERROR,ENDFILE,
- /* keywords */
- ELSE,IF,INT,RETURN,VOID,WHILE,
- /* multicharacter tokens */
- ID,NUM,
- /* special symbols */
- PLUS,MINUS,TIMES,DIV,LT,LTEQ,GT,GTEQ,EQ,NEQ,ASSIGN,SEMI,
- COMMA,LPAREN,RPAREN,LSQR,RSQR,LCRLY,RCRLY,LCMNT,RCMNT
- } TokenType;
- /* states in scanner DFA */
- typedef enum
- { START,INNUM,INID,DONE,INLT,INGT,INEQ,INNEQ,INSLASH,INLCMNT,INRCMNT,ERR}
- StateType;
- class Myscanner
- {
- public:
- Myscanner(const char *);
- TokenType scan(); /*scan procedure*/
- void printToken(TokenType token, string tokenString);/*print out tokens*/
- TokenType reservedLookup (string str);/*look up the Keywords table*/
- string tokens;
- int lineno;
- ifstream sf;//source file
- private:
- bool save;
- char c;
- StateType state;
- TokenType currentToken;
- };