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 a开发者_如何转开发n 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
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
加载中,请稍侯......
精彩评论