I'm trying to parse multidimensional arrays with YACC. Here is my lvalue definition:
lvalue: ID { EM_debug("got lvalue identifier " + to_String($1));
$$.My_VAR = A_SimpleVar($$.pos, $1);
$$.size = 0;
$$.name = $1;
}
| lvalue L_SQUARE_BRACKET exp R_SQUARE_BRACKET { EM_debug("got lvalue[exp]");
$$.My_VAR = A_SubscriptVar($$.pos, $1.My_VAR, $3.My_AST);
$$.size = $3.My_AST;
$$.name = $1.name;
}
;
For the (simplified) input ia[2]
it prints got lvalue identifier ia
and gives a parsing error when it encounters the left bracket. I don't get why this would not work. It should see the left bracket in its lookahead and shift. It should not reduce immediately like this. How can I prevent it from shifting?