]> git.saurik.com Git - bison.git/blobdiff - doc/bison.texinfo
maint: address a couple of syntax-check errors.
[bison.git] / doc / bison.texinfo
index 8391e71445b62f695591051f60fa8665d1e5fd0e..cd687b90c29fc606e112c8b63d113229ce52fbdc 100644 (file)
@@ -178,6 +178,8 @@ Multi-Function Calculator: @code{mfcalc}
 * Mfcalc Declarations::    Bison declarations for multi-function calculator.
 * Mfcalc Rules::           Grammar rules for the calculator.
 * Mfcalc Symbol Table::    Symbol table management subroutines.
+* Mfcalc Lexer::           The lexical analyzer.
+* Mfcalc Main::            The controlling function.
 
 Bison Grammar Files
 
@@ -2320,6 +2322,8 @@ Note that multiple assignment and nested function calls are permitted.
 * Mfcalc Declarations::    Bison declarations for multi-function calculator.
 * Mfcalc Rules::           Grammar rules for the calculator.
 * Mfcalc Symbol Table::    Symbol table management subroutines.
+* Mfcalc Lexer::           The lexical analyzer.
+* Mfcalc Main::            The controlling function.
 @end menu
 
 @node Mfcalc Declarations
@@ -2332,6 +2336,7 @@ Here are the C and Bison declarations for the multi-function calculator.
 @group
 %@{
   #include <stdio.h>  /* For printf, etc. */
+  #include <math.h>   /* For pow, used in the grammar.  */
   #include "calc.h"   /* Contains definition of `symrec'.  */
   int yylex (void);
   void yyerror (char const *);
@@ -2466,23 +2471,11 @@ symrec *getsym (char const *);
 @end group
 @end smallexample
 
-The new version of @code{main} includes a call to @code{init_table}, a
-function that initializes the symbol table.  Here it is, and
-@code{init_table} as well:
+The new version of @code{main} will call @code{init_table} to initialize
+the symbol table:
 
 @comment file: mfcalc.y
 @smallexample
-#include <stdio.h>
-
-@group
-/* Called by yyparse on error.  */
-void
-yyerror (char const *s)
-@{
-  printf ("%s\n", s);
-@}
-@end group
-
 @group
 struct init
 @{
@@ -2492,7 +2485,6 @@ struct init
 @end group
 
 @group
-#include <math.h>  /* Math functions, cos(), sin(), etc.  */
 struct init const arith_fncts[] =
 @{
   @{ "atan", atan @},
@@ -2525,15 +2517,6 @@ init_table (void)
     @}
 @}
 @end group
-
-@group
-int
-main (void)
-@{
-  init_table ();
-  return yyparse ();
-@}
-@end group
 @end smallexample
 
 By simply editing the initialization list and adding the necessary include
@@ -2577,6 +2560,9 @@ getsym (char const *sym_name)
 @}
 @end smallexample
 
+@node Mfcalc Lexer
+@subsection The @code{mfcalc} Lexer
+
 The function @code{yylex} must now recognize variables, numeric values, and
 the single-character arithmetic operators.  Strings of alphanumeric
 characters with a leading letter are recognized as either variables or
@@ -2678,6 +2664,34 @@ yylex (void)
 @end group
 @end smallexample
 
+@node Mfcalc Main
+@subsection The @code{mfcalc} Main
+
+The error reporting function is unchanged, and the new version of
+@code{main} includes a call to @code{init_table}:
+
+@comment file: mfcalc.y
+@smallexample
+
+@group
+@group
+/* Called by yyparse on error.  */
+void
+yyerror (char const *s)
+@{
+  fprintf (stderr, "%s\n", s);
+@}
+@end group
+
+int
+main (int argc, char const* argv[])
+@{
+  init_table ();
+  return yyparse ();
+@}
+@end group
+@end smallexample
+
 This program is both powerful and flexible.  You may easily add new
 functions, and it is a simple job to modify this code to install
 predefined variables such as @code{pi} or @code{e} as well.