Re: bison @n constructs

ct7@datatel.com (W. Craig Trader)
Fri, 15 Sep 1995 17:01:22 GMT

          From comp.compilers

Related articles
bison @n constructs gl@arlut.utexas.edu (Jay Scott) (1995-09-08)
Re: bison @n constructs ct7@datatel.com (1995-09-15)
Re: bison @n constructs rankin@eql.caltech.edu (1995-09-21)
| List of all articles for this month |

Newsgroups: comp.compilers
From: ct7@datatel.com (W. Craig Trader)
Keywords: yacc, comment
Organization: Datatel, Inc.
References: 95-09-086
Date: Fri, 15 Sep 1995 17:01:22 GMT

Jay Scott <gl@arlut.utexas.edu> wrote:
]Every time I get a version of bison, I see the mentions of the @n
](also known as guards?) construction. But I see nothing on how to
]USE them. Can anybody give me an example? My (by now ancient) bison
]source code didn't actually support the construct as near as I can
]tell -- ie, the lexer and so forth wouldn't recognize them as having
]any special properties. So I'd assumed this was a never-implemented
]and not fully abandoned feature. But I see other posters saying they
]USE them. I'll play the fool -- HOW? j.


>From Section 4.4 of the Bison 1.20 manual:


'@n' Acts like a structure variable containing information on the line
numbers and column numbers of the nth component of the current rule.
The structure has four members, like this:


struct {
int first_line, last_line;
int first_column, last_column;
};


Thus, to get the starting line number of the third component, use
'@3.first_line'. In order for the members of this structure to
contain valid information, you must make yylex supply this information
about each token. If you need only certain members, then yylex need
only fill in those members.
The use of this feature makes the parser noticeably slower.


>From Section 4.2.3 of the Bison 1.20 manual:


If you are using the '@n'-feature in actions to keep track of the
texual locations of tokens and groupings, then you must provide this
information in yylex. The function yyparse expects to find the texual
localtion of a token just parsed in the global variable yylloc. So
yylex must store the proper data in that variable. The value of
yylloc is a structure and you need only initialize the members that
   are going to be used by the actions. The four members are called
first_line, first_column, last_line and last_column. Note that the
use of this feature makes the parser noticeably slower.


The data type of yylloc has the name YYLTYPE.


Apparently this has nothing to do with "guards", but it seems easy enough to
use.


In _lex & yacc_, John Levine et. al. refer to guards and the '%guard'
definition for Bison with regards to the semantic parser option for Bison, and
then direct you to the Bison documentation for details. Since guards and/or
the '%guard' syntax (or the semantic parser for that matter) aren't mentioned
in the Bison 1.20 documentation, I'm willing to bet that this feature faded
away.
-------------------------------------------------------------------------
    W. Craig Trader, Programmer/Analyst, Datatel, Inc. <ct7@datatel.com>
[I could never figure out what %guard really did. -John]
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.