[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
To allow hex and oct %token values
From: |
Odd Arild Olsen |
Subject: |
To allow hex and oct %token values |
Date: |
Wed, 3 Mar 2004 10:40:53 +0100 |
User-agent: |
KMail/1.5.1 |
I use Bison to generate parsers for tokens generated by real time events and
find it handy to specify token values by hexadecimal numbers. So I changed
two lines in scan-gram.l
I can now run this through Bison:
/* Reverse polish notation calculator. */
%defines
%{
#define YYSTYPE double
#include <math.h>
int yylex (void);
void yyerror (char const *);
%}
%token NUM10 200
%token NUM16 0x200
%token NUM8 0200
%% /* Grammar rules and actions follow. */
input: /* empty */
| input line
;
line: '\n'
| exp '\n' { printf ("\t%.10g\n", $1); }
;
exp: NUM10 { $$ = $1; }
| exp exp '+' { $$ = $1 + $2; }
| exp exp '-' { $$ = $1 - $2; }
| exp exp '*' { $$ = $1 * $2; }
| exp exp '/' { $$ = $1 / $2; }
/* Exponentiation */
| exp exp '^' { $$ = pow ($1, $2); }
/* Unary minus */
| exp 'n' { $$ = -$1; }
;
%%
Index: scan-gram.l
===================================================================
RCS file: /cvsroot/bison/bison/src/scan-gram.l,v
retrieving revision 1.66
diff -c -r1.66 scan-gram.l
*** scan-gram.l 7 Oct 2003 07:32:57 -0000 1.66
--- scan-gram.l 3 Mar 2004 09:30:15 -0000
***************
*** 114,120 ****
letter [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
id {letter}({letter}|[0-9])*
directive %{letter}({letter}|[0-9]|-)*
! int [0-9]+
/* POSIX says that a tag must be both an id and a C union member, but
historically almost any character is allowed in a tag. We disallow
--- 114,120 ----
letter [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
id {letter}({letter}|[0-9])*
directive %{letter}({letter}|[0-9]|-)*
! int (0x)?[0-9]+
/* POSIX says that a tag must be both an id and a C union member, but
historically almost any character is allowed in a tag. We disallow
***************
*** 237,243 ****
{int} {
unsigned long num;
set_errno (0);
! num = strtoul (yytext, 0, 10);
if (INT_MAX < num || get_errno ())
{
complain_at (*loc, _("integer out of range: %s"), quote (yytext));
--- 237,243 ----
{int} {
unsigned long num;
set_errno (0);
! num = strtoul (yytext, 0, 0);
if (INT_MAX < num || get_errno ())
{
complain_at (*loc, _("integer out of range: %s"), quote (yytext));
--
Odd Arild Olsen
- To allow hex and oct %token values,
Odd Arild Olsen <=