blob: 78096f4cee2339ebc6f477b8d43f6e3cb468230f (
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
|
#include <stdio.h>
#include "lexer.h"
char tab[] = {
[TOKEN_PLUS] = '+', [TOKEN_MINUS] = '-', [TOKEN_MUL] = '*',
[TOKEN_DIV] = '/', [TOKEN_LEFT_PAR] = '(', [TOKEN_RIGHT_PAR] = ')'
};
int main(int argc, char *argv[])
{
if (argc != 2)
return 1;
struct lexer *lexer = lexer_new(argv[1]);
struct token token = lexer_pop(lexer);
while (token.type != TOKEN_EOF && token.type != TOKEN_ERROR)
{
if (token.type == TOKEN_NUMBER)
printf("%zu\n", token.value);
else
printf("%c\n", tab[token.type]);
token = lexer_pop(lexer);
}
if (token.type == TOKEN_EOF)
printf("EOF\n");
lexer_free(lexer);
return 0;
}
|