Untitled
unknown
plain_text
8 months ago
3.3 kB
7
Indexable
#include <string>
#include <iostream>
#include <fstream>
#include <cctype>
#include <sstream>
#include <list>
#include <algorithm>
#include <bits/stdc++.h>
#include <map>
#include "lex.h"
using std ::cin;
using std ::cout;
using std ::endl;
using std::find;
using std ::ifstream;
using std ::istringstream;
using std::list;
using std::map;
using std ::string;
using std::stringstream;
map<string, Token> reservedWords = {
{"if", IF}, {"else", ELSE}, {"elsif", ELSIF}, {"put", PUT}, {"putline", PUTLN}, {"get", GET}, {"integer", INT}, {"float", FLOAT}, {"character", CHAR}, {"string", STRING}, {"boolean", BOOL}, {"procedure", PROCEDURE}, {"true", TRUE}, {"false", FALSE}, {"end", END}, {"is", IS}, {"begin", BEGIN}, {"then", THEN}, {"constant", CONST}};
LexItem id_or_kw(const string &lexeme, int linenum)
{
}
LexItem getNextToken(istream &in, int &linenum)
{
string lexeme;
char ch;
while (in.get(ch))
{
if (ch == '\n')
{
linenum++;
}
if (ch == ' ')
{
continue;
}
if (isalpha(ch))
{
lexeme += ch;
}
if (ch == ',')
{
return LexItem(COMMA, "Comma", linenum);
}
if (ch == ';')
{
return LexItem(SEMICOL, "Semi-colon", linenum);
}
if (ch == '(')
{
return LexItem(LPAREN, "Left Parenthesis", linenum);
}
if (ch == ')')
{
return LexItem(RPAREN, "Right Parenthesis", linenum);
}
if (ch == ':')
{
return LexItem(COLON, "Colon", linenum);
}
if (ch == '.')
{
return LexItem(DOT, "Dot", linenum);
}
}
}
ostream &operator<<(ostream &out, const LexItem &tok)
{
}
int main(int argc, char *argv[])
{
list<string> keywords{"begin", "end", "if", "else", "while", "for", "break", "continue", "case",
"switch", "class", "public", "private", "abstract", "final"};
map<string, int> specMap;
map<string, int> keyMap;
map<string, int> idtMap;
ifstream inputFile("infile4");
int xx = 1;
getNextToken(inputFile, xx);
// if (argc < 2)
// {
// cout << "NO SPECIFIED INPUT FILE NAME." << endl;
// return 0;
// }
// ifstream inputFile(argv[1]);
// if (!inputFile.is_open())
// {
// cout << "CANNOT OPEN THE FILE " << argv[1] << endl;
// return 0;
// }
// bool showKeywords = false;
// bool showspecialWords = false;
// bool showIdentifiers = false;
// for (int i = 2; i < argc; i++)
// {
// string flags = argv[i];
// if (flags == "-kw")
// {
// showKeywords = true;
// }
// else if (flags == "-sp")
// {
// showspecialWords = true;
// }
// else if (flags == "-id")
// {
// showIdentifiers = true;
// }
// else
// {
// cout << "UNRECOGNIZED FLAG " << flags << endl;
// return 0;
// }
// }
return 0;
}Editor is loading...
Leave a Comment