help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bison's semantic parsers


From: Hans Aberg
Subject: Re: Bison's semantic parsers
Date: Thu, 12 Oct 2000 20:37:22 +0200

I looked a little at Corbett's thesis, where he describes the Bison's
semantic parser feature, p 66 ff. The guards stuff is a system for error
recovery. It does not seem overly difficult to use. -- But I do not know
how useful one would view it in todays programming.

The idea is that one has to integer values, yyerror and yycost, which
initially are set to zero. The syntactic rules in the .y input file have
the form
<non-terminal>: <symbol 1> ... <symbol n> [%guard expression] [action]
The idea is that the %guard expression checks for semantic errors:

If one detects a semantic error that might be fixed by a syntactic reset,
the %%guard expression should set yyerror to 1 and yycost to a typical
penalty value based on experience. As example, he gives the following for a
Pascal auditor:
    arrval: name %guard chkarrname($1) { $$ = mkarrname($1, &(@1)); }
were one wants to define a name for an array variable in arrval. Then
chkarrname checks whether the name already is defined (semantic test!), and
if it is , sets yyerror to 1, and yycost to 5 or 20 depending on semantics.

I didn't see exactly how the yycost value should be used, perhaps only when
issuing error messages. I got the impression it is ignored by Bison.

  Hans Aberg





reply via email to

[Prev in Thread] Current Thread [Next in Thread]