-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken.c
32 lines (27 loc) · 857 Bytes
/
token.c
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
#include <stdio.h>
#include "token.h"
void
print_token(const token_t* token) {
print_token_kind(token->kind);
}
void
print_token_kind(token_kind kind) {
switch (kind) {
case LEFT_PAREN: puts("'('"); break;
case RIGHT_PAREN: puts("')'"); break;
case LEFT_BRACE: puts("'{'"); break;
case RIGHT_BRACE: puts("'}'"); break;
case MINUS: puts("'-'"); break;
case PLUS: puts("'+'"); break;
case STAR: puts("'*'"); break;
case SLASH: puts("'/'"); break;
case SEMICOLON: puts("';'"); break;
case IDENTIFIER: puts("identifier"); break;
case STRING: puts("string"); break;
case NUMBER: puts("number"); break;
case IF: puts("if"); break;
case END_OF_FILE: puts("<eof>"); break;
case UNKNOWN: puts("<unknown>"); break;
case UNTERMINATED_STRING: puts("<unterminated string>"); break;
}
}