aboutsummaryrefslogtreecommitdiff
path: root/include/cps/Lexer.h
blob: 4226cc3fcdb5a64a5ec0b668db3a84c1e35e2e80 (plain)
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

#pragma once
#include <string>
#include <cstdint>

namespace cps {

enum Token {
    tok_eof = -1,

    tok_declare = -2,
    tok_integer_kw = -3,
    tok_input = -4,
    tok_output = -5,
    
    tok_if = -6,
    tok_then = -7,
    tok_else = -8,
    tok_endif = -9,
    
    tok_while = -10,
    tok_do = -11,
    tok_endwhile = -12,
    
    tok_repeat = -13,
    tok_until = -14,
    
    tok_for = -15,
    tok_to = -16,
    tok_step = -17,
    tok_next = -18,

    tok_array = -19,
    tok_of = -20,

    tok_identifier = -100,
    tok_number = -101,
    
    tok_assign = -200, // <-
    tok_eq = -201, // =
    tok_ne = -202, // <>
    tok_le = -203, // <=
    tok_ge = -204, // >=
    
    tok_colon = -300, // :

    tok_function = -400, 
    tok_endfunction = -401, 
    tok_return = -402, 
    tok_returns = -403,
    tok_procedure = -404, 
    tok_endprocedure = -405, 
    tok_call = -406,
    tok_byref = -407,
    tok_byval = -408
};

class Lexer {
    int CurrentLine = 1;
public:
    std::string IdentifierStr;
    int64_t NumVal;

    int gettok();
    int getLine() const { return CurrentLine; }
};

}