diff --git a/vhdlpp/lexor.lex b/vhdlpp/lexor.lex index 33011cee4..dd59ad95b 100644 --- a/vhdlpp/lexor.lex +++ b/vhdlpp/lexor.lex @@ -25,8 +25,15 @@ # include "parse_api.h" # include "lexor_keyword.h" +# include "vhdlnum.h" +# include "vhdlreal.h" # include "parse_wrap.h" +# include + +//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) diff --git a/vhdlpp/lexor_keyword.gperf b/vhdlpp/lexor_keyword.gperf index 2f31ad521..39663f02f 100644 --- a/vhdlpp/lexor_keyword.gperf +++ b/vhdlpp/lexor_keyword.gperf @@ -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 diff --git a/vhdlpp/parse.y b/vhdlpp/parse.y index 0c739cfcb..9c24a65a1 100644 --- a/vhdlpp/parse.y +++ b/vhdlpp/parse.y @@ -20,9 +20,11 @@ */ # include "vhdlpp_config.h" +# include "vhdlnum.h" +# include "vhdlreal.h" # include "compiler.h" # include "parse_api.h" -# include +# include # include # include @@ -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* interface_list; }; @@ -74,8 +79,11 @@ int parse_errors = 0; %token K_xnor K_xor /* Identifiers that are not keywords are identifiers. */ %token IDENTIFIER +%token INT_LITERAL +%token REAL_LITERAL +%token 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 diff --git a/vhdlpp/parse_wrap.h b/vhdlpp/parse_wrap.h index 1b835d5a9..2d09ecd62 100644 --- a/vhdlpp/parse_wrap.h +++ b/vhdlpp/parse_wrap.h @@ -26,6 +26,8 @@ */ # include +# include "vhdlnum.h" +# include "vhdlreal.h" # include "parse.h" #endif diff --git a/vhdlpp/vhdlnum.h b/vhdlpp/vhdlnum.h new file mode 100644 index 000000000..034760315 --- /dev/null +++ b/vhdlpp/vhdlnum.h @@ -0,0 +1,13 @@ +#ifndef __vhdlnum_H +#define __vhdlnum_H + +#include "config.h" + +#warning vhdlnum + +class vhdlnum { + public: + vhdlnum(char* text) {} +}; + +#endif diff --git a/vhdlpp/vhdlreal.h b/vhdlpp/vhdlreal.h new file mode 100644 index 000000000..c74263fdd --- /dev/null +++ b/vhdlpp/vhdlreal.h @@ -0,0 +1,11 @@ +#ifndef __vhdlreal_h +#define __vhdlreal_h + +#include "config.h" + +class vhdlreal { + public: + vhdlreal(char* text) {} +}; + +#endif