Thread: YACC abstract syntax tree error: line 47: fatal: must specify type for Begin

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    178

    YACC abstract syntax tree error: line 47: fatal: must specify type for Begin

    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.

  2. #2
    Registered User
    Join Date
    Jul 2010
    Posts
    178
    I figured it out. Begin needs to be in the token declaration with a value:
    Code:
    %token <i> Ident 1 IntConst 2 Begin 6

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. yacc: type clashes and useless nontermins
    By zxcv in forum Linux Programming
    Replies: 1
    Last Post: 02-14-2009, 02:52 AM
  2. boost::spirit, abstract syntax tree question
    By Raven Arkadon in forum C++ Programming
    Replies: 1
    Last Post: 08-18-2007, 07:31 PM
  3. Yacc question related to %type
    By g_p in forum Tech Board
    Replies: 0
    Last Post: 05-31-2007, 09:55 AM
  4. draw tree graph of yacc parsing
    By talz13 in forum C Programming
    Replies: 2
    Last Post: 07-23-2006, 01:33 AM
  5. [Linker Fatal Error] Fatal: Expected a file name
    By Checco in forum C++ Programming
    Replies: 1
    Last Post: 07-27-2005, 05:34 AM