Your question is slightly unclear: where do you want to call yyerror
from?
If you want to call it from the parser, then just use the @n
pseudo-variables:
exp: exp "/" exp
{
if (!$3)
{
yyerror(@3, "division by zero");
YYERROR;
}
else
{
$$ = $1 / $3;
}
}
If you want to call it from the scanner, then use the variable used there to denote the current location, probably something like yylloc
.
If you want to call it from elsewhere (e.g., from an AST traversal, but that would be weird), then find the location there.
But more importantly (sorry, I may state something that you already know): be aware that you typically do not need to call yyerror
: you have to provide it, so that parser can raise errors. Typical calls to yyerror
are in the generated code, not in code you are expected to write.