blob: 400058b3dce24a01dc22c114308dac4d23f02ebe (
plain) (
blame)
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
|
#include <iomanip>
#include <iostream>
#include <cassert>
#include "token.hpp"
#include "tokenizer.hpp"
using namespace SpasmImpl::ASM::Lexer;
#define TOKENS \
TOK(push) \
TOK(pop) \
TOK(dup) \
TOK(print) \
TOK(read) \
TOK(plus) \
TOK(minus) \
TOK(multiply) \
TOK(divide) \
TOK(modulus) \
TOK(gotrue) \
TOK(gofalse) \
TOK(go) \
TOK(call) \
TOK(ret) \
TOK(load) \
TOK(store) \
TOK(label) \
TOK(ident) \
TOK(integer) \
TOK(xinteger) \
TOK(endinput)
const char* token_name[24] = {"halt",
#define TOK(x) #x,
TOKENS
#undef TOK
"notused!!!"};
int main()
{
Tokenizer td(std::cin);
Token token;
token = td.next_token();
while (token.type() != Token::EndInput)
{
token = td.next_token();
Token::Token_type ttype = token.type();
std::cout.width(8);
std::cout << token.lineno();
std::cout << ": " << token_name[ttype];
if (ttype == Token::Integer || ttype == Token::XInteger)
std::cout << '|' << token.value_int() << '|';
else if (ttype == Token::Ident)
std::cout << '|' << token.value_str() << '|';
std::cout << std::endl;
}
return 0;
}
|