我試圖從Compiler Construction using Flex and Bison書中運行簡單編譯器,但有很多錯誤,我只是寫下書中的代碼。我不是flex和野牛的專家,我試圖解決它,但我不能。使用Flex和Bison創建簡單編譯器時出現錯誤
here are codes我試圖運行,這是錯誤。
[email protected]:/home/karo/Desktop# bison -dv Simple.y
Simple.y: warning: 39 shift/reduce conflicts [-Wconflicts-sr]
[email protected]:/home/karo/Desktop# gcc -c Simple.tab.c
In file included from Simple.y:6:0:
SM.h: In function ‘fetch_execute_cycle’:
SM.h:55:4: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat=]
default : printf("%sInternal Error: Memory Dump\n"); break;
^
In file included from Simple.y:7:0:
CG.h: In function ‘print_code’:
CG.h:28:3: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘int’ [-Wformat=]
printf("%3ld: %-10s%4ld\n",i,op_name[(int) code[i].op], code[i].arg);
^
CG.h:28:3: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 4 has type ‘int’ [-Wformat=]
Simple.tab.c: At top level:
Simple.tab.c:158:15: error: stray ‘#’ in program
typedef union #line 37 "Simple.y" /* yacc.c:355 */
^
Simple.tab.c:158:21: error: expected identifier or ‘(’ before numeric constant
typedef union #line 37 "Simple.y" /* yacc.c:355 */
^
Simple.tab.c:161:7: error: stray ‘#’ in program
union #line 37 "Simple.y" /* yacc.c:355 */
^
Simple.tab.c:161:13: error: expected identifier or ‘(’ before numeric constant
union #line 37 "Simple.y" /* yacc.c:355 */
^
Simple.tab.c:178:1: error: unknown type name ‘YYSTYPE’
extern YYSTYPE yylval;
^
Simple.tab.c:354:3: error: unknown type name ‘YYSTYPE’
YYSTYPE yyvs_alloc;
^
Simple.tab.c:683:52: error: unknown type name ‘YYSTYPE’
yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
^
Simple.tab.c:702:46: error: unknown type name ‘YYSTYPE’
yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
^
Simple.tab.c:740:39: error: unknown type name ‘YYSTYPE’
yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
^
Simple.tab.c:1020:44: error: unknown type name ‘YYSTYPE’
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
^
Simple.tab.c:1027:16: error: expected end of line before ‘push’
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
^
Simple.tab.c:1027:16: error: expected end of line before ‘ignored’
Simple.tab.c:1027:16: error: expected end of line before ‘ignored’
Simple.tab.c:1029:16: error: expected end of line before ‘pop’
YY_IGNORE_MAYBE_UNINITIALIZED_END
^
Simple.tab.c:1039:1: error: unknown type name ‘YYSTYPE’
YYSTYPE yylval;
^
Simple.tab.c: In function ‘yyparse’:
Simple.tab.c:1068:5: error: unknown type name ‘YYSTYPE’
YYSTYPE yyvsa[YYINITDEPTH];
^
Simple.tab.c:1069:5: error: unknown type name ‘YYSTYPE’
YYSTYPE *yyvs;
^
Simple.tab.c:1070:5: error: unknown type name ‘YYSTYPE’
YYSTYPE *yyvsp;
^
Simple.tab.c:1080:3: error: unknown type name ‘YYSTYPE’
YYSTYPE yyval;
^
Simple.tab.c:363:46: error: ‘YYSTYPE’ undeclared (first use in this function)
((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
^
Simple.tab.c:1157:44: note: in expansion of macro ‘YYSTACK_BYTES’
(union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
^
Simple.tab.c:363:46: note: each undeclared identifier is reported only once for each function it appears in
((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
^
Simple.tab.c:1157:44: note: in expansion of macro ‘YYSTACK_BYTES’
(union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
^
Simple.y:60:26: error: request for member ‘id’ in something not a structure or union
| INTEGER id_seq IDENTIFIER '.' { install($3); }
^
Simple.y:63:26: error: request for member ‘id’ in something not a structure or union
| id_seq IDENTIFIER ',' { install($2); }
^
Simple.y:69:41: error: request for member ‘id’ in something not a structure or union
| READ IDENTIFIER { context_check(READ_INT, $2); }
^
Simple.y:71:39: error: request for member ‘id’ in something not a structure or union
| IDENTIFIER ASSGNOP exp { context_check(STORE, $1); }
^
Simple.y:72:17: error: request for member ‘lbls’ in something not a structure or union
| IF exp { $1 = (struct lbs *) newlblrec(); $1->for_jmp_false = reserve_loc();}
^
Simple.y:72:64: error: request for member ‘lbls’ in something not a structure or union
| IF exp { $1 = (struct lbs *) newlblrec(); $1->for_jmp_false = reserve_loc();}
^
Simple.y:73:17: error: request for member ‘lbls’ in something not a structure or union
THEN commands { $1->for_goto = reverse_loc(); }
^
Simple.y:74:29: error: request for member ‘lbls’ in something not a structure or union
ELSE { back_patch($1->for_jmp_false, JMP_FALSE,gen_label());}
^
Simple.y:76:28: error: request for member ‘lbls’ in something not a structure or union
FI { back_patch($1->for_goto,GOTO,gen_label());}
^
Simple.y:77:16: error: request for member ‘lbls’ in something not a structure or union
| WHILE { $1 = (struct lbs *) newlblrec(); $1->for_goto = gen_label(); }
^
Simple.y:77:62: error: request for member ‘lbls’ in something not a structure or union
| WHILE { $1 = (struct lbs *) newlblrec(); $1->for_goto = gen_label(); }
^
Simple.y:78:17: error: request for member ‘lbls’ in something not a structure or union
exp { $1->for_jmp_false = reserve_loc(); }
^
Simple.y:81:33: error: request for member ‘lbls’ in something not a structure or union
END { gen_code(GOTO, $1->for_goto);back_patch($1->for_jmp_false,JMP_FALSE,gen_label());}
^
Simple.y:81:74: error: request for member ‘lbls’ in something not a structure or union
END { gen_code(GOTO, $1->for_goto);back_patch($1->for_jmp_false,JMP_FALSE,gen_label());}
^
Simple.y:83:34: error: request for member ‘intval’ in something not a structure or union
exp : NUMBER { gen_code(LD_INT, $1);}
^
Simple.y:84:39: error: request for member ‘id’ in something not a structure or union
| IDENTIFIER { context_check(LD_VAR, $1);}
^
我該如何解決?
你不能指望這裏的人爲你解析你的編譯器消息。我也不熟悉Flex/Bison,但對我來說,其中許多錯誤都是不言自明的。如果這些錯誤來自自動生成的代碼,則Flex/Bison版本與您使用的編譯器不兼容,或者使用不正確的選項。 – 2014-10-09 20:21:41
@ 500-InternalServerError:這是一個野牛的錯誤。請參閱https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=733942。如果這是您的失望,您可能需要重新考慮。 – rici 2014-10-11 07:28:47
不是我的 - 我幾乎從不投下任何東西。 – 2014-10-11 10:46:56