/[bison]/bison/doc/bison.texinfo
ViewVC logotype

Diff of /bison/doc/bison.texinfo

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.53 by eggert, Thu Feb 14 20:26:54 2002 UTC revision 1.54 by eggert, Thu Apr 4 21:34:14 2002 UTC
# Line 47  END-INFO-DIR-ENTRY Line 47  END-INFO-DIR-ENTRY
47  This file documents the Bison parser generator.  This file documents the Bison parser generator.
48    
49  Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1995, 1998, 1999,  Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1995, 1998, 1999,
50  2000, 2001  2000, 2001, 2002
51  Free Software Foundation, Inc.  Free Software Foundation, Inc.
52    
53  Permission is granted to make and distribute verbatim copies of  Permission is granted to make and distribute verbatim copies of
# Line 89  instead of in the original English. Line 89  instead of in the original English.
89  @page  @page
90  @vskip 0pt plus 1filll  @vskip 0pt plus 1filll
91  Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1995, 1998,  Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1995, 1998,
92  1999, 2000, 2001  1999, 2000, 2001, 2002
93  Free Software Foundation, Inc.  Free Software Foundation, Inc.
94    
95  @sp 2  @sp 2
# Line 1083  The return value of the lexical analyzer Line 1083  The return value of the lexical analyzer
1083  represents a token type.  The same text used in Bison rules to stand for  represents a token type.  The same text used in Bison rules to stand for
1084  this token type is also a C expression for the numeric code for the type.  this token type is also a C expression for the numeric code for the type.
1085  This works in two ways.  If the token type is a character literal, then its  This works in two ways.  If the token type is a character literal, then its
1086  numeric code is the ASCII code for that character; you can use the same  numeric code is that of the character; you can use the same
1087  character literal in the lexical analyzer to express the number.  If the  character literal in the lexical analyzer to express the number.  If the
1088  token type is an identifier, that identifier is defined by Bison as a C  token type is an identifier, that identifier is defined by Bison as a C
1089  macro whose definition is the appropriate number.  In this example,  macro whose definition is the appropriate number.  In this example,
# Line 1104  Here is the code for the lexical analyze Line 1104  Here is the code for the lexical analyze
1104  @example  @example
1105  @group  @group
1106  /* Lexical analyzer returns a double floating point  /* Lexical analyzer returns a double floating point
1107     number on the stack and the token NUM, or the ASCII     number on the stack and the token NUM, or the numeric code
1108     character read if not a number.  Skips all blanks     of the character read if not a number.  Skips all blanks
1109     and tabs, returns 0 for EOF. */     and tabs, returns 0 for EOF. */
1110    
1111  #include <ctype.h>  #include <ctype.h>
# Line 2148  your program will confuse other readers. Line 2148  your program will confuse other readers.
2148    
2149  All the usual escape sequences used in character literals in C can be  All the usual escape sequences used in character literals in C can be
2150  used in Bison as well, but you must not use the null character as a  used in Bison as well, but you must not use the null character as a
2151  character literal because its ASCII code, zero, is the code @code{yylex}  character literal because its numeric code, zero, is the code @code{yylex}
2152  returns for end-of-input (@pxref{Calling Convention, ,Calling Convention  returns for end-of-input (@pxref{Calling Convention, ,Calling Convention
2153  for @code{yylex}}).  for @code{yylex}}).
2154    
# Line 2189  on when the parser function returns that Line 2189  on when the parser function returns that
2189  The value returned by @code{yylex} is always one of the terminal symbols  The value returned by @code{yylex} is always one of the terminal symbols
2190  (or 0 for end-of-input).  Whichever way you write the token type in the  (or 0 for end-of-input).  Whichever way you write the token type in the
2191  grammar rules, you write it the same way in the definition of @code{yylex}.  grammar rules, you write it the same way in the definition of @code{yylex}.
2192  The numeric code for a character token type is simply the ASCII code for  The numeric code for a character token type is simply the numeric code of
2193  the character, so @code{yylex} can use the identical character constant to  the character, so @code{yylex} can use the identical character constant to
2194  generate the requisite code.  Each named token type becomes a C macro in  generate the requisite code.  Each named token type becomes a C macro in
2195  the parser file, so @code{yylex} can use the name to stand for the code.  the parser file, so @code{yylex} can use the name to stand for the code.
# Line 2202  option when you run Bison, so that it wi Line 2202  option when you run Bison, so that it wi
2202  into a separate header file @file{@var{name}.tab.h} which you can include  into a separate header file @file{@var{name}.tab.h} which you can include
2203  in the other source files that need it.  @xref{Invocation, ,Invoking Bison}.  in the other source files that need it.  @xref{Invocation, ,Invoking Bison}.
2204    
2205    The @code{yylex} function must use the same character set and encoding
2206    that was used by Bison.  For example, if you run Bison in an
2207    @sc{ascii} environment, but then compile and run the resulting program
2208    in an environment that uses an incompatible character set like
2209    @sc{ebcdic}, the resulting program will probably not work because the
2210    tables generated by Bison will assume @sc{ascii} numeric values for
2211    character tokens.  Portable grammars should avoid non-@sc{ascii}
2212    character tokens, as implementations in practice often use different
2213    and incompatible extensions in this area.  However, it is standard
2214    practice for software distributions to contain C source files that
2215    were generated by Bison in an @sc{ascii} environment, so installers on
2216    platforms that are incompatible with @sc{ascii} must rebuild those
2217    files before compiling them.
2218    
2219  The symbol @code{error} is a terminal symbol reserved for error recovery  The symbol @code{error} is a terminal symbol reserved for error recovery
2220  (@pxref{Error Recovery}); you shouldn't use it for any other purpose.  (@pxref{Error Recovery}); you shouldn't use it for any other purpose.
2221  In particular, @code{yylex} should never return this value.  In particular, @code{yylex} should never return this value.
2222    The default value of the error token is 256, so in the
2223    unlikely event that you need to use a character token with numeric
2224    value 256 you must reassign the error token's value with a
2225    @code{%token} declaration.
2226    
2227  @node Rules  @node Rules
2228  @section Syntax of Grammar Rules  @section Syntax of Grammar Rules
# Line 2942  an integer value in the field immediatel Line 2960  an integer value in the field immediatel
2960  @noindent  @noindent
2961  It is generally best, however, to let Bison choose the numeric codes for  It is generally best, however, to let Bison choose the numeric codes for
2962  all token types.  Bison will automatically select codes that don't conflict  all token types.  Bison will automatically select codes that don't conflict
2963  with each other or with ASCII characters.  with each other or with normal characters.
2964    
2965  In the event that the stack type is a union, you must augment the  In the event that the stack type is a union, you must augment the
2966  @code{%token} or other token declaration to include the data type  @code{%token} or other token declaration to include the data type

Legend:
Removed from v.1.53  
changed lines
  Added in v.1.54

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26