-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.hpp
69 lines (64 loc) · 3.8 KB
/
lexer.hpp
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
63
64
65
66
67
68
69
#ifndef PJPPROJECT_LEXER_HPP
#define PJPPROJECT_LEXER_HPP
#include <iostream>
#include <vector>
#include "token.hpp"
#include "misc.hpp"
//=================================================================================================
class CIstream {
public:
CIstream ( std::istream & sin );
uint lineNumber ( void ) const;
uint offset ( void ) const;
bool eof ( void );
int get ( void ); // this is often called advance
// but in c++ streams does
// the job, and this way we wont
// have to rewrite everything
int peek ( void );
private:
std::istream & m_Sin;
uint m_LineNumber = 1;
uint m_Offset = 1;
};
//=================================================================================================
/* This lexer does not support arrays and real numbers.
It's pretty anyway.
*/
class CLexer {
public:
CLexer ( std::istream & sin );
/* These are the two main ways to use the lexer - either ask for a token one at a time
or ask for the vector of all the tokens in the input.
*/
CToken NextToken ( void );
static std::vector<CToken> Analyse ( std::istream & sin );
private:
CToken nextToken ( void );
CToken scanPunctuation ( void );
CToken scanOperator ( void );
CToken scanNumber ( void );
CToken scanString ( void );
CToken scanName ( void );
CToken scanRelationOp ( void );
CToken scanArithmeticOp ( void );
CToken scanOperatorKeyword ( std::string & name );
CToken scanContFlowKeyword ( std::string & name );
CToken scanBuiltinKeyword ( std::string & name );
CToken scanBasicKeyword ( std::string & name );
int getDecaNumber ( void );
int getOctaNumber ( void );
int getHexaNumber ( void );
std::string getName ( void );
void noWhiteSpaces ( void );
void skipCommentsBlanks ( void );
bool match ( char compare );
CToken addToken ( CToken::EType type );
CToken addToken ( CToken::EType type,
int num );
CToken addToken ( CToken::EType type,
std::string str );
CIstream m_Sin;
};
//=================================================================================================
#endif //PJPPROJECT_LEXER_HPP