aboutsummaryrefslogtreecommitdiff
path: root/lr-parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'lr-parser.c')
-rw-r--r--lr-parser.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/lr-parser.c b/lr-parser.c
index 9f7ea24..3ab9af4 100644
--- a/lr-parser.c
+++ b/lr-parser.c
@@ -18,10 +18,13 @@ static stack_item *stack_head = stack_bottom;
int lr_parser()
{
-#define push(item) ({ if(++stack_head - stack_bottom < STACK_CAP ) (*stack_head = item); else { fprintf(stderr, "ERROR: STACK_CAP exceeded"); return 1; }})
+#define push(item) ({ if(++stack_head - stack_bottom < STACK_CAP ) (*stack_head = item); else { fprintf(stderr, "ERROR: STACK_CAP exceeded\n"); return 1; }})
#define pop() (--stack_head)
#define eat() toklist_eat()
-#define peek() ({ symbol s = toklist_peek(); if(!symbol_is_valid(s)) return 1; s; })
+#define peek() ({ \
+ symbol s = toklist_peek(); \
+ if(!symbol_is_valid(s)) { fprintf(stderr, "ERROR: Unknown token '%d'\n", s); return 1;} \
+ s; })
while(1) {
struct action a = table[(size_t)*stack_head][peek()];
@@ -38,7 +41,7 @@ int lr_parser()
struct action a_goto = table[(size_t)*stack_head][lhs];
if(a_goto.type != ACTION_GOTO) {
fprintf(stderr,
- "ERROR: Expected goto action for symbol %d at state %zu",
+ "ERROR: Expected goto action for token '%d' at state %zu\n",
lhs, (size_t)*stack_head);
return 1;
}
@@ -51,7 +54,7 @@ int lr_parser()
case ACTION_NOT_SET:
default:
fprintf(stderr,
- "ERROR: Unexpected error symbol %d at state %zu",
+ "ERROR: Unexpected token '%d' at state %zu\n",
peek(), (size_t)*stack_head);
return 1;
}