-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lexeme.h
54 lines (39 loc) · 1.33 KB
/
Lexeme.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
/*
Carlos Villagomez & Andrew Zenoni
CPSC 326 - Organization of Programming Languages
Assignment 2
v 1.0.0
January 29, 2018
Defines methods for a Lexeme Object
*/
#ifndef LEXEME_H
#define LEXEME_H
// You shouldn't need to modify this file for HW2
#include <string>
#include <ostream>
#include <sstream>
#include "Token.h"
/* Represents a lexeme in the code */
struct Lexeme {
/* Explicitly allow default constructor (creating a Lexeme without providing
any information */
Lexeme() = default;
/* Allow constructing a Lexeme by passing in a token, text, line, and
column. Initializes the member variables appropriately */
Lexeme(Token initToken, std::string initText, int initLine, int initCol):
token(initToken), text(initText), line(initLine), col(initCol) {}
// What token?
Token token;
// What text corresponds in the source code?
std::string text;
// What line did the token start on?
int line = -1;
// What character did the token start on?
int col = -1;
};
/* Allows Lexemes to be output to cout or other output streams using the
<< syntax */
std::ostream& operator<<(std::ostream& out, const Lexeme& lex);
/* Given a lexeme, return a string representation of its contents */
std::string toString(const Lexeme &lex);
#endif /* LEXEME_H */