Search code examples
ccompiler-constructionbisonyacc

YACC Not getting the values from successor nodes


I'm making a school project and I'm having some trouble.

I have this yacc grammer

FILE        : '{' GEOMETRY '}'
            ;

GEOMETRY    : key_type ':' value_point ',' key_coordinates ':' PONTO
            ;


PONTO       : VETOR_MIN2 { printf("%s", $<str>1); }
            ;

VETOR_MIN2  : '['  numero ',' numero ']'
            ;

When I make that printf in the non terminal PONTO I only get this: [

but I should get something like this: [20, 10] What it's missing here? Please help. Thanks for your time.


Solution

  • The semantic value of a rule is the value that resides in $$ after that rule's actions have been run. If a rule does not have any actions (as is the case for VECTOR_MIN2), the default action is $$ = $1; (unless there is no $1 or the types don't match, in which case there is no default action).

    If you want VECTOR_MIN2 to produce a different value, you'll need to add an action and assign a different value to $$.