X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/705db0b507ba8d57d31a23a1ac685b2d4d17e7d5..a940e84e293e55228f7c7341bc4cc7b4c6c61c98:/doc/bison.info-2 diff --git a/doc/bison.info-2 b/doc/bison.info-2 index 4bb2a61c..2cf29fce 100644 --- a/doc/bison.info-2 +++ b/doc/bison.info-2 @@ -1,5 +1,5 @@ -Ceci est le fichier Info bison.info, produit par Makeinfo version 4.0 à -partir bison.texinfo. +Ceci est le fichier Info bison.info, produit par Makeinfo version 4.0b +à partir bison.texinfo. START-INFO-DIR-ENTRY * bison: (bison). GNU Project parser generator (yacc replacement). @@ -28,6 +28,48 @@ License", "Conditions for Using Bison" and this permission notice may be included in translations approved by the Free Software Foundation instead of in the original English. + +File: bison.info, Node: Rpcalc Decls, Next: Rpcalc Rules, Up: RPN Calc + +Declarations for `rpcalc' +------------------------- + + Here are the C and Bison declarations for the reverse polish notation +calculator. As in C, comments are placed between `/*...*/'. + + /* Reverse polish notation calculator. */ + + %{ + #define YYSTYPE double + #include + %} + + %token NUM + + %% /* Grammar rules and actions follow */ + + The C declarations section (*note The C Declarations Section: C +Declarations.) contains two preprocessor directives. + + The `#define' directive defines the macro `YYSTYPE', thus specifying +the C data type for semantic values of both tokens and groupings (*note +Data Types of Semantic Values: Value Type.). The Bison parser will use +whatever type `YYSTYPE' is defined as; if you don't define it, `int' is +the default. Because we specify `double', each token and each +expression has an associated value, which is a floating point number. + + The `#include' directive is used to declare the exponentiation +function `pow'. + + The second section, Bison declarations, provides information to +Bison about the token types (*note The Bison Declarations Section: +Bison Declarations.). Each terminal symbol that is not a +single-character literal must be declared here. (Single-character +literals normally don't need to be declared.) In this example, all the +arithmetic operators are designated by single-character literals, so the +only terminal symbol that needs to be declared is `NUM', the token type +for numeric constants. +  File: bison.info, Node: Rpcalc Rules, Next: Rpcalc Lexer, Prev: Rpcalc Decls, Up: RPN Calc @@ -642,14 +684,18 @@ declarations, but it requires some additional C functions for support. definition, which is kept in the header `calc.h', is as follows. It provides for either functions or variables to be placed in the table. + /* Fonctions type. */ + typedef double (*func_t) (double); + /* Data type for links in the chain of symbols. */ struct symrec { char *name; /* name of symbol */ int type; /* type of symbol: either VAR or FNCT */ - union { - double var; /* value of a VAR */ - double (*fnctptr)(); /* value of a FNCT */ + union + { + double var; /* value of a VAR */ + func_t fnctptr; /* value of a FNCT */ } value; struct symrec *next; /* link field */ }; @@ -659,8 +705,8 @@ provides for either functions or variables to be placed in the table. /* The symbol table: a chain of `struct symrec'. */ extern symrec *sym_table; - symrec *putsym (); - symrec *getsym (); + symrec *putsym (const char *, func_t); + symrec *getsym (const char *); The new version of `main' includes a call to `init_table', a function that initializes the symbol table. Here it is, and @@ -684,22 +730,22 @@ function that initializes the symbol table. Here it is, and struct init { char *fname; - double (*fnct)(); + double (*fnct)(double); }; struct init arith_fncts[] = { - "sin", sin, - "cos", cos, + "sin", sin, + "cos", cos, "atan", atan, - "ln", log, - "exp", exp, + "ln", log, + "exp", exp, "sqrt", sqrt, 0, 0 }; /* The symbol table: a chain of `struct symrec'. */ - symrec *sym_table = (symrec *)0; + symrec *sym_table = (symrec *) 0; /* Put arithmetic functions in table. */ void @@ -857,7 +903,7 @@ produces a C-language function that recognizes correct instances of the grammar. The Bison grammar input file conventionally has a name ending in -`.y'. +`.y'. *Note Invoking Bison: Invocation. * Menu: @@ -866,6 +912,7 @@ grammar. * Rules:: How to write grammar rules. * Recursion:: Writing recursive rules. * Semantics:: Semantic values and actions. +* Locations:: Locations and actions. * Declarations:: All kinds of Bison declarations are described here. * Multiple Parsers:: Putting more than one Bison parser in one program. @@ -1168,7 +1215,7 @@ defines two mutually-recursive nonterminals, since each refers to the other.  -File: bison.info, Node: Semantics, Next: Declarations, Prev: Recursion, Up: Grammar File +File: bison.info, Node: Semantics, Next: Locations, Prev: Recursion, Up: Grammar File Defining Language Semantics ===========================