[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master: doc: mfcalc: send errors to stderr
From: |
Akim Demaille |
Subject: |
master: doc: mfcalc: send errors to stderr |
Date: |
Thu, 16 Feb 2012 15:58:47 +0100 |
From aeb57fb68d65623029357887015c2044342e2722 Mon Sep 17 00:00:00 2001
From: Akim Demaille <address@hidden>
Date: Thu, 16 Feb 2012 15:11:13 +0100
Subject: [PATCH 3/5] doc: mfcalc: send errors to stderr.
* doc/bison.texinfo (Mfcalc Lexer): New.
(Mfcalc Main): Move the definition of main and yyerror here, for
clarity.
Let yyerror report on stderr.
---
doc/bison.texinfo | 60 ++++++++++++++++++++++++++++++++--------------------
1 files changed, 37 insertions(+), 23 deletions(-)
diff --git a/doc/bison.texinfo b/doc/bison.texinfo
index 8391e71..f39f79e 100644
--- a/doc/bison.texinfo
+++ b/doc/bison.texinfo
@@ -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
@@ -2466,23 +2470,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
address@hidden 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>
-
address@hidden
-/* Called by yyparse on error. */
-void
-yyerror (char const *s)
address@hidden
- printf ("%s\n", s);
address@hidden
address@hidden group
-
@group
struct init
@{
@@ -2525,15 +2517,6 @@ init_table (void)
@}
@}
@end group
-
address@hidden
-int
-main (void)
address@hidden
- init_table ();
- return yyparse ();
address@hidden
address@hidden 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
address@hidden Mfcalc Lexer
address@hidden 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
address@hidden Mfcalc Main
address@hidden The @code{mfcalc} Main
+
+The error reporting function is unchanged, and the new version of
address@hidden includes a call to @code{init_table}:
+
address@hidden file: mfcalc.y
address@hidden
+
address@hidden
address@hidden
+/* Called by yyparse on error. */
+void
+yyerror (char const *s)
address@hidden
+ fprintf (stderr, "%s\n", s);
address@hidden
address@hidden group
+
+int
+main (int argc, char const* argv[])
address@hidden
+ init_table ();
+ return yyparse ();
address@hidden
address@hidden group
address@hidden 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.
--
1.7.9
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master: doc: mfcalc: send errors to stderr,
Akim Demaille <=