Support sized decimal numbers,
Fix operator precedence order.
This commit is contained in:
parent
51b4f70c8f
commit
bd40e5dfe1
37
lexor.lex
37
lexor.lex
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: lexor.lex,v 1.10 1999/03/15 02:43:32 steve Exp $"
|
||||
#ident "$Id: lexor.lex,v 1.11 1999/03/16 04:44:45 steve Exp $"
|
||||
#endif
|
||||
|
||||
//# define YYSTYPE lexval
|
||||
|
|
@ -41,6 +41,7 @@ static int check_identifier(const char*name);
|
|||
static void ppinclude_filename();
|
||||
static void ppdo_include();
|
||||
static verinum*make_sized_binary(const char*txt);
|
||||
static verinum*make_sized_dec(const char*txt);
|
||||
static verinum*make_sized_octal(const char*txt);
|
||||
static verinum*make_sized_hex(const char*txt);
|
||||
|
||||
|
|
@ -120,7 +121,7 @@ static verinum*make_sized_hex(const char*txt);
|
|||
yylval.text = new string(yytext);
|
||||
return SYSTEM_IDENTIFIER; }
|
||||
|
||||
[0-9][0-9_]*\'d[0-9][0-9_]* { yylval.number = 0;
|
||||
[0-9][0-9_]*\'d[0-9][0-9_]* { yylval.number = make_sized_dec(yytext);
|
||||
return NUMBER; }
|
||||
[0-9][0-9_]*\'[bB][0-1xz_]+ { yylval.number = make_sized_binary(yytext);
|
||||
return NUMBER; }
|
||||
|
|
@ -478,6 +479,38 @@ static verinum*make_sized_hex(const char*txt)
|
|||
return new verinum(bits, size);
|
||||
}
|
||||
|
||||
/*
|
||||
* Making a deciman number is much easier then the other base numbers
|
||||
* because there are no z or x values to worry about.
|
||||
*/
|
||||
static verinum*make_sized_dec(const char*txt)
|
||||
{
|
||||
char*ptr;
|
||||
unsigned size = strtoul(txt,&ptr,10);
|
||||
assert(*ptr == '\'');
|
||||
ptr += 1;
|
||||
assert(tolower(*ptr) == 'd');
|
||||
|
||||
unsigned long value = 0;
|
||||
for (ptr += 1 ; *ptr ; ptr += 1)
|
||||
if (isdigit(*ptr)) {
|
||||
value *= 10;
|
||||
value += *ptr - '0';
|
||||
} else {
|
||||
assert(*ptr == '_');
|
||||
}
|
||||
|
||||
|
||||
verinum::V*bits = new verinum::V[size];
|
||||
|
||||
for (unsigned idx = 0 ; idx < size ; idx += 1) {
|
||||
bits[idx] = (value&1)? verinum::V1 : verinum::V0;
|
||||
value /= 2;
|
||||
}
|
||||
|
||||
return new verinum(bits, size);
|
||||
}
|
||||
|
||||
struct include_stack_t {
|
||||
string path;
|
||||
FILE*file;
|
||||
|
|
|
|||
41
parse.y
41
parse.y
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: parse.y,v 1.15 1999/03/15 02:43:32 steve Exp $"
|
||||
#ident "$Id: parse.y,v 1.16 1999/03/16 04:44:45 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "parse_misc.h"
|
||||
|
|
@ -111,15 +111,15 @@ extern void lex_end_table();
|
|||
%type <statement> statement statement_opt
|
||||
%type <statement_list> statement_list
|
||||
|
||||
%left UNARY_PREC
|
||||
%left '+' '-'
|
||||
%left K_GE K_LE '<' '>'
|
||||
%left K_EQ K_NE K_CEQ K_CNE
|
||||
%left '&'
|
||||
%left '^'
|
||||
%left '|'
|
||||
%left K_LAND
|
||||
%left K_LOR
|
||||
%left K_LAND
|
||||
%left '|'
|
||||
%left '^'
|
||||
%left '&'
|
||||
%left K_EQ K_NE K_CEQ K_CNE
|
||||
%left K_GE K_LE '<' '>'
|
||||
%left '+' '-'
|
||||
%left UNARY_PREC
|
||||
|
||||
%%
|
||||
|
||||
|
|
@ -169,7 +169,13 @@ case_items
|
|||
|
||||
const_expression
|
||||
: NUMBER
|
||||
{ $$ = new PENumber($1);
|
||||
{ verinum*tmp = $1;
|
||||
if (tmp == 0) {
|
||||
yyerror(@1, "XXXX internal error: const_expression.");
|
||||
$$ = 0;
|
||||
} else {
|
||||
$$ = new PENumber(tmp);
|
||||
}
|
||||
}
|
||||
| STRING
|
||||
{ $$ = new PEString(*$1);
|
||||
|
|
@ -179,7 +185,13 @@ const_expression
|
|||
|
||||
delay
|
||||
: '#' NUMBER
|
||||
{ $$ = new PENumber($2);
|
||||
{ verinum*tmp = $2;
|
||||
if (tmp == 0) {
|
||||
yyerror(@2, "XXXX internal error: delay.");
|
||||
$$ = 0;
|
||||
} else {
|
||||
$$ = new PENumber(tmp);
|
||||
}
|
||||
}
|
||||
| '#' IDENTIFIER
|
||||
{ $$ = new PEIdent(*$2);
|
||||
|
|
@ -293,7 +305,12 @@ expression_list
|
|||
|
||||
expr_primary
|
||||
: NUMBER
|
||||
{ $$ = new PENumber($1);
|
||||
{ if ($1 == 0) {
|
||||
yyerror(@1, "XXXX No number value in primary?");
|
||||
$$ = 0;
|
||||
} else {
|
||||
$$ = new PENumber($1);
|
||||
}
|
||||
}
|
||||
| STRING
|
||||
{ $$ = new PEString(*$1);
|
||||
|
|
|
|||
Loading…
Reference in New Issue