我正在使用LEMON Parser Generator,由于某种原因,它在输出文件的末尾输出了一堆垃圾,而不是用%%
生成的代码替换 lempar.c 中的 s。我直接从 sqlite 源复制了 lemon.c 和 lempar.c。这是我的语法文件:
%token_prefix TK_
%token_type {const char*}
%extra_argument { HiqupElem elem }
%syntax_error {
printf("Hit syntax error, not sure..\n");
}
%stack_overflow {
printf("Stackoverflow.com\n");
}
%name hiqupParser
%include {
#include <stdio.h>
#include <assert.h>
#include "types.h"
}
%start_symbol start
start ::= in .
in(A) ::= in expression(B) SEMICOLON . { printf("Found expression %s, %s!\n", A, B); }
expression(A) ::= STRING(B) . { A = B }
expression(A) ::= NUMBER(B) . { A = B }
这是它只是附加到lempar文件副本末尾的垃圾
"$", "SEMICOLON", "STRING", "NUMBER",
"error", "start", "in", "expression",
/* 0 */ "in ::= in expression SEMICOLON",
/* 1 */ "expression ::= STRING",
/* 2 */ "expression ::= NUMBER",
/* 3 */ "start ::= in",
#line 9 "compiler.y"
printf("Stackoverflow.com\n");
#line 1025 "compiler.c"
{ 6, 3 },
{ 7, 1 },
{ 7, 1 },
{ 5, 1 },
YYMINORTYPE yylhsminor;
case 0: /* in ::= in expression SEMICOLON */
#line 25 "compiler.y"
{ printf("Found expression %s, %s!\n", yymsp[-2].minor.yy0, yymsp[-1].minor.yy0); }
#line 1034 "compiler.c"
break;
case 1: /* expression ::= STRING */
case 2: /* expression ::= NUMBER */ yytestcase(yyruleno==2);
#line 27 "compiler.y"
{ yylhsminor.yy0 = yymsp[0].minor.yy0 }
#line 1040 "compiler.c"
yymsp[0].minor.yy0 = yylhsminor.yy0;
break;
default:
/* (3) start ::= in */ yytestcase(yyruleno==3);
break;
#line 5 "compiler.y"
printf("Hit syntax error, not sure..\n");
#line 1049 "compiler.c"