-
Notifications
You must be signed in to change notification settings - Fork 0
/
LexicalAnalyzer.h
62 lines (54 loc) · 2.4 KB
/
LexicalAnalyzer.h
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*******************************************************************************
* Assignment: Project 1 - Lexical Analyzer for Scheme to C++ Translator *
* Author: Dr. Watts *
* Date: Fall 2017 *
* File: LexicalAnalyzer.h *
* *
* Description: This file contains the *
*******************************************************************************/
#ifndef LEX_H
#define LEX_H
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
/*******************************************************************************
* Type: token_type *
* *
* Description: The token_type enumerated type is used to identify the tokens *
* associated with the lexemes scanned from an input file. *
*******************************************************************************/
enum token_type {NONE = -1, LAMBDA, IDENT_T, NUMLIT_T, STRLIT_T, CONS_T, IF_T,
COND_T, DISPLAY_T, NEWLINE_T, LISTOP_T, AND_T, OR_T, NOT_T,
DEFINE_T, NUMBERP_T, SYMBOLP_T, LISTP_T, ZEROP_T, NULLP_T,
STRINGP_T, MODULO_T, PLUS_T, MINUS_T, DIV_T, MULT_T, EQUALTO_T,
GT_T, LT_T, GTE_T, LTE_T, LPAREN_T, RPAREN_T, QUOTE_T,
ERROR_T, EOF_T, MAX_TOKENS};
/*******************************************************************************
* Class: Lexical_Analyzer *
* *
* Description: This class is designed to *
*******************************************************************************/
class LexicalAnalyzer
{
public:
LexicalAnalyzer (char * filename);
~LexicalAnalyzer ();
token_type GetToken ();
string GetTokenName (token_type t) const;
string GetLexeme () const;
void ReportError (const string & msg);
ofstream debug;
private:
ifstream input;
ofstream listing;
ofstream p1file;
string line;
int linenum;
int pos;
string lexeme;
int error_type;
int errors;
map <string, token_type> symbols;
};
#endif