# Location type.
m4_define_default([b4_location_type], [yyltype])
+
+## ------------------------ ##
+## Pure/impure interfaces. ##
+## ------------------------ ##
+
+
+# b4_Pure_if(IF-TRUE, IF-FALSE)
+# -----------------------------
+# Expand IF-TRUE, if %pure-parser and %parse-param, IF-FALSE otherwise.
+m4_define([b4_Pure_if],
+[b4_pure_if([m4_ifset([b4_parse_param],
+ [$1], [$2])],
+ [$2])])
+
+
+# b4_pure_args
+# ------------
+# Arguments passed to yyerror: user args plus yylloc.
+m4_define([b4_pure_args],
+[b4_Pure_if([b4_location_if([, &yylloc])])[]b4_user_args])
+
+
+# b4_lex_param
+# ------------
# Accumule in b4_lex_param all the yylex arguments.
-# Yes, this is quite ugly...
+# b4_lex_param arrives quoted twice, but we want to keep only one level.
m4_define([b4_lex_param],
m4_dquote(b4_pure_if([[[[YYSTYPE *]], [[&yylval]]][]dnl
b4_location_if([, [[YYLTYPE *], [&yylloc]]])])dnl
m4_ifdef([b4_lex_param], [, ]b4_lex_param)))
+
+## ------------ ##
+## Data Types. ##
+## ------------ ##
+
+# b4_int_type(MIN, MAX)
+# ---------------------
+# Return the smallest int type able to handle numbers ranging from
+# MIN to MAX (included). We overwrite the version from c.m4 which relies
+# on "signed char" which is not portable to old K&R compilers.
+m4_define([b4_int_type],
+[m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char],
+ b4_ints_in($@, [-128], [127]), [1], [yysigned_char],
+
+ b4_ints_in($@, [0], [65535]), [1], [unsigned short],
+ b4_ints_in($@, [-32768], [32767]), [1], [short],
+
+ m4_eval([0 <= $1]), [1], [unsigned int],
+
+ [int])])
+
+
## ----------------- ##
## Semantic Values. ##
## ----------------- ##
])
-
+# We do want M4 expansion after # for CPP macros.
+m4_changecom()
m4_divert(0)dnl
#output "b4_output_parser_name"
b4_copyright([Skeleton parser for Yacc-like parsing with Bison],
define necessary library symbols; they are noted "INFRINGES ON
USER NAME SPACE" below. */
-/* Identify Bison output. */
-#define YYBISON 1
-
-/* Pure parsers. */
-#define YYPURE b4_pure
-
-/* Using locations. */
-#define YYLSP_NEEDED b4_locations_flag
-
+b4_identification
m4_if(b4_prefix[], [yy], [],
[/* If NAME_PREFIX is specified substitute the variables and functions
names. */
} \
else \
{ \
- yyerror ("syntax error: cannot back up"); \
+ yyerror ("syntax error: cannot back up"b4_pure_args); \
YYERROR; \
} \
while (0)
| Print this symbol on YYOUT. |
`-----------------------------*/
-b4_c_function([yysymprint],
- [static void],
- [[FILE*], [yyout]],
- [[int], [yytype]],
- [[YYSTYPE], [yyvalue]]b4_location_if([,
- [[YYLTYPE], [yylocation]]]))
+b4_c_function_def([yysymprint],
+ [static void],
+ [[FILE *yyout], [yyout]],
+ [[int yytype], [yytype]],
+ [[YYSTYPE yyvalue], [yyvalue]]b4_location_if([,
+ [[YYLTYPE yylocation], [yylocation]]]))
{
/* Pacify ``unused variable'' warnings. */
(void) yyvalue;
| Release the memory associated to this symbol. |
`-----------------------------------------------*/
-b4_c_function([yydestruct],
- [static void],
- [[int], [yytype]],
- [[YYSTYPE], [yyvalue]]b4_location_if([,
- [[YYLTYPE], [yylocation]]]))
+b4_c_function_def([yydestruct],
+ [static void],
+ [[int yytype], [yytype]],
+ [[YYSTYPE yyvalue], [yyvalue]]b4_location_if([,
+ [[YYLTYPE yylocation], [yylocation]]]))
{
/* Pacify ``unused variable'' warnings. */
(void) yyvalue;
\f
-/* The user can define YYPARSE_PARAM as the name of an argument to be passed
- into yyparse. The argument should have type void *.
- It should actually point to an object.
- Grammar actions can access the variable by casting it
- to the proper pointer type. */
+/* Prevent warnings from -Wmissing-prototypes. */
#ifdef YYPARSE_PARAM
# if defined (__STDC__) || defined (__cplusplus)
-# define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
-# define YYPARSE_PARAM_DECL
+int yyparse (void *YYPARSE_PARAM);
# else
-# define YYPARSE_PARAM_ARG YYPARSE_PARAM
-# define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
-# endif
-#else /* !YYPARSE_PARAM */
-# define YYPARSE_PARAM_ARG
-# define YYPARSE_PARAM_DECL
-#endif /* !YYPARSE_PARAM */
-
-/* Prevent warning if -Wstrict-prototypes. */
-#ifdef __GNUC__
-# ifdef YYPARSE_PARAM
-int yyparse (void *);
-# else
-int yyparse (void);
+int yyparse ();
# endif
+#else /* ! YYPARSE_PARAM */
+b4_c_function_decl([yyparse], [int], b4_parse_param)
#endif
+
m4_divert_push([KILL])# ======================== M4 code.
# b4_declare_parser_variables
# ---------------------------
# Declare the variables that are global, or local to YYPARSE if
-# pure-parser
+# pure-parser.
m4_define([b4_declare_parser_variables],
[/* The lookahead symbol. */
int yychar;
b4_pure_if([],
[b4_declare_parser_variables])
-int
-yyparse (YYPARSE_PARAM_ARG)
- YYPARSE_PARAM_DECL
+
+/*----------.
+| yyparse. |
+`----------*/
+
+#ifdef YYPARSE_PARAM
+# if defined (__STDC__) || defined (__cplusplus)
+int yyparse (void *YYPARSE_PARAM)
+# else
+int yyparse (YYPARSE_PARAM)
+ void *YYPARSE_PARAM;
+# endif
+#else /* ! YYPARSE_PARAM */
+b4_c_function_def([yyparse], [int], b4_parse_param)
+#endif
{[
]b4_pure_if([b4_declare_parser_variables])[
register int yystate;
yycount++;
}
}
- yyerror (yymsg);
+ yyerror (yymsg]b4_pure_args[);
YYSTACK_FREE (yymsg);
}
else
- yyerror ("parse error; also virtual memory exhausted");
+ yyerror ("parse error; also virtual memory exhausted"]b4_pure_args[);
}
else
#endif /* YYERROR_VERBOSE */
- yyerror ("parse error");
+ yyerror ("parse error"]b4_pure_args[);
}
goto yyerrlab1;
| yyoverflowlab -- parser overflow comes here. |
`----------------------------------------------*/
yyoverflowlab:
- yyerror ("parser stack overflow");
+ yyerror ("parser stack overflow"]b4_pure_args[);
yyresult = 2;
/* Fall through. */
#endif