Introductory changes for numbers handling
This commit is contained in:
parent
75203dc121
commit
0395eadbc8
|
|
@ -25,8 +25,15 @@
|
|||
|
||||
# include "parse_api.h"
|
||||
# include "lexor_keyword.h"
|
||||
# include "vhdlnum.h"
|
||||
# include "vhdlreal.h"
|
||||
# include "parse_wrap.h"
|
||||
|
||||
# include <iostream>
|
||||
|
||||
//class vhdlnum;
|
||||
//class vhdlreal;
|
||||
|
||||
extern int lexor_keyword_code (const char*str, unsigned len);
|
||||
|
||||
/*
|
||||
|
|
@ -38,7 +45,10 @@ extern int lexor_keyword_code (const char*str, unsigned len);
|
|||
*/
|
||||
extern YYLTYPE yylloc;
|
||||
|
||||
static int check_underscores(char*);
|
||||
static int check_underscores(char* text);
|
||||
|
||||
vhdlnum* make_unisized_dec(char* text);
|
||||
vhdlnum* make_unisized_based(char* text);
|
||||
|
||||
static char* strdupnew(char const *str)
|
||||
{
|
||||
|
|
@ -57,6 +67,7 @@ decimal_literal {integer}(\.{integer})?({exponent})?
|
|||
integer [0-9](_?[0-9])*
|
||||
exponent [eE][-+]?{integer}
|
||||
|
||||
based_literal {integer}#{based_integer}(\.{based_integer})?#{exponent}?
|
||||
based_integer [0-9a-fA-F](_?[0-9a-fA-F])*
|
||||
%%
|
||||
|
||||
|
|
@ -84,6 +95,9 @@ based_integer [0-9a-fA-F](_?[0-9a-fA-F])*
|
|||
int rc = lexor_keyword_code(yytext, yyleng);
|
||||
switch (rc) {
|
||||
case IDENTIFIER:
|
||||
if(check_underscores(yytext))
|
||||
std::cerr << "An invalid underscore in the identifier" << std::endl;
|
||||
//yywarn(yylloc, "An invalid underscore in the identifier");
|
||||
yylval.text = strdupnew(yytext);
|
||||
break;
|
||||
default:
|
||||
|
|
@ -91,7 +105,30 @@ based_integer [0-9a-fA-F](_?[0-9a-fA-F])*
|
|||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
\\(.|\\\\)*\\ { /* extended identifiers */
|
||||
yylval.text = strdupnew(yytext);
|
||||
printf("special %s\n", yytext);
|
||||
return IDENTIFIER;
|
||||
}
|
||||
|
||||
|
||||
{decimal_literal} {
|
||||
if(strchr(yytext, '.')) {
|
||||
yylval.real = new vhdlreal(yytext);
|
||||
return REAL_LITERAL;
|
||||
} else {
|
||||
yylval.integer = new vhdlnum(yytext);
|
||||
return INT_LITERAL;
|
||||
}
|
||||
}
|
||||
|
||||
{based_literal} {
|
||||
yylval.integer = new vhdlnum(yytext);
|
||||
return INT_LITERAL;
|
||||
}
|
||||
|
||||
|
||||
/* Compound symbols */
|
||||
"<=" { return LEQ; }
|
||||
">=" { return GEQ; }
|
||||
|
|
@ -99,7 +136,13 @@ based_integer [0-9a-fA-F](_?[0-9a-fA-F])*
|
|||
"/=" { return NE; }
|
||||
"<>" { return BOX; }
|
||||
"**" { return EXP; }
|
||||
/*
|
||||
"=>" { return ARROW; }
|
||||
"<<" { return DLT; }
|
||||
">>" { return DGT; }
|
||||
/*
|
||||
Here comes a list of symbols that are more then strange,
|
||||
at least for the time being.
|
||||
|
||||
"??" { return K_CC; }
|
||||
"?=" {}
|
||||
"?/=" {}
|
||||
|
|
@ -115,8 +158,22 @@ based_integer [0-9a-fA-F](_?[0-9a-fA-F])*
|
|||
|
||||
extern void yyparse_set_filepath(const char*path);
|
||||
|
||||
static int check_underscores(char* text) {
|
||||
|
||||
static int check_underscores(char* text)
|
||||
{
|
||||
unsigned char underscore_allowed = 0;
|
||||
const char* cp;
|
||||
for( cp = text; *cp; ++cp)
|
||||
{
|
||||
if (*cp == '_')
|
||||
{
|
||||
if (!underscore_allowed || *(cp+1) == '\0')
|
||||
return 1;
|
||||
underscore_allowed = 0;
|
||||
}
|
||||
else
|
||||
underscore_allowed = 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void reset_lexor(FILE*fd, const char*path)
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ guarded, GN_KEYWORD_2008, K_guarded
|
|||
if, GN_KEYWORD_2008, K_if
|
||||
impure, GN_KEYWORD_2008, K_impure
|
||||
in, GN_KEYWORD_2008, K_in
|
||||
inertial, GN_KEYWORD_2008, K_internal
|
||||
inertial, GN_KEYWORD_2008, K_inertial
|
||||
inout, GN_KEYWORD_2008, K_inout
|
||||
is, GN_KEYWORD_2008, K_is
|
||||
label, GN_KEYWORD_2008, K_label
|
||||
|
|
@ -83,7 +83,7 @@ port, GN_KEYWORD_2008, K_port
|
|||
postponed, GN_KEYWORD_2008, K_postponed
|
||||
procedure, GN_KEYWORD_2008, K_procedure
|
||||
process, GN_KEYWORD_2008, K_process
|
||||
property, GN_KEYWORD_2008, K_propoerty
|
||||
property, GN_KEYWORD_2008, K_property
|
||||
protected, GN_KEYWORD_2008, K_protected
|
||||
pure, GN_KEYWORD_2008, K_pure
|
||||
range, GN_KEYWORD_2008, K_range
|
||||
|
|
|
|||
|
|
@ -20,9 +20,11 @@
|
|||
*/
|
||||
|
||||
# include "vhdlpp_config.h"
|
||||
# include "vhdlnum.h"
|
||||
# include "vhdlreal.h"
|
||||
# include "compiler.h"
|
||||
# include "parse_api.h"
|
||||
# include <string.h>
|
||||
# include <string.h>
|
||||
# include <cstdarg>
|
||||
# include <list>
|
||||
|
||||
|
|
@ -39,10 +41,13 @@ static void errormsg(const YYLTYPE&loc, const char*msg, ...);
|
|||
int parse_errors = 0;
|
||||
%}
|
||||
|
||||
|
||||
%union {
|
||||
port_mode_t port_mode;
|
||||
char*text;
|
||||
|
||||
vhdlnum* integer;
|
||||
vhdlreal* real;
|
||||
|
||||
InterfacePort*interface_element;
|
||||
std::list<InterfacePort*>* interface_list;
|
||||
};
|
||||
|
|
@ -74,8 +79,11 @@ int parse_errors = 0;
|
|||
%token K_xnor K_xor
|
||||
/* Identifiers that are not keywords are identifiers. */
|
||||
%token <text> IDENTIFIER
|
||||
%token <integer> INT_LITERAL
|
||||
%token <real> REAL_LITERAL
|
||||
%token <text> STRING_LITERAL CHARACTER_LITERAL
|
||||
/* compound symbols */
|
||||
%token LEQ GEQ VASSIGN NE BOX EXP
|
||||
%token LEQ GEQ VASSIGN NE BOX EXP ARROW DLT DGT
|
||||
|
||||
/* The rules may have types. */
|
||||
%type <interface_element> interface_element
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@
|
|||
*/
|
||||
|
||||
# include <list>
|
||||
# include "vhdlnum.h"
|
||||
# include "vhdlreal.h"
|
||||
# include "parse.h"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef __vhdlnum_H
|
||||
#define __vhdlnum_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#warning vhdlnum
|
||||
|
||||
class vhdlnum {
|
||||
public:
|
||||
vhdlnum(char* text) {}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef __vhdlreal_h
|
||||
#define __vhdlreal_h
|
||||
|
||||
#include "config.h"
|
||||
|
||||
class vhdlreal {
|
||||
public:
|
||||
vhdlreal(char* text) {}
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue