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
|
#include <stdio.h>
#include <stdlib.h>
#include "lr-parser.c"
#include "bin/generated.c"
#include "parts/toklist.h"
enum symbol {
PLUS = 0,
MINUS,
LPAREN,
RPAREN,
N0, N1,
END_INPUT,
EP, E, T, N,
SYMBOLS_END,
};
static inline symbol char_to_token(char c)
{
switch(c) {
case '+': return PLUS;
case '-': return MINUS;
case '(': return LPAREN;
case ')': return RPAREN;
case '0': return N0;
case '1': return N1;
case 0 : return END_INPUT;
default: fprintf(stderr, "ERROR: Unknown character '%c'\n", c); exit(1);
}
}
static char *input;
symbol toklist_eat() { return char_to_token(*(input++)); } // unsafe
symbol toklist_peek() { return char_to_token(*input); } // unsafe
int main(int argc, char **argv)
{
if(argc != 2) {
fprintf(stderr, "ERROR: Not enough arguments\n");
return 1;
}
input = argv[1];
return lr_parser();
}
|