lex.h

#include <string>
#include <signal.h>
using namespace std;

#define CRASH_NOW()  raise(SIGSEGV); 
#define EOT -9999

#define CHAR_AT(pos,line_no) str_line[line_no].at(pos)
#define SPACE_CHECK(pos) CHAR_AT(pos, line_no) == ' ' ||  \
                         CHAR_AT(pos, line_no) == '\n' || \
                         CHAR_AT(pos, line_no) == '\v' || \
                         CHAR_AT(pos, line_no) == '\t'

#define NULL_CHECK(pos)  str_line[line_no].length() <= pos

#define NL_CHECK(pos)     if (NULL_CHECK(pos))    \
                          {                  \
                             pos = 0;         \
                             line_no++;       \
                          }


#define ALPHA_NUM_CHECK(pos) ((CHAR_AT(pos, line_no) >= 'a' && CHAR_AT(pos, line_no) <= 'z') || (CHAR_AT(pos, line_no) >= 'A' && CHAR_AT(pos, line_no) <= 'Z') || (CHAR_AT(pos, line_no) >= '0' && CHAR_AT(pos, line_no) <= '9'))

/* Macro Values for Tokens */
#define ELIPPSIS 0x1000
#define ADD_ASSIGN 0x1001
#define INC_OP 0x1002
#define SUB_ASSIGN 0x1003
#define DEC_OP 0x1004
#define DIV_ASSIGN 0x1005
#define MUL_ASSIGN 0x1006
#define MOD_ASSIGN 0x1007
#define AND_ASSIGN 0x1008
#define XOR_ASSIGN 0x1009
#define OR_ASSIGN 0x1010
#define NOT_ASSIGN 0x1011
#define RIGHT_OP 0x1012
#define LEFT_OP 0x1013

#define ID 0x1014
#define STROBJ 0x1015
#define INT_CONST 0x1016
#define F_CONST 0x1017

/* Keyword token */
#define AUTO 0
#define BREAK 1
#define CASE 2
#define CHAR 3
#define CONST 4
#define CONTINUE 5
#define DEFAULT 6
#define DO 7
#define DOUBLE 8
#define ELSE 9
#define ENUM 10
#define EXTERN 11
#define FLOAT 12
#define FOR 13
#define GOTO 14
#define IF 15
#define INT 16
#define LONG 17
#define REGISTER 18
#define RETURN 19
#define SHORT 20
#define SIGNED 21
#define SIZEOF 22
#define STATIC 23
#define STRUCT 24
#define SWITCH 25
#define TYPEDEF 26
#define UNION 27
#define UNSIGNED 28
#define VOID 29
#define VOLATILE 30
#define WHILE 31

int keyword_check(string str, bool &is_keyword);
int getToken(string *str_line, int max);

#define NO_PREPROCESSOR 1

#ifdef NO_PREPROCESSOR
bool is_first(string str_line, char c);


#define is_prep()   if(is_first(str_line[line_no], '#')) \
                    {                                    \
                           pos= 0;                       \
                           line_no++;                    \
                    }                                    \

#endif 

Comments

Popular posts from this blog

lex.cpp