⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vparselex.l

📁 Verilog Parser in Perl
💻 L
📖 第 1 页 / 共 3 页
字号:
}  /* Identifiers and numbers */<V95,V01,V05,S05>{  /* Consume a following space, as we're going to add one to the symbol, we'd like to avoid inserting an extra */  {escid}{space}	{ if (VParseLex::symEscapeless(yytext+1,yyleng-1-1)) {			      string sym = string(yytext+1,yyleng-1-1);			      FL; CALLBACKS(symbolCb, sym); VALTEXTS(sym); unput(' ');			  } else {			      string sym = string(yytext,yyleng-1) + ' ';			      FL; CALLBACKS(symbolCb, sym); VALTEXTS(sym);			  }			  return yaID; }  {escid}		{ if (VParseLex::symEscapeless(yytext+1,yyleng-1)) {			      string sym = string(yytext+1,yyleng-1);			      FL; CALLBACKS(symbolCb, sym); VALTEXTS(sym);			  } else {			      string sym = string(yytext,yyleng) + ' ';			      FL; CALLBACKS(symbolCb, sym); VALTEXTS(sym);			  }			  return yaID; }  {id}			{ FL; VALTEXT; CALLBACK(symbolCb); return yaID; }  \"[^\"\\]*\"		{ FL; VALTEXT; CALLBACK(stringCb); return yaSTRING;			}  \" 			{ yy_push_state(STRING); yymore(); }  [0-9]*?['']s?[bcodhBCODH][ \t]*[A-Fa-f0-9xXzZ_?]*	{			  FL; VALTEXT; CALLBACK(numberCb); return yaINTNUM;			}  [0-9]*?['']s?[01xXzZ]	{	/* SystemVerilog */			  FL; VALTEXT; CALLBACK(numberCb); return yaINTNUM;			}  [0-9][_0-9]*[ \t]*['']s?[bcodhBCODH]?[ \t]*[A-Fa-f0-9xXzZ_?]*	{			  FL; VALTEXT; CALLBACK(numberCb); return yaINTNUM;			}  [0-9][_0-9]*		{ FL; VALTEXT; CALLBACK(numberCb); return yaINTNUM;			}  [0-9][_0-9]*(\.[_0-9]+)([eE][-+]?[_0-9]+)? {                          FL; VALTEXT; CALLBACK(numberCb); return yaFLOATNUM;			}  [0-9][_0-9]*(\.[_0-9]+)?([eE][-+]?[_0-9]+) {                          FL; VALTEXT; CALLBACK(numberCb); return yaFLOATNUM;			}  [0-9][_0-9]*(\.[_0-9]+)?(fs|ps|ns|us|ms|s|step) {                          FL; VALTEXT; CALLBACK(numberCb); return yaTIMENUM;			}}  /************************************************************************/  /* STRINGS */<STRING>\n 		{ yyerrorf("Unterminated string\n"); }<STRING>\r		;<STRING>[^\"\\]* 	{ yymore(); }<STRING>\\.	 	{ yymore(); }<STRING>\" 		{ yy_pop_state();			  FL; VALTEXT; CALLBACK(stringCb); return yaSTRING; }  /************************************************************************/  /* Multi-line COMMENTS */<CMTMODE>"*"+[^*/\n]* 	{ yymore(); }<CMTMODE>\n		{ yymore(); NEXTLINE(); }<CMTMODE>"*"+"/"	{ FL; VALTEXT; CALLBACK(commentCb); yy_pop_state(); }<CMTMODE>. 		{ yymore(); }<CMTMODE><<EOF>>	{ yyerrorf("EOF in '/* ... */' block comment");			  yyleng = 0; yy_pop_state(); }  /************************************************************************/  /* Protected */<PROTMODE>\n		{ yymore(); NEXTLINE(); }<PROTMODE>"`endprotected"	{ FL; VALTEXT; CALLBACK(preprocCb); yy_pop_state(); }<PROTMODE>. 		{ yymore(); }<PROTMODE><<EOF>>	{ yyerrorf("EOF in `protected");			  yyleng = 0; yy_pop_state(); }  /************************************************************************/  /* Attributes */<ATTRMODE>\n		{ yymore(); NEXTLINE(); }<ATTRMODE>"*)"		{ FL; VALTEXT; CALLBACK(attributeCb); yy_pop_state(); }<ATTRMODE>. 		{ yymore(); }<ATTRMODE><<EOF>>	{ yyerrorf("EOF in (*");			  yyleng = 0; yy_pop_state(); }  /************************************************************************/  /* Attributes */<V95,V01,V05,S05>{    "(*"/{ws}*[^)]	{ FL; yymore(); yy_push_state(ATTRMODE); }	// Doesn't match (*)}  /************************************************************************/  /* Preprocssor */<V95,V01,V05,S05>{  "`accelerate"			{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog-XL compatibility  "`autoexpand_vectornets"	{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog-XL compatibility  "`celldefine"			{ FL; VALTEXT; CALLBACK(preprocCb); LEXP->m_inCellDefine=true; }  "`default_decay_time"{ws}+[^\n]*	{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog spec - delays only  "`default_nettype"{ws}+[a-zA-Z0-9]*	{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog 2001  "`delay_mode_distributed"	{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog spec - delays only  "`delay_mode_path"		{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog spec - delays only  "`delay_mode_unit"		{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog spec - delays only  "`delay_mode_zero"		{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog spec - delays only  "`disable_portfaults"		{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog-XL compatibility  "`enable_portfaults"		{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog-XL compatibility  "`endcelldefine"		{ FL; VALTEXT; CALLBACK(preprocCb); LEXP->m_inCellDefine=false; }  "`endprotect"			{ FL; VALTEXT; CALLBACK(preprocCb); }  "`expand_vectornets"		{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog-XL compatibility  "`inline"			{ FL; VALTEXT; CALLBACK(preprocCb); }  "`line"{ws}+[^\n]*\n		{ LPARSEP->inLineDirective(yytext); FL; VALTEXT; CALLBACK(preprocCb); }  "`noaccelerate"		{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog-XL compatibility  "`noexpand_vectornets"	{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog-XL compatibility  "`noremove_gatenames"		{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog-XL compatibility  "`noremove_netnames"		{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog-XL compatibility  "`nosuppress_faults"		{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog-XL compatibility  "`nounconnected_drive"	{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog-XL compatibility  "`portcoerce"			{ FL; VALTEXT; CALLBACK(preprocCb); }  "`pragma"{ws}+[^\n]*\n	{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog 2005  "`protect"			{ FL; VALTEXT; CALLBACK(preprocCb); }  "`protected"			{ FL; VALTEXT; CALLBACK(preprocCb); yy_push_state(PROTMODE); }  "`remove_gatenames"		{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog-XL compatibility  "`remove_netnames"		{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog-XL compatibility  "`resetall"			{ FL; VALTEXT; CALLBACK(preprocCb); }  "`suppress_faults"		{ FL; VALTEXT; CALLBACK(preprocCb); } // Verilog-XL compatibility  "`timescale"{ws}+[^\n]*\n	{ FL; VALTEXT; CALLBACK(preprocCb); NEXTLINE(); }  /* See also setLanguage below */  "`begin_keywords"[ \t]*\"1364-1995\"		{ yy_push_state(V95); CALLBACK(preprocCb); }  "`begin_keywords"[ \t]*\"1364-2001\"		{ yy_push_state(V01); CALLBACK(preprocCb); }  "`begin_keywords"[ \t]*\"1364-2001-noconfig\"	{ yy_push_state(V01); CALLBACK(preprocCb); }  "`begin_keywords"[ \t]*\"1364-2005\"		{ yy_push_state(V05); CALLBACK(preprocCb); }  "`begin_keywords"[ \t]*\"1800-2005\"		{ yy_push_state(S05); CALLBACK(preprocCb); }  "`end_keywords"				{ yy_pop_state();     CALLBACK(preprocCb); }}  /************************************************************************/  /* Default rules - leave last */<V95,V01,V05,S05>{  "`"[a-zA-Z_0-9]+	{ FL; VALTEXT;			  if (LPARSEP->sigParser()) { yyerrorf("Define or directive not defined: %s",yytext); }			  else { CALLBACK(preprocCb); } }  "//"[^\n]*		{ FL; VALTEXT; CALLBACK(commentCb); }  "/*"		       	{ yy_push_state(CMTMODE); yymore(); }  .			{ FL; VALTEXT; CALLBACK(operatorCb); return ygenOPERATOR; } /* return single char ops. */}  /* Catch all - absolutely last */<*>.|\n     		{ yyerrorf("Missing VParseLex.l rule: Default rule invoked in state %d: %s", YY_START, yytext); }%%void VParseLex::unputString(const char* textp) {    s_currentLexp = this;    // Add characters to input stream in back-to-front order    const char* cp;    for (cp = textp; *cp; cp++);    for (cp--; cp >= textp; cp--) {	unput(*cp);    }}void VParseLex::unused() {    if (0) {	// Prevent unused warnings	yy_top_state();    }}int VParseLex::lexToken(VParseBisonYYSType* yylvalp) {    // Fetch next token from prefetch or real lexer    s_currentLexp = this;    if (m_ahead) {	// We prefetched a extra token, give it back	m_ahead = false;	*yylvalp = m_aheadVal;	return m_aheadToken;    }    // Parse new token    s_yylvalp = yylvalp;    int token = yylex();    // If a paren, read another    if (token == '('	|| token == yVIRTUAL) {#ifdef FLEX_DEBUG	if (yy_flex_debug) { cout<<"   lexToken: reading ahead to find possible strength"<<endl; }#endif	s_yylvalp = &m_aheadVal;	int nexttok = yylex();	m_ahead = true;	m_aheadToken = nexttok;	// Now potentially munge the current token	if (token == '(' && (nexttok == ygenSTRENGTH			     || nexttok == ySUPPLY0			     || nexttok == ySUPPLY1)) {	    token = yP_PAR__STRENGTH;	}	else if (token == yVIRTUAL && (nexttok == yCLASS)) {	    token = yVIRTUAL__CLASS;	}	// If add to above "else if", also add to "if (token" further above    }    return token;}void VParseLex::debug(int level) {#ifdef FLEX_DEBUG    yy_flex_debug = level;#endif}void VParseLex::language(const char* value) {    if (0==strcmp(value,"1364-1995"))		{ BEGIN V95; }    else if (0==strcmp(value,"1364-2001"))	{ BEGIN V01; }    else if (0==strcmp(value,"1364-2001-noconfig")) { BEGIN V01; }    else if (0==strcmp(value,"1364-2005"))	{ BEGIN V05; }    else if (0==strcmp(value,"1800-2005"))	{ BEGIN S05; }    else yyerrorf("Unknown setLanguage code: %s", value);}/*################################################################### * Local Variables: * mode: C++ * End: */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -