Internals: Real1: properly lex doubles
This commit is contained in:
parent
a007458cb8
commit
59c3c536c7
|
|
@ -1624,7 +1624,7 @@ public:
|
||||||
void ignoreOverlap(bool flag) { m_ignoreOverlap = flag; }
|
void ignoreOverlap(bool flag) { m_ignoreOverlap = flag; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class AstSFormatF : public AstNode {
|
struct AstSFormatF : public AstNode {
|
||||||
// Convert format to string, generally under a AstDisplay or AstSFormat
|
// Convert format to string, generally under a AstDisplay or AstSFormat
|
||||||
// Also used as "real" function for /*verilator sformat*/ functions
|
// Also used as "real" function for /*verilator sformat*/ functions
|
||||||
string m_text;
|
string m_text;
|
||||||
|
|
|
||||||
|
|
@ -254,6 +254,7 @@ public:
|
||||||
void verilatorCmtLintSave();
|
void verilatorCmtLintSave();
|
||||||
void verilatorCmtLintRestore();
|
void verilatorCmtLintRestore();
|
||||||
void verilatorCmtBad(const char* text);
|
void verilatorCmtBad(const char* text);
|
||||||
|
double parseDouble(const char* text, size_t length);
|
||||||
void pushBeginKeywords(int state) { m_inBeginKwd++; m_lastVerilogState=state; }
|
void pushBeginKeywords(int state) { m_inBeginKwd++; m_lastVerilogState=state; }
|
||||||
bool popBeginKeywords() { if (m_inBeginKwd) { m_inBeginKwd--; return true; } else return false; }
|
bool popBeginKeywords() { if (m_inBeginKwd) { m_inBeginKwd--; return true; } else return false; }
|
||||||
int lastVerilogState() { return m_lastVerilogState; }
|
int lastVerilogState() { return m_lastVerilogState; }
|
||||||
|
|
|
||||||
|
|
@ -812,11 +812,11 @@ word [a-zA-Z0-9_]+
|
||||||
return yaINTNUM;
|
return yaINTNUM;
|
||||||
}
|
}
|
||||||
[0-9][_0-9]*(\.[_0-9]+)([eE][-+]?[_0-9]+)? {
|
[0-9][_0-9]*(\.[_0-9]+)([eE][-+]?[_0-9]+)? {
|
||||||
FL; yylval.cdouble = 0; /* Only for delays, not used yet */
|
FL; yylval.cdouble = PARSEP->parseDouble(yytext, yyleng);
|
||||||
return yaFLOATNUM;
|
return yaFLOATNUM;
|
||||||
}
|
}
|
||||||
[0-9][_0-9]*(\.[_0-9]+)?([eE][-+]?[_0-9]+) {
|
[0-9][_0-9]*(\.[_0-9]+)?([eE][-+]?[_0-9]+) {
|
||||||
FL; yylval.cdouble = 0; /* Only for delays, not used yet */
|
FL; yylval.cdouble = PARSEP->parseDouble(yytext, yyleng);
|
||||||
return yaFLOATNUM;
|
return yaFLOATNUM;
|
||||||
}
|
}
|
||||||
[0-9][_0-9]*(\.[_0-9]+)?(fs|ps|ns|us|ms|s|step) {
|
[0-9][_0-9]*(\.[_0-9]+)?(fs|ps|ns|us|ms|s|step) {
|
||||||
|
|
@ -949,6 +949,20 @@ word [a-zA-Z0-9_]+
|
||||||
%%
|
%%
|
||||||
int V3ParseImp::stateVerilogRecent() { return STATE_VERILOG_RECENT; }
|
int V3ParseImp::stateVerilogRecent() { return STATE_VERILOG_RECENT; }
|
||||||
|
|
||||||
|
double V3ParseImp::parseDouble(const char* textp, size_t length) {
|
||||||
|
char* strgp = new char[strlen(textp)+1];
|
||||||
|
char* dp=strgp;
|
||||||
|
for (const char* sp=textp; sp<(textp+length);) {
|
||||||
|
if (*sp != '_') *dp++ = *sp++;
|
||||||
|
else sp++;
|
||||||
|
}
|
||||||
|
char* endp = strgp;
|
||||||
|
double d = strtod(strgp, &endp);
|
||||||
|
if ((endp-strgp) != length) { yyerrorf("Syntax error parsing real: %s",strgp); }
|
||||||
|
delete strgp;
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
int V3ParseImp::lexToken() {
|
int V3ParseImp::lexToken() {
|
||||||
// called from lexToBison, has a "this"
|
// called from lexToBison, has a "this"
|
||||||
// Fetch next token from prefetch or real lexer
|
// Fetch next token from prefetch or real lexer
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue