Lab 3
Lab 3
Computing
Compiler Construction
Class: BSCS
Source Code:
#include <iostream>
#include <fstream>
#include <windows.h>
#include <string>
#include <sstream>
#include <unordered_map>
int arithmeticLength = 5;
int rlationalOperatorLength = 2;
int punctuatorLength = 11;
size_t string_Hashing(string s)
{
hash<string> hasher;
return hasher(s);
}
int i = 0;
while (i != str.length())
{
if (alphabets.find(str[i]) == -1 && digit.find(str[i]) == -1)
{
return -1;
}
else if (str.length() == 0 || digit.find(str[0]) != -1)
{
return -1;
}
else
{
if (i == str.length() - 1)
{
return 1;
}
}
++i;
}
}
while (i != str.length())
{
if (counter == 1 && str[i] == '.')
{
return -1;
}
if (str.length() == 0)
{
return -1;
}
if (str[i] == '.')
{
counter++;
}
if (i == str.length() - 1)
{
return 1;
}
++i;
}
}
stringTerminator[0] = dict[i];
if (str == stringTerminator)
{
return 1;
}
}
return 0;
}
tokenChecker(word);
tokenChecker(stringTerminator);
word = "";
}
else
{
word = word + x;
}
i++;
}
}
if (argc < 2)
{
cerr << "Error: File name argument not given :`{" << endl;
exit(1);
}
// SetConsoleTextAttribute(Colour, FOREGROUND_RED);
// cout << "Content of file given as input: " << endl;
// SetConsoleTextAttribute(Colour, x);
// printFunc(file_Content);
// SetConsoleTextAttribute(Colour, FOREGROUND_BLUE);
// cout << "Content of file without comments: " << endl;
// SetConsoleTextAttribute(Colour, x);
// printFunc(plain_Text);
SetConsoleTextAttribute(Colour, FOREGROUND_GREEN);
cout << "\nLexical Analyzer Output: " << endl;
SetConsoleTextAttribute(Colour, x);
cout << "\tToken Name \t\t|\t Token value\t|\t Hash Value\n\n";
lexicalAnalyzer(plain_Text);
return 0;
}