-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer.cpp
More file actions
55 lines (49 loc) · 1.53 KB
/
lexer.cpp
File metadata and controls
55 lines (49 loc) · 1.53 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
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "lexer.hpp"
#include "error.hpp"
#include "driver.hpp"
#include <iostream>
#include <cctype>
using namespace Error;
Lexer::Token_value Lexer::curr_tok;
double Lexer::number_value;
std::string Lexer::string_value;
Lexer::Token_value Lexer::get_token() {
using Driver::input;
using Lexer::curr_tok;
extern std::istream* input;
char ch;
do { // skip whitespace except '\n'
if(!input->get(ch)) return Lexer::curr_tok = END; // istream& get ( char& c ); Extracts a character from the stream and stores it in c
} while (ch != '\n' && isspace(ch)); // ебать мой хуй, что это блять тут случилось с кодировкой?
switch (ch) {
case 0:
return curr_tok = END;
case ';' :
case '\n':
return curr_tok = PRINT;
case '*' :
case '/' :
case '+' :
case '-' :
case '(' :
case ')' :
case '=' :
return curr_tok = Token_value(ch);
case '0' : case '1' : case '2' : case '3' : case '4' :
case '5' : case '6' : case '7' : case '8' : case '9' : case '.' :
input->putback(ch);
input->operator >>(number_value);
return curr_tok=NUMBER;
default:
if (isalpha(ch)) {
string_value = ch;
while (input->get(ch) && isalnum(ch)) {
string_value.push_back(ch);
}
input->putback(ch);
return curr_tok=NAME;
}
throw Syntax_error("bad token");
return curr_tok=PRINT;
}
}