mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
doc: check the rpcalc.
* doc/bison.texinfo: Tag rpcalc.y snippets. Add missing includes. (Rpcalc Rules): Don't issue leading tabs. Complete an Info menu. Use @result. * examples/rpcalc/local.mk: New. * examples/rpcalc/rpcalc.test: New. * examples/local.mk: Use them. * examples/mfcalc/mfcalc.test: Remove dup test. * examples/test: Disable debug traces.
This commit is contained in:
@@ -163,9 +163,9 @@ Reverse Polish Notation Calculator
|
|||||||
|
|
||||||
Grammar Rules for @code{rpcalc}
|
Grammar Rules for @code{rpcalc}
|
||||||
|
|
||||||
* Rpcalc Input::
|
* Rpcalc Input:: Explanation of the @code{input} nonterminal
|
||||||
* Rpcalc Line::
|
* Rpcalc Line:: Explanation of the @code{line} nonterminal
|
||||||
* Rpcalc Expr::
|
* Rpcalc Expr:: Explanation of the @code{expr} nonterminal
|
||||||
|
|
||||||
Location Tracking Calculator: @code{ltcalc}
|
Location Tracking Calculator: @code{ltcalc}
|
||||||
|
|
||||||
@@ -1517,11 +1517,13 @@ The source code for this calculator is named @file{rpcalc.y}. The
|
|||||||
Here are the C and Bison declarations for the reverse polish notation
|
Here are the C and Bison declarations for the reverse polish notation
|
||||||
calculator. As in C, comments are placed between @samp{/*@dots{}*/}.
|
calculator. As in C, comments are placed between @samp{/*@dots{}*/}.
|
||||||
|
|
||||||
|
@comment file: rpcalc.y
|
||||||
@example
|
@example
|
||||||
/* Reverse polish notation calculator. */
|
/* Reverse polish notation calculator. */
|
||||||
|
|
||||||
%@{
|
%@{
|
||||||
#define YYSTYPE double
|
#define YYSTYPE double
|
||||||
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
int yylex (void);
|
int yylex (void);
|
||||||
void yyerror (char const *);
|
void yyerror (char const *);
|
||||||
@@ -1566,13 +1568,14 @@ type for numeric constants.
|
|||||||
|
|
||||||
Here are the grammar rules for the reverse polish notation calculator.
|
Here are the grammar rules for the reverse polish notation calculator.
|
||||||
|
|
||||||
|
@comment file: rpcalc.y
|
||||||
@example
|
@example
|
||||||
input: /* empty */
|
input: /* empty */
|
||||||
| input line
|
| input line
|
||||||
;
|
;
|
||||||
|
|
||||||
line: '\n'
|
line: '\n'
|
||||||
| exp '\n' @{ printf ("\t%.10g\n", $1); @}
|
| exp '\n' @{ printf ("%.10g\n", $1); @}
|
||||||
;
|
;
|
||||||
|
|
||||||
exp: NUM @{ $$ = $1; @}
|
exp: NUM @{ $$ = $1; @}
|
||||||
@@ -1607,9 +1610,9 @@ main job of most actions. The semantic values of the components of the
|
|||||||
rule are referred to as @code{$1}, @code{$2}, and so on.
|
rule are referred to as @code{$1}, @code{$2}, and so on.
|
||||||
|
|
||||||
@menu
|
@menu
|
||||||
* Rpcalc Input::
|
* Rpcalc Input:: Explanation of the @code{input} nonterminal
|
||||||
* Rpcalc Line::
|
* Rpcalc Line:: Explanation of the @code{line} nonterminal
|
||||||
* Rpcalc Expr::
|
* Rpcalc Expr:: Explanation of the @code{expr} nonterminal
|
||||||
@end menu
|
@end menu
|
||||||
|
|
||||||
@node Rpcalc Input
|
@node Rpcalc Input
|
||||||
@@ -1653,7 +1656,7 @@ Now consider the definition of @code{line}:
|
|||||||
|
|
||||||
@example
|
@example
|
||||||
line: '\n'
|
line: '\n'
|
||||||
| exp '\n' @{ printf ("\t%.10g\n", $1); @}
|
| exp '\n' @{ printf ("%.10g\n", $1); @}
|
||||||
;
|
;
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
@@ -1769,6 +1772,7 @@ A token type code of zero is returned if the end-of-input is encountered.
|
|||||||
|
|
||||||
Here is the code for the lexical analyzer:
|
Here is the code for the lexical analyzer:
|
||||||
|
|
||||||
|
@comment file: rpcalc.y
|
||||||
@example
|
@example
|
||||||
@group
|
@group
|
||||||
/* The lexical analyzer returns a double floating point
|
/* The lexical analyzer returns a double floating point
|
||||||
@@ -1817,6 +1821,7 @@ In keeping with the spirit of this example, the controlling function is
|
|||||||
kept to the bare minimum. The only requirement is that it call
|
kept to the bare minimum. The only requirement is that it call
|
||||||
@code{yyparse} to start the process of parsing.
|
@code{yyparse} to start the process of parsing.
|
||||||
|
|
||||||
|
@comment file: rpcalc.y
|
||||||
@example
|
@example
|
||||||
@group
|
@group
|
||||||
int
|
int
|
||||||
@@ -1837,6 +1842,7 @@ always @code{"syntax error"}). It is up to the programmer to supply
|
|||||||
@code{yyerror} (@pxref{Interface, ,Parser C-Language Interface}), so
|
@code{yyerror} (@pxref{Interface, ,Parser C-Language Interface}), so
|
||||||
here is the definition we will use:
|
here is the definition we will use:
|
||||||
|
|
||||||
|
@comment file: rpcalc.y
|
||||||
@example
|
@example
|
||||||
@group
|
@group
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -1919,15 +1925,15 @@ example session using @code{rpcalc}.
|
|||||||
@example
|
@example
|
||||||
$ @kbd{rpcalc}
|
$ @kbd{rpcalc}
|
||||||
@kbd{4 9 +}
|
@kbd{4 9 +}
|
||||||
13
|
@result{} 13
|
||||||
@kbd{3 7 + 3 4 5 *+-}
|
@kbd{3 7 + 3 4 5 *+-}
|
||||||
-13
|
@result{} -13
|
||||||
@kbd{3 7 + 3 4 5 * + - n} @r{Note the unary minus, @samp{n}}
|
@kbd{3 7 + 3 4 5 * + - n} @r{Note the unary minus, @samp{n}}
|
||||||
13
|
@result{} 13
|
||||||
@kbd{5 6 / 4 n +}
|
@kbd{5 6 / 4 n +}
|
||||||
-3.166666667
|
@result{} -3.166666667
|
||||||
@kbd{3 4 ^} @r{Exponentiation}
|
@kbd{3 4 ^} @r{Exponentiation}
|
||||||
81
|
@result{} 81
|
||||||
@kbd{^D} @r{End-of-file indicator}
|
@kbd{^D} @r{End-of-file indicator}
|
||||||
$
|
$
|
||||||
@end example
|
@end example
|
||||||
|
|||||||
@@ -20,3 +20,4 @@ TEST_LOG_COMPILER = $(top_srcdir)/examples/test
|
|||||||
|
|
||||||
include examples/calc++/local.mk
|
include examples/calc++/local.mk
|
||||||
include examples/mfcalc/local.mk
|
include examples/mfcalc/local.mk
|
||||||
|
include examples/rpcalc/local.mk
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ cat >input <<EOF
|
|||||||
1+2*3
|
1+2*3
|
||||||
EOF
|
EOF
|
||||||
run 0 7
|
run 0 7
|
||||||
run 0 7
|
|
||||||
|
|
||||||
cat >input <<EOF
|
cat >input <<EOF
|
||||||
(1+2) * 3
|
(1+2) * 3
|
||||||
|
|||||||
3
examples/rpcalc/.gitignore
vendored
Normal file
3
examples/rpcalc/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/calc.h
|
||||||
|
/rpcalc.stamp
|
||||||
|
/rpcalc.y
|
||||||
57
examples/rpcalc/local.mk
Normal file
57
examples/rpcalc/local.mk
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
## Process this file with automake to produce Makefile.in -*-Makefile-*-
|
||||||
|
|
||||||
|
## Copyright (C) 2005-2006, 2008-2012 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
## ------------ ##
|
||||||
|
## Extracting. ##
|
||||||
|
## ------------ ##
|
||||||
|
|
||||||
|
# Extract in src.
|
||||||
|
$(top_srcdir)/examples/rpcalc/rpcalc.stamp: $(doc) $(extexi)
|
||||||
|
$(AM_V_GEN)rm -f $@ $@.tmp
|
||||||
|
$(AM_V_at)touch $@.tmp
|
||||||
|
$(AM_V_at)cd $(top_srcdir)/examples/rpcalc && \
|
||||||
|
$(AWK) -f ../extexi -v VERSION="$(VERSION)" \
|
||||||
|
../../doc/bison.texinfo -- calc.h rpcalc.y
|
||||||
|
$(AM_V_at)mv $@.tmp $@
|
||||||
|
|
||||||
|
$(rpcalc_extracted): $(top_srcdir)/examples/rpcalc/rpcalc.stamp
|
||||||
|
$(AM_V_GEN)if test -f $@; then :; else \
|
||||||
|
rm -f $< && \
|
||||||
|
$(MAKE) $(AM_MAKEFLAGS) $<; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
## -------------------- ##
|
||||||
|
## Building & testing. ##
|
||||||
|
## -------------------- ##
|
||||||
|
|
||||||
|
BUILT_SOURCES += $(rpcalc_sources)
|
||||||
|
MAINTAINERCLEANFILES += $(top_srcdir)/examples/rpcalc/rpcalc.stamp $(rpcalc_sources)
|
||||||
|
EXTRA_DIST += examples/rpcalc/rpcalc.stamp
|
||||||
|
|
||||||
|
rpcalc_extracted = \
|
||||||
|
examples/rpcalc/rpcalc.y
|
||||||
|
rpcalc_sources = \
|
||||||
|
$(rpcalc_extracted)
|
||||||
|
|
||||||
|
check_PROGRAMS += examples/rpcalc/rpcalc
|
||||||
|
examples_rpcalc_rpcalc_LDADD = -lm
|
||||||
|
examples_rpcalc_rpcalc_SOURCES = \
|
||||||
|
$(rpcalc_sources)
|
||||||
|
|
||||||
|
examples_rpcalc_rpcalc_CPPFLAGS = -I$(top_srcdir)/examples/rpcalc
|
||||||
|
TESTS += examples/rpcalc/rpcalc.test
|
||||||
|
EXTRA_DIST += examples/rpcalc/rpcalc.test
|
||||||
46
examples/rpcalc/rpcalc.test
Executable file
46
examples/rpcalc/rpcalc.test
Executable file
@@ -0,0 +1,46 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
# Copyright (C) 2005-2012 Free Software Foundation, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
1 2 3 * +
|
||||||
|
EOF
|
||||||
|
run 0 7
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
1.1 2.2 3.3 * +
|
||||||
|
EOF
|
||||||
|
run 0 8.36
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
1 2 + 3 *
|
||||||
|
EOF
|
||||||
|
run 0 9
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
1 2 3 4 5 6 7 8 9 * * * * * * * *
|
||||||
|
EOF
|
||||||
|
run 0 362880
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
3 7 + 3 4 5 * + - n
|
||||||
|
EOF
|
||||||
|
run 0 13
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
3 4 ^
|
||||||
|
EOF
|
||||||
|
run 0 81
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
set -x
|
|
||||||
# Copyright (C) 2005-2012 Free Software Foundation, Inc.
|
# Copyright (C) 2005-2012 Free Software Foundation, Inc.
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
|||||||
Reference in New Issue
Block a user