Posts

C_Tools.cpp

// C_Tools.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include "lex.h" using namespace std; #define MAX_NO_OF_SCANNERS 255 class Lexer { int line_no; int token; int keyword; } L[MAX_NO_OF_SCANNERS]; /******** File reading API for testing framework *****/ int file_read(string input_file, string *str_line) { string line; unsigned int count_lines = 0; std::ifstream file(input_file.c_str()); // string str_line[100000]; if (file.is_open()) { while (getline(file, line)) { //  str_line[count_lines] = new char[line.length()]; //   memcpy(str_line[count_lines], line.c_str(), line.length()); str_line[count_lines] = line; #ifdef DEBUG       cout << count_lines << str_line[count_lines] << endl; #endif             count_lines++; } file.close(); } ...

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))    \                           {                  \                     ...

lex.cpp

#include "stdafx.h" #include "lex.h" #include <string> #include <iostream> using namespace std; bool is_first(string str_line, char c) {     int t_pos = 0;     while (str_line.at(t_pos) == ' ' || str_line.at(t_pos) == '\v' || str_line.at(t_pos) == '\t')         t_pos++;     if (str_line.at(t_pos) == c)         return true;     else         return false; } int keyword_check(string str, bool &is_keyword) {     string keyword[32] =      {   "auto",         "break",         "case",         "char",         "const",         "continue",         "default",         "do",         "double",         "else",         "enum",         "ex...