[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
03-foo-params.patch
From: |
Akim Demaille |
Subject: |
03-foo-params.patch |
Date: |
Mon, 21 Oct 2002 09:23:26 +0200 |
Index: ChangeLog
from Akim Demaille <address@hidden>
Prototype support of %lex-param and %parse-param.
* src/parse-gram.y: Add the definition of the %lex-param and
%parse-param tokens, plus their rules.
Drop the `_' version of %glr-parser.
Add the "," token.
* src/scan-gram.l (INITIAL): Scan them.
* src/muscle_tab.c: Comment changes.
(muscle_insert, muscle_find): Rename `pair' as `probe'.
* src/muscle_tab.h (MUSCLE_INSERT_PREFIX): Remove unused.
(muscle_entry_s): The `value' member is no longer const.
Adjust all dependencies.
* src/muscle_tab.c (muscle_init): Adjust: use
MUSCLE_INSERT_STRING.
Initialize the obstack earlier.
* src/muscle_tab.h, src/muscle_tab.c (muscle_grow)
(muscle_pair_list_grow): New.
* data/c.m4 (b4_c_function_call, b4_c_args): New.
* data/yacc.c (YYLEX): Use b4_c_function_call to honor %lex-param.
* tests/calc.at: Use %locations, not --locations.
(AT_CHECK_CALC_GLR): Use %glr-parser, not %glr_parser.
Index: TODO
--- TODO Sun, 13 Oct 2002 21:20:02 +0200 akim
+++ TODO Sat, 19 Oct 2002 14:23:43 +0200 akim
@@ -5,6 +5,18 @@
From Franc,ois: should we keep the directory part in the CPP guard?
+* readpipe
+
+It should be replaced to avoid tmp files and to improve portability.
+Also, as it is it does not call error () when execve fails, and
+therefore, running M4='m4 --version' bison will silently fail instead
+of:
+
+ bison: cannot run m4 --version: No such file or directory
+
+BTW: I would really like to be able to pass arguments to m4...
+
+
* URGENT: Documenting C++ output
Write a first documentation for C++ output.
Index: src/muscle_tab.c
--- src/muscle_tab.c Fri, 14 Jun 2002 18:30:31 +0200 akim
+++ src/muscle_tab.c Sat, 19 Oct 2002 15:10:21 +0200 akim
@@ -1,4 +1,4 @@
-/* Macro table manager for Bison,
+/* Muscle table manager for Bison,
Copyright (C) 2001, 2002 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -56,31 +56,31 @@
void
muscle_init (void)
{
+ /* Initialize the muscle obstack. */
+ obstack_init (&muscle_obstack);
+
muscle_table = hash_initialize (HT_INITIAL_CAPACITY, NULL, hash_muscle,
hash_compare_muscles, free);
/* Version and input file. */
- muscle_insert ("version", VERSION);
- muscle_insert ("filename", infile);
+ MUSCLE_INSERT_STRING ("version", VERSION);
+ MUSCLE_INSERT_STRING ("filename", infile);
/* FIXME: there should probably be no default here, only in the
skeletons. */
/* Types. */
- muscle_insert ("ltype", "yyltype");
+ MUSCLE_INSERT_STRING ("ltype", "yyltype");
/* Default #line formatting. */
- muscle_insert ("linef", "#line %d %s\n");
+ MUSCLE_INSERT_STRING ("linef", "#line %d %s\n");
/* Stack parameters. */
- muscle_insert ("maxdepth", "10000");
- muscle_insert ("initdepth", "200");
+ MUSCLE_INSERT_STRING ("maxdepth", "10000");
+ MUSCLE_INSERT_STRING ("initdepth", "200");
/* C++ macros. */
- muscle_insert ("name", "Parser");
-
- /* Initialize the muscle obstack. */
- obstack_init (&muscle_obstack);
+ MUSCLE_INSERT_STRING ("name", "Parser");
}
@@ -97,14 +97,19 @@
+/*------------------------------------------------------------.
+| Insert (KEY, VALUE). If KEY already existed, overwrite the |
+| previous value. |
+`------------------------------------------------------------*/
+
void
-muscle_insert (const char *key, const char *value)
+muscle_insert (const char *key, char *value)
{
- muscle_entry_t pair;
+ muscle_entry_t probe;
muscle_entry_t *entry = NULL;
- pair.key = key;
- entry = hash_lookup (muscle_table, &pair);
+ probe.key = key;
+ entry = hash_lookup (muscle_table, &probe);
if (!entry)
{
@@ -116,32 +121,99 @@
entry->value = value;
}
-const char*
+
+/*-------------------------------------------------------------------.
+| Insert (KEY, VALUE). If KEY already existed, overwrite the |
+| previous value. Uses MUSCLE_OBSTACK. De-allocates the previously |
+| associated value. VALUE and SEPARATOR are copied. |
+`-------------------------------------------------------------------*/
+
+void
+muscle_grow (const char *key, const char *val, const char *separator)
+{
+ muscle_entry_t probe;
+ muscle_entry_t *entry = NULL;
+
+ probe.key = key;
+ entry = hash_lookup (muscle_table, &probe);
+
+ if (!entry)
+ {
+ /* First insertion in the hash. */
+ entry = XMALLOC (muscle_entry_t, 1);
+ entry->key = key;
+ hash_insert (muscle_table, entry);
+ entry->value = xstrdup (val);
+ }
+ else
+ {
+ /* Grow the current value. */
+ char *new_val;
+ fprintf (stderr, "<= %s + %s\n", entry->value, val);
+ obstack_sgrow (&muscle_obstack, entry->value);
+ free (entry->value);
+ obstack_sgrow (&muscle_obstack, separator);
+ obstack_sgrow (&muscle_obstack, val);
+ obstack_1grow (&muscle_obstack, 0);
+ new_val = obstack_finish (&muscle_obstack);
+ entry->value = xstrdup (new_val);
+ fprintf (stderr, "=> %s\n", new_val);
+ obstack_free (&muscle_obstack, new_val);
+ }
+}
+
+
+/*-------------------------------------------------------------------.
+| MUSCLE is an M4 list of pairs. Create or extend it with the pair |
+| (A1, A2). Note that because the muscle values are output *double* |
+| quoted, one needs to strip the first level of quotes to reach the |
+| list itself. |
+`-------------------------------------------------------------------*/
+
+void muscle_pair_list_grow (const char *muscle,
+ const char *a1, const char *a2)
+{
+ char *value;
+ obstack_fgrow2 (&muscle_obstack, "[[[%s]], [[%s]]]", a1, a2);
+ obstack_1grow (&muscle_obstack, 0);
+ value = obstack_finish (&muscle_obstack);
+ muscle_grow (muscle, value, ",\n");
+ obstack_free (&muscle_obstack, value);
+}
+
+/*-------------------------------.
+| Find the value of muscle KEY. |
+`-------------------------------*/
+
+char*
muscle_find (const char *key)
{
- muscle_entry_t pair;
+ muscle_entry_t probe;
muscle_entry_t *result = NULL;
- pair.key = key;
- result = hash_lookup (muscle_table, &pair);
+ probe.key = key;
+ result = hash_lookup (muscle_table, &probe);
return result ? result->value : NULL;
}
-/* Output the definition of all the current muscles into a list of
- m4_defines. */
+/*------------------------------------------------.
+| Output the definition of ENTRY as a m4_define. |
+`------------------------------------------------*/
static int
muscle_m4_output (muscle_entry_t *entry, FILE *out)
{
fprintf (out, "m4_define([b4_%s],\n", entry->key);
- fprintf (out, " [[%s]])\n\n\n", entry->value);
+ fprintf (out, "[[%s]])\n\n\n", entry->value);
return 1;
}
-/* Output the definition of all the current muscles into a list of
- m4_defines. */
+/*----------------------------------------------------------------.
+| Output the definition of all the current muscles into a list of |
+| m4_defines. |
+`----------------------------------------------------------------*/
void
muscles_m4_output (FILE *out)
Index: src/muscle_tab.h
--- src/muscle_tab.h Fri, 14 Jun 2002 18:30:31 +0200 akim
+++ src/muscle_tab.h Sat, 19 Oct 2002 15:10:09 +0200 akim
@@ -1,4 +1,4 @@
-/* Definitions for macrotab.c and callers, part of bison,
+/* Muscle table manager for Bison,
Copyright (C) 2001, 2002 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -21,17 +21,15 @@
#ifndef MUSCLE_TAB_H_
# define MUSCLE_TAB_H
-# define MTABSIZE 101
-
typedef struct muscle_entry_s
{
const char *key;
- const char *value;
+ char *value;
} muscle_entry_t;
void muscle_init PARAMS ((void));
-void muscle_insert PARAMS ((const char *key, const char *value));
-const char *muscle_find PARAMS ((const char *key));
+void muscle_insert PARAMS ((const char *key, char *value));
+char *muscle_find PARAMS ((const char *key));
void muscle_free PARAMS ((void));
@@ -59,14 +57,27 @@
muscle_insert (Key, obstack_finish (&muscle_obstack)); \
}
-#define MUSCLE_INSERT_PREFIX(Key, Value) \
-{ \
- obstack_fgrow2 (&muscle_obstack, "%s%s", \
- spec_name_prefix ? spec_name_prefix : "yy", Value); \
- obstack_1grow (&muscle_obstack, 0); \
- muscle_insert (Key, obstack_finish (&muscle_obstack)); \
+#define MUSCLE_GROW_STRING_PAIR(Key, Value1, Value2) \
+{ \
+ obstack_sgrow (&muscle_obstack, Value1); \
+ obstack_1grow (&muscle_obstack, 0); \
+ muscle_insert (Key, obstack_finish (&muscle_obstack)); \
}
+/* Insert (KEY, VALUE). If KEY already existed, overwrite the
+ previous value. Uses MUSCLE_OBSTACK. De-allocates the previously
+ associated value. VALUE and SEPARATOR are copied. */
+
+void muscle_grow PARAMS ((const char *key,
+ const char *value, const char *separator));
+
+/* MUSCLE is an M4 list of pairs. Create or extend it with the pair
+ (A1, A2). Note that because the muscle values are output *double*
+ quoted, one needs to strip the first level of quotes to reach the
+ list itself. */
+
+void muscle_pair_list_grow PARAMS ((const char *muscle,
+ const char *a1, const char *a2));
void muscles_m4_output PARAMS ((FILE *out));
Index: src/output.c
--- src/output.c Sun, 13 Oct 2002 19:57:05 +0200 akim
+++ src/output.c Fri, 18 Oct 2002 12:35:37 +0200 akim
@@ -355,9 +355,9 @@
fputs ("]])\n\n", out);
}
-/*---------------------------------------.
-| Output the tokens definition to OOUT. |
-`---------------------------------------*/
+/*--------------------------------------.
+| Output the tokens definition to OUT. |
+`--------------------------------------*/
static void
token_definitions_output (FILE *out)
@@ -405,9 +405,9 @@
}
-/*----------------------------------------.
-| Output the symbol destructors to OOUT. |
-`----------------------------------------*/
+/*---------------------------------------.
+| Output the symbol destructors to OUT. |
+`---------------------------------------*/
static void
symbol_destructors_output (FILE *out)
@@ -438,9 +438,9 @@
}
-/*-------------------------------------.
-| Output the symbol printers to OOUT. |
-`-------------------------------------*/
+/*------------------------------------.
+| Output the symbol printers to OUT. |
+`------------------------------------*/
static void
symbol_printers_output (FILE *out)
@@ -456,7 +456,7 @@
/* Filename, lineno,
Symbol-name, Symbol-number,
- destructor, typename. */
+ printer, typename. */
fprintf (out, "%s[[[%s]], [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
first ? "" : ",\n",
infile, symbol->printer_location.first_line,
Index: src/parse-gram.y
--- src/parse-gram.y Fri, 27 Sep 2002 20:10:16 +0200 akim
+++ src/parse-gram.y Sat, 19 Oct 2002 15:09:02 +0200 akim
@@ -113,36 +113,42 @@
%token PERCENT_RIGHT "%right"
%token PERCENT_NONASSOC "%nonassoc"
-%token PERCENT_EXPECT "%expect"
-%token PERCENT_START "%start"
%token PERCENT_PREC "%prec"
%token PERCENT_DPREC "%dprec"
%token PERCENT_MERGE "%merge"
-%token PERCENT_VERBOSE "%verbose"
-%token PERCENT_ERROR_VERBOSE "%error-verbose"
-%token PERCENT_OUTPUT "%output"
-%token PERCENT_FILE_PREFIX "%file-prefix"
-%token PERCENT_NAME_PREFIX "%name-prefix"
-
-%token PERCENT_DEFINE "%define"
-%token PERCENT_PURE_PARSER "%pure-parser"
-%token PERCENT_GLR_PARSER "%glr-parser"
-
-%token PERCENT_DEFINES "%defines"
-
-%token PERCENT_YACC "%yacc"
-
-%token PERCENT_DEBUG "%debug"
-%token PERCENT_LOCATIONS "%locations"
-%token PERCENT_NO_LINES "%no-lines"
-%token PERCENT_SKELETON "%skeleton"
-%token PERCENT_TOKEN_TABLE "%token-table"
+
+/*----------------------.
+| Global Declarations. |
+`----------------------*/
+
+%token
+ PERCENT_DEBUG "%debug"
+ PERCENT_DEFINE "%define"
+ PERCENT_DEFINES "%defines"
+ PERCENT_ERROR_VERBOSE "%error-verbose"
+ PERCENT_EXPECT "%expect"
+ PERCENT_FILE_PREFIX "%file-prefix"
+ PERCENT_GLR_PARSER "%glr-parser"
+ PERCENT_LEX_PARAM "%lex-param"
+ PERCENT_LOCATIONS "%locations"
+ PERCENT_NAME_PREFIX "%name-prefix"
+ PERCENT_NO_LINES "%no-lines"
+ PERCENT_OUTPUT "%output"
+ PERCENT_PARSE_PARAM "%parse-param"
+ PERCENT_PURE_PARSER "%pure-parser"
+ PERCENT_SKELETON "%skeleton"
+ PERCENT_START "%start"
+ PERCENT_TOKEN_TABLE "%token-table"
+ PERCENT_VERBOSE "%verbose"
+ PERCENT_YACC "%yacc"
+;
%token TYPE "type"
%token EQUAL "="
%token SEMICOLON ";"
%token COLON ":"
+%token COMMA ","
%token PIPE "|"
%token ID "identifier"
%token PERCENT_PERCENT "%%"
@@ -186,12 +192,16 @@ declaration:
| "%error-verbose" { error_verbose = 1; }
| "%expect" INT { expected_conflicts = $2; }
| "%file-prefix" "=" string_content { spec_file_prefix = $3; }
+| "%glr-parser" { glr_parser = 1; }
+| "%lex-param" string_content "," string_content
+ { muscle_pair_list_grow ("lex_param", $2, $4); }
| "%locations" { locations_flag = 1; }
| "%name-prefix" "=" string_content { spec_name_prefix = $3; }
| "%no-lines" { no_lines_flag = 1; }
| "%output" "=" string_content { spec_outfile = $3; }
+| "%parse-param" string_content "," string_content
+ { muscle_pair_list_grow ("parse_param", $2, $4); }
| "%pure-parser" { pure_parser = 1; }
-| "%glr-parser" { glr_parser = 1; }
| "%skeleton" string_content { skeleton = $2; }
| "%token-table" { token_table_flag = 1; }
| "%verbose" { report_flag = 1; }
Index: src/scan-gram.l
--- src/scan-gram.l Thu, 17 Oct 2002 09:33:17 +0200 akim
+++ src/scan-gram.l Fri, 18 Oct 2002 08:21:31 +0200 akim
@@ -126,7 +126,7 @@
"%expect" return PERCENT_EXPECT;
"%file-prefix" return PERCENT_FILE_PREFIX;
"%fixed"[-_]"output"[-_]"files" return PERCENT_YACC;
- "%glr"[-_]"parser" return PERCENT_GLR_PARSER;
+ "%glr-parser" return PERCENT_GLR_PARSER;
"%left" return PERCENT_LEFT;
"%locations" return PERCENT_LOCATIONS;
"%merge" return PERCENT_MERGE;
@@ -135,10 +135,12 @@
"%nonassoc" return PERCENT_NONASSOC;
"%nterm" return PERCENT_NTERM;
"%output" return PERCENT_OUTPUT;
+ "%parse-param" return PERCENT_PARSE_PARAM;
"%prec" { rule_length--; return PERCENT_PREC; }
"%printer" return PERCENT_PRINTER;
"%pure"[-_]"parser" return PERCENT_PURE_PARSER;
"%right" return PERCENT_RIGHT;
+ "%lex-param" return PERCENT_LEX_PARAM;
"%skeleton" return PERCENT_SKELETON;
"%start" return PERCENT_START;
"%term" return PERCENT_TOKEN;
@@ -152,6 +154,7 @@
"=" return EQUAL;
":" { rule_length = 0; return COLON; }
"|" { rule_length = 0; return PIPE; }
+ "," return COMMA;
";" return SEMICOLON;
{eols} YY_LINES; YY_STEP;
Index: data/yacc.c
--- data/yacc.c Sun, 13 Oct 2002 16:03:02 +0200 akim
+++ data/yacc.c Sat, 19 Oct 2002 15:03:38 +0200 akim
@@ -500,13 +500,14 @@ m4_define([b4_symbol_actions],
/* YYLEX -- calling `yylex' with the right arguments. */
-b4_pure_if(
-[#ifdef YYLEX_PARAM
-# define YYLEX yylex (&yylval[]b4_location_if([, &yylloc]), YYLEX_PARAM)
+#ifdef YYLEX_PARAM
+# define YYLEX yylex (b4_pure_if([&yylval[]b4_location_if([, &yylloc]),
])YYLEX_PARAM)
#else
-# define YYLEX yylex (&yylval[]b4_location_if([, &yylloc]))
-#endif],
-[#define YYLEX yylex ()])
+# define YYLEX b4_c_function_call([yylex],
+ b4_pure_if([[[[]], [[&yylval]]],
+ b4_location_if([[[], [&yylloc]],])])
+ m4_fst(b4_lex_param))
+#endif
/* Enable debugging if requested. */
#if YYDEBUG
Index: data/c.m4
--- data/c.m4 Sun, 13 Oct 2002 10:01:29 +0200 akim
+++ data/c.m4 Sat, 19 Oct 2002 14:44:24 +0200 akim
@@ -1,4 +1,4 @@
-m4_divert(-1) -*- C -*-
+m4_divert(-1) *- Autoconf -*-
# C M4 Macros for Bison.
# Copyright (C) 2002 Free Software Foundation, Inc.
@@ -121,13 +121,36 @@ m4_define([b4_token_defines],
])
+## --------------------- ##
+## Calling C functions. ##
+## --------------------- ##
+
+
+# b4_c_function_call(NAME, RETURN-VALUE, [TYPE1, NAME1], ...)
+# -----------------------------------------------------------
+# Call the function NAME with arguments NAME1, NAME2 etc.
+m4_define([b4_c_function_call],
+[$1 (b4_c_args(m4_shiftn(2, $@)))[]dnl
+])
+
+
+# b4_c_args([TYPE1, NAME1], ...)
+# ------------------------------
+# Output the arguments NAME1, NAME2...
+m4_define([b4_c_args],
+[m4_map_sep([b4_c_arg], [, ], address@hidden)])
+
+m4_define([b4_c_arg],
+[$2])
+
+
## ---------------------------------------------- ##
## Declaring C functions in both K&R and ANSI-C. ##
## ---------------------------------------------- ##
# b4_c_function(NAME, RETURN-VALUE, [TYPE1, NAME1], ...)
-# ------------------------------------------------
+# ------------------------------------------------------
# Declare the function NAME.
m4_define([b4_c_function],
[$2
Index: tests/calc.at
--- tests/calc.at Sun, 13 Oct 2002 16:16:48 +0200 akim
+++ tests/calc.at Sat, 19 Oct 2002 15:21:40 +0200 akim
@@ -352,7 +352,7 @@ m4_define([_AT_CHECK_CALC_ERROR],
[$4
])
# 3. If locations are not used, remove them.
-m4_bmatch([$1], [--location], [],
+m4_bmatch([$1], [%locations], [],
[[sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout]])
# 4. If error-verbose is not used, strip the`, unexpected....' part.
@@ -449,18 +449,18 @@ m4_define([AT_CHECK_CALC_LALR],
AT_CHECK_CALC_LALR()
AT_CHECK_CALC_LALR([--defines])
-AT_CHECK_CALC_LALR([--locations])
+AT_CHECK_CALC_LALR([%locations])
AT_CHECK_CALC_LALR([--name-prefix=calc])
AT_CHECK_CALC_LALR([--verbose])
AT_CHECK_CALC_LALR([--yacc])
AT_CHECK_CALC_LALR([%error-verbose])
-AT_CHECK_CALC_LALR([%error-verbose --locations])
+AT_CHECK_CALC_LALR([%error-verbose %locations])
-AT_CHECK_CALC_LALR([%error-verbose --defines --locations --name-prefix=calc
--verbose --yacc])
+AT_CHECK_CALC_LALR([%error-verbose --defines %locations --name-prefix=calc
--verbose --yacc])
AT_CHECK_CALC_LALR([%debug])
-AT_CHECK_CALC_LALR([%error-verbose %debug --defines --locations
--name-prefix=calc --verbose --yacc])
+AT_CHECK_CALC_LALR([%error-verbose %debug --defines %locations
--name-prefix=calc --verbose --yacc])
# ----------------------- #
@@ -474,21 +474,21 @@ m4_define([AT_CHECK_CALC_LALR],
# Start a testing chunk which compiles `calc' grammar with
# BISON-OPTIONS and %glr-parser, and performs several tests over the parser.
m4_define([AT_CHECK_CALC_GLR],
-[AT_CHECK_CALC([%glr_parser] $@)])
+[AT_CHECK_CALC([%glr-parser] $@)])
AT_CHECK_CALC_GLR()
AT_CHECK_CALC_GLR([--defines])
-AT_CHECK_CALC_GLR([--locations])
+AT_CHECK_CALC_GLR([%locations])
AT_CHECK_CALC_GLR([--name-prefix=calc])
AT_CHECK_CALC_GLR([--verbose])
AT_CHECK_CALC_GLR([--yacc])
AT_CHECK_CALC_GLR([%error-verbose])
-AT_CHECK_CALC_GLR([%error-verbose --locations])
+AT_CHECK_CALC_GLR([%error-verbose %locations])
-AT_CHECK_CALC_GLR([%error-verbose --defines --locations --name-prefix=calc
--verbose --yacc])
+AT_CHECK_CALC_GLR([%error-verbose --defines %locations --name-prefix=calc
--verbose --yacc])
AT_CHECK_CALC_GLR([%debug])
-AT_CHECK_CALC_GLR([%error-verbose %debug --defines --locations
--name-prefix=calc --verbose --yacc])
+AT_CHECK_CALC_GLR([%error-verbose %debug --defines %locations
--name-prefix=calc --verbose --yacc])
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- 03-foo-params.patch,
Akim Demaille <=