views:

237

answers:

1

i am developing parser using bison...in my grammar i am getting this error

Here is a code

extern NodePtr  CreateNode(NodeType, ...);
extern NodePtr  ReplaceNode(NodeType, NodePtr); 
extern NodePtr  MergeSubTrees(NodeType, ...); 


            ...................


NodePtr   rootNodePtr = NULL; /* pointer to the root of the parse tree */
NodePtr   nodePtr = NULL; /* pointer to an error node */


                         ...........................

NodePtr   mainMethodDecNodePtr = NULL;

                   ................

/* YYSTYPE */

%union {
 NodePtr nodePtr;
}

i am getting this error whenever i use like $$.nodePtr or $1.nodePtr ... I am getting Parser.y:1302.32-33: $1 of `Expressi on' has no declared type

+2  A: 

That means that the first item (terminal or non-terminal) on the RHS of the Expression rule on line 1302 of parser.y has no type declared for it. If its a terminal, you need to add %token declarations for it, and if its a non-terminal, you need to add a %type declaration for it. When you do that (probably either $type <nodePtr> or %token <nodePtr>), you will access the value as just $1 (no .nodePtr suffix)

edit

sounds like line 1302 should be $$ = $1;. The %type <nodePtr> XXX should go in the first section, where XXX is the non-terminal for this rule. When you use %union in a .y file, the tags declared in the union should ONLY be used in %type and %token declarations -- they should not appear in any action in the .y file

Chris Dodd
line at 1302 is $$.nodePtr = $1.nodePtr;.... in %union { NodePtr nodePtr;} NodePtr is structure...
mihirpmehta
you mean if nodePtr is of type Structure NodePtr then it should be %type <nodePtr> NodePtr ?
mihirpmehta
No, `%type` is used to declare which member of the `%union` is associated with a given non-terminal in the grammar. Since you haven't posted any of your grammar, I don't know what that would be.
Chris Dodd