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();
}
return count_lines;
}
int listoffiles_toread(string file_content[])
{
int max_no_of_lines = 0;
string list_of_files[10];
int count_lines = file_read("C:\\comp\\list.txt", list_of_files);
for (int i = 0; i < count_lines; i++)
{
max_no_of_lines = file_read(list_of_files[i], file_content);
}
return max_no_of_lines;
}
/******* Testing Framework for lexer *******/
void simulate_lexer(string str_line[], int max_no_of_lines)
{
int t = -1;
for (int i = 0; i < max_no_of_lines; i++)
{
cout << (t= getToken(str_line, max_no_of_lines)) << endl;
}
}
void start_compiler()
{
// string file = "p5.c";
string str_line[1000];
int max_no_of_lines = listoffiles_toread(str_line);
simulate_lexer(str_line,max_no_of_lines);
}
int main(int argc, _TCHAR* argv[])
{
// cout << "hello world";
start_compiler();
system("pause");
return 0;
}
Comments
Post a Comment