I am working on a YACC file for a compiler independent study. I have received the above error. I am pretty sure the way I am starting off the tree is incorrect and I am not sure how I would correct the issue. The CFG Production for the first tow items happen to be:
Code:
program -> block
block -> "begin" optdecls stmts "end"
The portion of the yacc file is as follows:
Code:
%token <i> Ident 1 IntConst 2
%token <f> RealConst 3
%token And 4 Array 5 Begin 6 Boolean 7 Div 8 Do 9 Else 10
%token End 11 False 12 For 13 Goto 14 If 15
%token Imply 16 Integer 17 Label 18 Not 19 Or 20
%token Own 21 Procedure 22 Real 23 Step 24 String 25
%token Then 26 True 27 Until 28 Value 29 While 30
%token Plus 31 Minus 32 Mult 33 Divide 34 Less 35
%token LessEq 36 Great 37 GreatEq 38 Eq 39 NotEq 40
%token Comma 41 Colon 42 Semi 43 LParan 44 RParan 45
%token LBrak 46 RBrak 47 Assign 48
%{
#include "tree.h"
extern tree root;
%}
%start program
%union { tree t; int i; float f; }
%type <t> block optdecls decl vardecl type idlist arraydecl arraylist arrayseg
%type <t> stmts stmt u_stmt assign dummy for_stmt if_stmt var factor term sum
%type <t> brel relation bsecond bfactor bterm expr a_expr
%%
program
: block
{ root = $1; }
;
block
: Begin optdecls stmts End
{ $$ = buildTree(Begin, $1, $2, NULL); } <----ERROR here, line 47
;
optdecls
: /* empty */
{ $$ = NULL; }
| decl Semi optdecls
{ $$ = buildTree($1, Semi); $$->next = $3; }
After looking over some code my professor has shown us, I noticed he does not specify a type for his "begin" in his version of a different yacc file. I am not sure how to correct this. Can someone show me what is my error and how I would correct it? If you need more code, I will repost. Thanks.