Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think your principal problem is that you failed to define a subtree constructor in your object subgrammar. (EDIT: OP says he left the semantic actions for <strong>object</strong> out of his example text. That doesn't change the following answer).</p> <p>You probably have to lookup up the objects in the order encountered, too. Maybe you intended:</p> <pre><code>primary_expression : constant_value { $$ = $1; } | '(' expression ')' { $$ = $2; } | list_initialization { $$ = $1; } | function_call { $$ = $1; } | object { $$ = $1; } ; object : IDENTIFIER { $$ = LookupVariableOrObject( yytext ); } | object ARROW IDENTIFIER { $$ = LookupSubobject( $1, yytext ); } ; </code></pre> <p>I assume that if one encounters an identifier X by itself, your default interpretation is that it is a variable name. But, if you encounter X -> Y, then even if X is a variable name, you want the <em>object</em> X with subobject Y. </p> <p>What LookupVarOrObject does is to lookup the <em>leftmost</em> identifier encountered to see if it is variable (and return essentially the same value as idlookup which must produce an AST node of type AST_VAR), or see if it is valid object name, and return an AST node marked as an AST_OBJ, or complain if the identifier isn't one of these.</p> <p>What LookupSuboject does, is to check its left operand to ensure it is an AST_OBJ (or an AST_VAR whose name happens to be the same as that of an object). and complain if it is not. If it is, then its looks up the yytext-child object of the named AST_OBJ.</p> <p>EDIT: Based on discussion comments in another answer, right-recursion in the OP's original grammar might be problematic if the OP's semantic checks inspect global lexer state (yytext). This solution is left-recursive and won't run afoul of that particular trap.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload