[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bison-1_29-branch] Change location symbol.
From: |
Pascal Bart |
Subject: |
[bison-1_29-branch] Change location symbol. |
Date: |
Fri, 24 Aug 2001 00:46:29 +0000 (GMT) |
Hello,
here a patch to change the location symbol `@', Akim tell me if
it's interesting, please. I cann't remember his name, but a guy, who would
to use Bison with Perl, ask us to do it. FYI it works fine.
Index: ChangeLog
===================================================================
RCS file: /cvsroot/bison/bison/ChangeLog,v
retrieving revision 1.173.2.5
diff -u -u -r1.173.2.5 ChangeLog
--- ChangeLog 2001/08/21 07:30:36 1.173.2.5
+++ ChangeLog 2001/08/23 22:39:20
@@ -1,3 +1,13 @@
+2001-08-24 Pascal Bart <address@hidden>
+
+ * src/reader.c (read_declarations): Adjust to call parse_tok_locchar.
+ (parse_tok_locchar): Add.
+ (location_char): New global.
+ (copy_action): Adjust.
+ (copy_guard): Adjust.
+ * src/lex.c (percent_table): Add entry for `%locations_char'.
+ * src/lex.h (token_e): Add new token flag tok_locchar.
+
2001-08-20 Pascal Bart <address@hidden>
* tests/suite.at: Exercise %header_extension and %source_extension.
Index: src/lex.c
===================================================================
RCS file: /cvsroot/bison/bison/src/lex.c,v
retrieving revision 1.33
diff -u -u -r1.33 lex.c
--- src/lex.c 2001/08/14 11:28:48 1.33
+++ src/lex.c 2001/08/23 22:39:20
@@ -536,6 +536,7 @@
{ "binary", NULL, tok_nonassoc },
{ "prec", NULL, tok_prec },
{ "locations", &locations_flag, tok_noop }, /* -l */
+ { "locations_char", NULL, tok_locchar },
{ "no_lines", &no_lines_flag, tok_noop }, /* -l */
{ "raw", NULL, tok_obsolete }, /* -r */
{ "token_table", &token_table_flag, tok_noop }, /* -k */
Index: src/lex.h
===================================================================
RCS file: /cvsroot/bison/bison/src/lex.h,v
retrieving revision 1.13
diff -u -u -r1.13 lex.h
--- src/lex.h 2001/08/06 08:51:41 1.13
+++ src/lex.h 2001/08/23 22:39:20
@@ -49,6 +49,7 @@
tok_thong,
tok_hdrext,
tok_srcext,
+ tok_locchar,
tok_noop,
tok_setopt,
tok_illegal,
Index: src/reader.c
===================================================================
RCS file: /cvsroot/bison/bison/src/reader.c,v
retrieving revision 1.72.2.1
diff -u -u -r1.72.2.1 reader.c
--- src/reader.c 2001/08/16 20:48:02 1.72.2.1
+++ src/reader.c 2001/08/23 22:39:21
@@ -20,6 +20,12 @@
Boston, MA 02111-1307, USA. */
+#if defined(STDC_HEADERS) || defined(HAVE_CTYPE_H)
+# include <ctype.h>
+#else /* not STDC_HEADERS and not HAVE_CTYPE_H */
+int isprint ();
+#endif
+
#include "system.h"
#include "obstack.h"
#include "quotearg.h"
@@ -60,6 +66,9 @@
/* Nonzero if %union has been seen. */
static int typed;
+/* Inform about the location char. */
+static int location_char = '@';
+
/* Incremented for each %left, %right or %nonassoc seen */
static int lastprec;
@@ -942,6 +951,49 @@
src_extension = parse_dquoted_param ("%source_extension");
}
+/*------------------------------------------------------------------.
+| Read the new user char to signal a location in his code, default |
+| stay `@'. |
+`------------------------------------------------------------------*/
+
+static void
+parse_tok_locchar (void)
+{
+ int c;
+ int tmp;
+
+ if (location_char != '@')
+ complain (_("multiple %%location_char declarations"));
+
+ c = skip_white_space ();
+ if (c != '"')
+ {
+ ungetc (c, finput);
+ complain (_("invalid %s declaration"), "%location_char");
+ return;
+ }
+
+ c = getc (finput);
+ if (!isprint (c) || c == ' ')
+ {
+ char buf[] = "c";
+ buf[0] = c;
+ ungetc (c, finput);
+ complain (_("invalid char: %s"), quote (buf));
+ return;
+ }
+
+ tmp = c;
+ c = getc (finput);
+ if (c != '"')
+ {
+ ungetc (c, finput);
+ complain (_("invalid %s declaration"), "%location_char");
+ return;
+ }
+ location_char = tmp;
+}
+
/*----------------------------------------------------------------.
| Read from finput until `%%' is seen. Discard the `%%'. Handle |
| any `%' declarations, and copy the contents of any `%{ ... %}' |
@@ -1019,6 +1071,10 @@
parse_source_extension_decl ();
break;
+ case tok_locchar:
+ parse_tok_locchar ();
+ break;
+
case tok_noop:
break;
@@ -1101,16 +1157,15 @@
rule, stack_offset);
break;
- case '@':
- copy_at (finput, &action_obstack,
- stack_offset);
- break;
-
case EOF:
fatal (_("unmatched %s"), "`{'");
default:
- obstack_1grow (&action_obstack, c);
+ if (c == location_char)
+ copy_at (finput, &action_obstack,
+ stack_offset);
+ else
+ obstack_1grow (&action_obstack, c);
}
c = getc (finput);
@@ -1196,15 +1251,14 @@
copy_dollar (finput, &guard_obstack, rule, stack_offset);
break;
- case '@':
- copy_at (finput, &guard_obstack, stack_offset);
- break;
-
case EOF:
fatal ("%s", _("unterminated %guard clause"));
default:
- obstack_1grow (&guard_obstack, c);
+ if (c == location_char)
+ copy_at (finput, &guard_obstack, stack_offset);
+ else
+ obstack_1grow (&guard_obstack, c);
}
if (c != '}' || count != 0)
Pascal Bart (address@hidden)
- [bison-1_29-branch] Change location symbol.,
Pascal Bart <=