-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparser.h
More file actions
executable file
·49 lines (35 loc) · 1.35 KB
/
parser.h
File metadata and controls
executable file
·49 lines (35 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <fstream>
using namespace std;
const int MAX_DELIMS = 14;
const int MAX_KEYWORD = 256;
const char delims[MAX_DELIMS] = { '<', '>', ';', '\n', '*', '&', ':', '(', ')',',', ' ','\t','[',']' };
class Parser {
public:
Parser();
Parser(char* inFile) { parse(inFile); }
virtual ~Parser() {}
int parse(char* fileName);
protected:
enum Context { string_literal, char_literal, raw_string_literal, single_line_comment, multiline_comment, file_end, newline, keyword };
char* keyWords[MAX_KEYWORD];
char keyWord[MAX_KEYWORD];
int keyIndex;
int KEYWORDS;
int outputChar(char ch, ofstream& outFile);
bool isDelim(char ch);
void printHeader(char* fileName, ofstream& outFile);
void printFooter(ofstream& outFile);
Context handle_code(ifstream& inFile, ofstream& outFile);
void handle_literal(char delimiter, ifstream& inFile, ofstream& outFile);
void handle_raw_literal(ifstream& inFile, ofstream& outFile);
virtual void handle_single_comment(ifstream& inFile, ofstream& outFile);
int keyMatch(char ch, ofstream& outFile);
void flushKeyWord(ofstream& outFile);
virtual void handle_multiline_comment(ifstream& inFile, ofstream& outFile);
void _parse(ifstream& inFile, ofstream& outFile);
};