aboutsummaryrefslogtreecommitdiff
path: root/lr-parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'lr-parser.c')
-rw-r--r--lr-parser.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/lr-parser.c b/lr-parser.c
index 41cc45b..2358164 100644
--- a/lr-parser.c
+++ b/lr-parser.c
@@ -19,10 +19,10 @@ int lr_parser()
#define pop() (--stack_head)
#define eat() toklist_eat()
#define peek() ({ symbol s = toklist_peek(); if(!symbol_is_valid(s)) return 1; s; })
-
+
while(1) {
struct action a = table[(size_t)*stack_head][peek()];
-
+
switch(a.type) {
case ACTION_SHIFT:
push(eat());
@@ -30,7 +30,7 @@ int lr_parser()
break;
case ACTION_REDUCE:
for(size_t i = 0; i < 2*grammar[a.arg].nRHS; i++) pop();
-
+
symbol lhs = grammar[a.arg].LHS;
struct action a_goto = table[(size_t)*stack_head][lhs];
if(a_goto.type != ACTION_GOTO) {
@@ -39,7 +39,7 @@ int lr_parser()
lhs, (size_t)*stack_head);
return 1;
}
-
+
push(lhs);
push(a_goto.arg);
break;
@@ -72,7 +72,7 @@ enum symbol {
SYMBOLS_END,
};
-const size_t total_symbols = SYMBOLS_END;
+size_t total_symbols = SYMBOLS_END;
int symbol_is_valid(symbol s) { return s < SYMBOLS_END; }
@@ -92,7 +92,7 @@ struct production grammar[] = {
const size_t total_productions = sizeof(grammar)/sizeof(*grammar);
// implement table.h
-struct action *table[] = {
+struct action **table = (struct action *([])){
(struct action[]){{0, 0},{0, 0},{1, 1},{0, 0},{1, 2},{1, 3},{0, 0},{0, 0},{2, 12},{2, 11},{2, 7},},
(struct action[]){{0, 0},{0, 0},{1, 1},{0, 0},{1, 2},{1, 3},{0, 0},{0, 0},{2, 4},{2, 11},{2, 7},},
(struct action[]){{3, 6},{3, 6},{0, 0},{3, 6},{0, 0},{0, 0},{3, 6},{0, 0},{0, 0},{0, 0},{0, 0},},