Got Error on Creating Simple Compiler Using Flex and Bison -



Got Error on Creating Simple Compiler Using Flex and Bison -

i'm trying run simple compiler compiler construction using flex , bison book there lot of error write downwards code book. not expert in flex , bison tried prepare can't.

here codes tried run , error.

root@tom:/home/karo/desktop# bison -dv simple.y simple.y: warning: 39 shift/reduce conflicts [-wconflicts-sr] root@tom:/home/karo/desktop# gcc -c simple.tab.c in file included simple.y:6:0: sm.h: in function ‘fetch_execute_cycle’: sm.h:55:4: warning: format ‘%s’ expects matching ‘char *’ argument [-wformat=] default : printf( "%sinternal error: memory dump\n" ); break; ^ in file included simple.y:7:0: cg.h: in function ‘print_code’: cg.h:28:3: warning: format ‘%ld’ expects argument of type ‘long int’, 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’, argument 4 has type ‘int’ [-wformat=] simple.tab.c: @ top level: simple.tab.c:158:15: error: stray ‘#’ in programme 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 programme 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 utilize in 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 reported 1 time each function 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 fellow member ‘id’ in not construction or union | integer id_seq identifier '.' { install( $3 ); } ^ simple.y:63:26: error: request fellow member ‘id’ in not construction or union | id_seq identifier ',' { install( $2 ); } ^ simple.y:69:41: error: request fellow member ‘id’ in not construction or union | read identifier { context_check( read_int, $2 ); } ^ simple.y:71:39: error: request fellow member ‘id’ in not construction or union | identifier assgnop exp { context_check( store, $1 ); } ^ simple.y:72:17: error: request fellow member ‘lbls’ in not construction or union | if exp { $1 = (struct lbs *) newlblrec(); $1->for_jmp_false = reserve_loc();} ^ simple.y:72:64: error: request fellow member ‘lbls’ in not construction or union | if exp { $1 = (struct lbs *) newlblrec(); $1->for_jmp_false = reserve_loc();} ^ simple.y:73:17: error: request fellow member ‘lbls’ in not construction or union commands { $1->for_goto = reverse_loc(); } ^ simple.y:74:29: error: request fellow member ‘lbls’ in not construction or union else { back_patch( $1->for_jmp_false, jmp_false,gen_label() );} ^ simple.y:76:28: error: request fellow member ‘lbls’ in not construction or union fi { back_patch($1->for_goto,goto,gen_label());} ^ simple.y:77:16: error: request fellow member ‘lbls’ in not construction or union | while { $1 = (struct lbs *) newlblrec(); $1->for_goto = gen_label(); } ^ simple.y:77:62: error: request fellow member ‘lbls’ in not construction or union | while { $1 = (struct lbs *) newlblrec(); $1->for_goto = gen_label(); } ^ simple.y:78:17: error: request fellow member ‘lbls’ in not construction or union exp { $1->for_jmp_false = reserve_loc(); } ^ simple.y:81:33: error: request fellow member ‘lbls’ in not construction 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 fellow member ‘lbls’ in not construction 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 fellow member ‘intval’ in not construction or union exp : number { gen_code( ld_int, $1 );} ^ simple.y:84:39: error: request fellow member ‘id’ in not construction or union | identifier { context_check( ld_var, $1 );} ^

how can prepare ?

this reported bug in bison 3.0.2, comes non-standard usage

%union <union-name> { <union members }

when this, bison 3.0.2 incorrectly inserts #line directive generated code before <union-name>, not @ origin of line.

if remove name, things work union called union yystype instead of union semrec, might turn out problem. i'd suggest following:

%union semrec { // .. members .. }

all other errors (probably) come syntax error in union declaration.

the new-line before union name should resolve problem. don't have install of 3.0.2 handy, though, no promises. i'll seek take @ tomorrow.

compiler-construction bison flex-lexer

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -