diff options
Diffstat (limited to 'yacc.1')
-rw-r--r-- | yacc.1 | 101 |
1 files changed, 95 insertions, 6 deletions
@@ -1,4 +1,4 @@ -.\" $Id: yacc.1,v 1.20 2014/01/01 17:40:13 tom Exp $ +.\" $Id: yacc.1,v 1.23 2014/04/09 09:48:50 tom Exp $ .\" .\" .TH YACC 1 "July\ 15,\ 1990" .\" .UC 6 @@ -27,8 +27,10 @@ .SH NAME Yacc \- an LALR(1) parser generator .SH SYNOPSIS -.B yacc [ -dgilrtv ] [ \-b +.B yacc [ -BdgilLPrtvVy ] [ \-b .I file_prefix +.B ] [ \-o +.I output_file .B ] [ \-p .I symbol_prefix .B ] @@ -55,6 +57,9 @@ the string denoted by The default prefix is the character .IR y. .TP +.B \-B +create a backtracking parser (compile-type configuration for \fBbtyacc\fP). +.TP .B \-d The \fB-d\fR option causes the header file .BR y.tab.h @@ -96,11 +101,14 @@ If the \fB-l\fR option is specified, will not insert the \fI#line\fP directives. \&\fI#line\fP directives specified by the user will be retained. .TP +.B \-L +enable position processing, e.g., \*(``%locations\*('' (compile-type configuration for \fBbtyacc\fP). +.TP \fB\-o \fP\fIoutput_file\fR specify the filename for the parser file. If this option is not given, the output filename is the file prefix concatenated with the file suffix, e.g., \fBy.tab.c\fP. -This overrides the \fB-p\fP option. +This overrides the \fB-b\fP option. .TP \fB\-p \fP\fIsymbol_prefix\fR The @@ -176,10 +184,55 @@ which bison supports for ostensible POSIX compatibility. .SH EXTENSIONS .B yacc provides some extensions for -compatibility with bison and other implementations of yacc: +compatibility with bison and other implementations of yacc. +The \fB%destructor\fP and \fB%locations\fP features are available +only if \fByacc\fP has been configured and compiled to support the +back-tracking (\fBbtyacc\fP) functionality. +The remaining features are always available: +.TP +\fB %destructor\fP { \fIcode\fP } \fIsymbol+\fP +defines code that is invoked when a symbol is automatically +discarded during error recovery. +This code can be used to +reclaim dynamically allocated memory associated with the corresponding +semantic value for cases where user actions cannot manage the memory +explicitly. +.IP +On encountering a parse error, the generated parser +discards symbols on the stack and input tokens until it reaches a state +that will allow parsing to continue. +This error recovery approach results in a memory leak +if the \fBYYSTYPE\fP value is, or contains, +pointers to dynamically allocated memory. +.IP +The bracketed \fIcode\fP is invoked whenever the parser discards one of +the symbols. Within \fIcode\fP, \*(``\fB$$\fP\*('' or +\*(``\fB$<tag>$\fP\*('' designates the semantic value associated with the +discarded symbol, and \*(``\fB@$\fP\*('' designates its location (see +\fB%locations\fP directive). +.IP +A per-symbol destructor is defined by listing a grammar symbol +in \fIsymbol+\fP. A per-type destructor is defined by listing +a semantic type tag (e.g., \*(``<some_tag>\*('') in \fIsymbol+\fP; in this +case, the parser will invoke \fIcode\fP whenever it discards any grammar +symbol that has that semantic type tag, unless that symbol has its own +per-symbol destructor. +.IP +Two categories of default destructor are supported that are +invoked when discarding any grammar symbol that has no per-symbol and no +per-type destructor: +.RS +.bP +the code for \*(``\fB<*>\fP\*('' is used +for grammar symbols that have an explicitly declared semantic type tag +(via \*(``\fB%type\fP\*(''); +.bP +the code for \*(``\fB<>\fP\*('' is used +for grammar symbols that have no declared semantic type tag. +.RE .TP \fB %expect\fP \fInumber\fP -tell \fByacc\fP the expected number of shift/reduce conflicts. +tells \fByacc\fP the expected number of shift/reduce conflicts. That makes it only report the number if it differs. .TP \fB %expect-rr\fP \fInumber\fP @@ -187,6 +240,42 @@ tell \fByacc\fP the expected number of reduce/reduce conflicts. That makes it only report the number if it differs. This is (unlike bison) allowable in LALR parsers. .TP +\fB %locations\fP +tells \fByacc\fP to enable management of position information associated +with each token, provided by the lexer in the global variable \fByylloc\fP, +similar to management of semantic value information provided in \fByylval\fP. +.IP +As for semantic values, locations can be referenced within actions using +\fB@$\fP to refer to the location of the left hand side symbol, and \fB@N\fP +(\fBN\fP an integer) to refer to the location of one of the right hand side +symbols. Also as for semantic values, when a rule is matched, a default +action is used the compute the location represented by \fB@$\fP as the +beginning of the first symbol and the end of the last symbol in the right +hand side of the rule. This default computation can be overridden by +explicit assignment to \fB@$\fP in a rule action. +.IP +The type of \fByylloc\fP is \fBYYLTYPE\fP, which is defined by default as: +.ES +typedef struct YYLTYPE { + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +.XE +.IP +\fBYYLTYPE\fP can be redefined by the user +(\fBYYLTYPE_IS_DEFINED\fP must be defined, to inhibit the default) +in the declarations section of the specification file. +As in bison, the macro \fBYYLLOC_DEFAULT\fP is invoked +each time a rule is matched to calculate a position for the left hand side of +the rule, before the associated action is executed; this macro can be +redefined by the user. +.IP +This directive adds a \fBYYLTYPE\fP parameter to \fByyerror()\fP. +If the \fB%pure-parser\fP directive is present, +a \fBYYLTYPE\fP parameter is added to \fByylex()\fP calls. +.TP \fB %lex-param\fP { \fIargument-declaration\fP } By default, the lexer accepts no parameters, e.g., \fByylex()\fP. Use this directive to add parameter declarations for your customized lexer. @@ -224,7 +313,7 @@ http://pubs.opengroup.org/onlinepubs/9699919799/utilities/yacc.html documents some features of AT&T yacc which are no longer required for POSIX compliance. .PP -That said, you may be interested in reusing grammary files with some +That said, you may be interested in reusing grammar files with some other implementation which is not strictly compatible with AT&T yacc. For instance, there is bison. Here are a few differences: |