* doc/bison.texinfo (Multi-function Calc): Add missing includes.
Fix the rendering of the result: use @result and remove the
initial tabulation in the actual code.
Fix stylistic issues: avoid the , operator.
Add extexi mark-up.
* examples/extexi: Also support @smallexample.
@example
$ @kbd{mfcalc}
@kbd{pi = 3.141592653589}
@example
$ @kbd{mfcalc}
@kbd{pi = 3.141592653589}
@kbd{alpha = beta1 = 2.3}
@kbd{alpha = beta1 = 2.3}
Here are the C and Bison declarations for the multi-function calculator.
Here are the C and Bison declarations for the multi-function calculator.
- #include <math.h> /* For math functions, cos(), sin(), etc. */
- #include "calc.h" /* Contains definition of `symrec'. */
+ #include <stdio.h> /* For printf, etc. */
+ #include "calc.h" /* Contains definition of `symrec'. */
int yylex (void);
void yyerror (char const *);
%@}
int yylex (void);
void yyerror (char const *);
%@}
Most of them are copied directly from @code{calc}; three rules,
those which mention @code{VAR} or @code{FNCT}, are new.
Most of them are copied directly from @code{calc}; three rules,
those which mention @code{VAR} or @code{FNCT}, are new.
@smallexample
@group
input: /* empty */
@smallexample
@group
input: /* empty */
- | exp '\n' @{ printf ("\t%.10g\n", $1); @}
- | error '\n' @{ yyerrok; @}
+ | exp '\n' @{ printf ("%.10g\n", $1); @}
+ | error '\n' @{ yyerrok; @}
definition, which is kept in the header @file{calc.h}, is as follows. It
provides for either functions or variables to be placed in the table.
definition, which is kept in the header @file{calc.h}, is as follows. It
provides for either functions or variables to be placed in the table.
@smallexample
@group
/* Function type. */
@smallexample
@group
/* Function type. */
function that initializes the symbol table. Here it is, and
@code{init_table} as well:
function that initializes the symbol table. Here it is, and
@code{init_table} as well:
@smallexample
#include <stdio.h>
@smallexample
#include <stdio.h>
+#include <math.h> /* Math functions, cos(), sin(), etc. */
struct init const arith_fncts[] =
@{
struct init const arith_fncts[] =
@{
- "sin", sin,
- "cos", cos,
- "atan", atan,
- "ln", log,
- "exp", exp,
- "sqrt", sqrt,
- 0, 0
+ @{ "atan", atan @},
+ @{ "cos", cos @},
+ @{ "exp", exp @},
+ @{ "ln", log @},
+ @{ "sin", sin @},
+ @{ "sqrt", sqrt @},
+ @{ 0, 0 @},
@group
/* Put arithmetic functions in table. */
@group
/* Put arithmetic functions in table. */
void
init_table (void)
@{
void
init_table (void)
@{
The function @code{getsym} is passed the name of the symbol to look up. If
found, a pointer to that symbol is returned; otherwise zero is returned.
The function @code{getsym} is passed the name of the symbol to look up. If
found, a pointer to that symbol is returned; otherwise zero is returned.
+#include <stdlib.h> /* malloc. */
+#include <string.h> /* strlen. */
+
symrec *
putsym (char const *sym_name, int sym_type)
@{
symrec *
putsym (char const *sym_name, int sym_type)
@{
No change is needed in the handling of numeric values and arithmetic
operators in @code{yylex}.
No change is needed in the handling of numeric values and arithmetic
operators in @code{yylex}.
@smallexample
@group
#include <ctype.h>
@smallexample
@group
#include <ctype.h>
/* Initially make the buffer long enough
for a 40-character symbol name. */
if (length == 0)
/* Initially make the buffer long enough
for a 40-character symbol name. */
if (length == 0)
- length = 40, symbuf = (char *)malloc (length + 1);
+ @{
+ length = 40;
+ symbuf = (char *) malloc (length + 1);
+ @}
-/^@example$/, /^@end example$/ {
+/^@(small)?example$/, /^@end (small)?example$/ {
+ if ($0 ~ /^@(small)?example$/)
{
input = files_output[file] ? "\n" : "";
{
input = files_output[file] ? "\n" : "";
- if ($0 ~ /^@end example$/)
+ if ($0 ~ /^@end (small)?example$/)
{
if (input == "")
fatal("no contents: " file);
{
if (input == "")
fatal("no contents: " file);