From 899655aa3b256dab10e764889c8323a53a585a04 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 14 Aug 2015 23:10:28 -0700 Subject: Get Berkeley Yacc port of the parser working again. * parser.y (byacc_fool): New grammar nonterminal symbol and dummy rule set. (spec): Use dummy byacc_fool to create a fake continuation in the grammar, so the Berkeley-Yacc-generated parser doesn't throw a syntax error. Our YYACCEPT prevents the byacc_fool part from consuming more than one token of lookahead. Bison doesn't need this because it has $default actions which reduce regardless of the lookahead token. BYacc insists on reducing only if it can match $end (end of input), and not other tokens, which constitute syntax errors. --- parser.y | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/parser.y b/parser.y index d0ab1f59..bfa88a78 100644 --- a/parser.y +++ b/parser.y @@ -120,6 +120,7 @@ int yyparse(scanner_t *, parser_t *); %type strlit chrlit quasilit quasi_items quasi_item litchars wordslit %type wordsqlit not_a_clause %type regchar +%type byacc_fool %type '(' '[' '@' %nonassoc LOW /* used for precedence assertion */ @@ -141,6 +142,7 @@ spec : clauses { parser->syntax_tree = $1; } | /* empty */ { parser->syntax_tree = nil; } | SECRET_ESCAPE_R regexpr { parser->syntax_tree = $2; end_of_regex(scnr); } | SECRET_ESCAPE_E n_expr { parser->syntax_tree = $2; YYACCEPT; } + byacc_fool { internal_error("notreached"); } | SECRET_ESCAPE_E { if (yychar == YYEOF) { parser->syntax_tree = nao; YYACCEPT; @@ -156,6 +158,11 @@ spec : clauses { parser->syntax_tree = $1; } ; +/* Hack needed for Berkeley Yacc */ +byacc_fool : n_expr { internal_error("notreached"); } + | { internal_error("notreached"); } + ; + clauses : clauses_rev { $$ = nreverse($1); } clauses_rev : clause { $$ = check_for_include(cons($1, nil)); } -- cgit v1.2.3