2

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"
4

1 に答える 1