📄 vparsebison.y
字号:
// -*- C++ -*-//*****************************************************************************// DESCRIPTION: SystemC bison parser//// This file is part of SystemC-Perl.//// Author: Wilson Snyder <wsnyder@wsnyder.org>//// Code available from: http://www.veripool.org/systemperl////*****************************************************************************//// Copyright 2001-2009 by Wilson Snyder. This program is free software;// you can redistribute it and/or modify it under the terms of either the GNU// Lesser General Public License or the Perl Artistic License.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.////****************************************************************************/%{#include <cstdio>#include <fstream>#include <stack>#include <vector>#include <map>#include <deque>#include <cassert>#include "VParse.h"#include "VParseGrammar.h"#define YYERROR_VERBOSE 1#define YYINITDEPTH 5000 // Large as the stack won't grow, since YYSTYPE_IS_TRIVIAL isn't defined#define YYMAXDEPTH 5000// See VParseGrammar.h for the C++ interface to this parser// Include that instead of VParseBison.h//*************************************************************************#define GRAMMARP VParseGrammar::staticGrammarp()#define PARSEP VParseGrammar::staticParsep()#define NEWSTRING(text) (string((text)))#define VARRESET() { VARDECL(""); VARIO(""); VARSIGNED(""); VARRANGE(""); VARARRAY("");}#define VARDECL(type) { GRAMMARP->m_varDecl = (type); }#define VARIO(type) { GRAMMARP->m_varIO = (type); }#define VARSIGNED(value) { GRAMMARP->m_varSigned=(value); }#define VARRANGE(range) { GRAMMARP->m_varRange=(range); }#define VARARRAY(value) { GRAMMARP->m_varArray=(value); }#define VARDONE(fl,name,value) {\ if (GRAMMARP->m_varIO!="") PARSEP->signalCb((fl),GRAMMARP->m_varIO, (name),GRAMMARP->m_varRange, GRAMMARP->m_varArray, GRAMMARP->m_varSigned, "", GRAMMARP->m_inFTask); \ if (GRAMMARP->m_varDecl!="") PARSEP->signalCb((fl),GRAMMARP->m_varDecl,(name),GRAMMARP->m_varRange, GRAMMARP->m_varArray, GRAMMARP->m_varSigned, (value), GRAMMARP->m_inFTask); \}#define INSTPREP(cellmod,cellparam) { GRAMMARP->pinNum(1); GRAMMARP->m_cellMod=(cellmod); GRAMMARP->m_cellParam=(cellparam); }static void PINDONE(VFileLine* fl, const string& name, const string& expr) { if (GRAMMARP->m_cellParam) { // Stack them until we create the instance itself GRAMMARP->m_pinStack.push_back(VParseGPin(fl, name, expr, GRAMMARP->pinNum())); } else { PARSEP->pinCb(fl, name, expr, GRAMMARP->pinNum()); }}static void PINPARAMS() { // Throw out all the pins we found before we could do instanceCb while (!GRAMMARP->m_pinStack.empty()) { VParseGPin& pinr = GRAMMARP->m_pinStack.front(); PARSEP->paramPinCb(pinr.m_fl, pinr.m_name, pinr.m_conn, pinr.m_number); GRAMMARP->m_pinStack.pop_front(); }}/* Yacc */static int VParseBisonlex(VParseBisonYYSType* yylvalp) { return PARSEP->lexToBison(yylvalp); }static void VParseBisonerror(const char *s) { VParseGrammar::bisonError(s); }%}%pure_parser%token_table// When writing Bison patterns we use yTOKEN instead of "token",// so Bison will error out on unknown "token"s.// Generic lexer tokens, for example a number// IEEE: real_number%token<str> yaFLOATNUM "FLOATING-POINT NUMBER"// IEEE: identifier, class_identifier, class_variable_identifier,// covergroup_variable_identifier, dynamic_array_variable_identifier,// enum_identifier, interface_identifier, interface_instance_identifier,// package_identifier, type_identifier, variable_identifier,%token<str> yaID "IDENTIFIER"// IEEE: integral_number%token<str> yaINTNUM "INTEGER NUMBER"// IEEE: time_literal + time_unit%token<str> yaTIMENUM "TIME NUMBER"// IEEE: string_literal%token<str> yaSTRING "STRING"%token<str> yaTIMINGSPEC "TIMING SPEC ELEMENT"%token<str> ygenGATE "GATE keyword"%token<str> ygenKEYWORD "KEYWORD"%token<str> ygenNETTYPE "NETTYPE keyword (tri0/wand/etc)"%token<str> ygenOPERATOR "OPERATOR"%token<str> ygenSTRENGTH "STRENGTH keyword (strong1/etc)"%token<str> ygenSYSCALL "SYSCALL"%token<str> '!'%token<str> '#'%token<str> '%'%token<str> '&'%token<str> '('%token<str> ')'%token<str> '*'%token<str> '+'%token<str> ','%token<str> '-'%token<str> '.'%token<str> '/'%token<str> ':'%token<str> ';'%token<str> '<'%token<str> '='%token<str> '>'%token<str> '?'%token<str> '@'%token<str> '['%token<str> ']'%token<str> '^'%token<str> '{'%token<str> '|'%token<str> '}'%token<str> '~'// Specific keywords// yKEYWORD means match "keyword"// Other cases are yXX_KEYWORD where XX makes it unique,// for example yP_ for punctuation based operators.// Double underscores "yX__Y" means token X followed by Y,// and "yX__ETC" means X folled by everything but Y(s).%token<str> yALIAS "alias"%token<str> yALWAYS "always"%token<str> yAND "and"%token<str> yASSERT "assert"%token<str> yASSIGN "assign"%token<str> yASSUME "assume"%token<str> yAUTOMATIC "automatic"%token<str> yBEFORE "before"%token<str> yBEGIN "begin"%token<str> yBIND "bind"%token<str> yBINS "bins"%token<str> yBINSOF "binsof"%token<str> yBIT "bit"%token<str> yBREAK "break"%token<str> yBUF "buf"%token<str> yBYTE "byte"%token<str> yCASE "case"%token<str> yCASEX "casex"%token<str> yCASEZ "casez"%token<str> yCHANDLE "chandle"%token<str> yCLASS "class"%token<str> yCLOCK "clock"%token<str> yCLOCKING "clocking"%token<str> yCONST "const"%token<str> yCONSTRAINT "constraint"%token<str> yCONTEXT "context"%token<str> yCONTINUE "continue"%token<str> yCOVER "cover"%token<str> yCOVERGROUP "covergroup"%token<str> yCOVERPOINT "coverpoint"%token<str> yCROSS "cross"%token<str> yDEASSIGN "deassign"%token<str> yDEFAULT "default"%token<str> yDEFPARAM "defparam"%token<str> yDISABLE "disable"%token<str> yDIST "dist"%token<str> yDO "do"%token<str> yELSE "else"%token<str> yEND "end"%token<str> yENDCASE "endcase"%token<str> yENDCLASS "endclass"%token<str> yENDCLOCKING "endclocking"%token<str> yENDFUNCTION "endfunction"%token<str> yENDGENERATE "endgenerate"%token<str> yENDGROUP "endgroup"%token<str> yENDINTERFACE "endinterface"%token<str> yENDMODULE "endmodule"%token<str> yENDPACKAGE "endpackage"%token<str> yENDPROGRAM "endprogram"%token<str> yENDPROPERTY "endproperty"%token<str> yENDSEQUENCE "endsequence"%token<str> yENDSPECIFY "endspecify"%token<str> yENDTABLE "endtable"%token<str> yENDTASK "endtask"%token<str> yENUM "enum"%token<str> yEVENT "event"%token<str> yEXPECT "expect"%token<str> yEXPORT "export"%token<str> yEXTENDS "extends"%token<str> yEXTERN "extern"%token<str> yFINAL "final"%token<str> yFIRST_MATCH "first_match"%token<str> yFOR "for"%token<str> yFORCE "force"%token<str> yFOREACH "foreach"%token<str> yFOREVER "forever"%token<str> yFORK "fork"%token<str> yFORKJOIN "forkjoin"%token<str> yFUNCTION "function"%token<str> yGENERATE "generate"%token<str> yGENVAR "genvar"%token<str> yIF "if"%token<str> yIFF "iff"%token<str> yIGNORE_BINS "ignore_bins"%token<str> yILLEGAL_BINS "illegal_bins"%token<str> yIMPORT "import"%token<str> yINITIAL "initial"%token<str> yINOUT "inout"%token<str> yINPUT "input"%token<str> yINSIDE "inside"%token<str> yINT "int"%token<str> yINTEGER "integer"%token<str> yINTERFACE "interface"%token<str> yINTERSECT "intersect"%token<str> yJOIN "join"%token<str> yLOCAL "local"%token<str> yLOCALPARAM "localparam"%token<str> yLOGIC "logic"%token<str> yLONGINT "longint"%token<str> yMATCHES "matches"%token<str> yMODPORT "modport"%token<str> yMODULE "module"%token<str> yNAND "nand"%token<str> yNEGEDGE "negedge"%token<str> yNEW "new"%token<str> yNOR "nor"%token<str> yNOT "not"%token<str> yNULL "null"%token<str> yOR "or"%token<str> yOUTPUT "output"%token<str> yPACKAGE "package"%token<str> yPACKED "packed"%token<str> yPARAMETER "parameter"%token<str> yPOSEDGE "posedge"%token<str> yPRIORITY "priority"%token<str> yPROGRAM "program"%token<str> yPROPERTY "property"%token<str> yPROTECTED "protected"%token<str> yPURE "pure"%token<str> yRAND "rand"%token<str> yRANDC "randc"%token<str> yRANDCASE "randcase"%token<str> yRANDOMIZE "randomize"%token<str> yRANDSEQUENCE "randsequence"%token<str> yREAL "real"%token<str> yREALTIME "realtime"%token<str> yREF "ref"%token<str> yREG "reg"%token<str> yRELEASE "release"%token<str> yREPEAT "repeat"%token<str> yRETURN "return"%token<str> ySCALARED "scalared"%token<str> ySEQUENCE "sequence"%token<str> ySHORTINT "shortint"%token<str> ySHORTREAL "shortreal"%token<str> ySIGNED "signed"%token<str> ySOLVE "solve"%token<str> ySPECIFY "specify"%token<str> ySPECPARAM "specparam"%token<str> ySTATIC "static"%token<str> ySTRING "string"%token<str> ySTRUCT "struct"%token<str> ySUPER "super"%token<str> ySUPPLY0 "supply0"%token<str> ySUPPLY1 "supply1"%token<str> yTABLE "table"%token<str> yTAGGED "tagged"%token<str> yTASK "task"%token<str> yTHIS "this"%token<str> yTHROUGHOUT "throughout"%token<str> yTIME "time"%token<str> yTIMEPRECISION "timeprecision"%token<str> yTIMEUNIT "timeunit"%token<str> yTRI "tri"%token<str> yTYPE "type"%token<str> yTYPEDEF "typedef"%token<str> yUNION "union"%token<str> yUNIQUE "unique"%token<str> yUNSIGNED "unsigned"%token<str> yVAR "var"%token<str> yVECTORED "vectored"%token<str> yVIRTUAL "virtual"%token<str> yVIRTUAL__CLASS "virtual-for-class"%token<str> yVOID "void"%token<str> yWAIT "wait"%token<str> yWAIT_ORDER "wait_order"%token<str> yWHILE "while"%token<str> yWILDCARD "wildcard"%token<str> yWIRE "wire"%token<str> yWITH "with"%token<str> yWITHIN "within"%token<str> yXNOR "xnor"%token<str> yXOR "xor"%token<str> yD_ROOT "$root"%token<str> yD_UNIT "$unit"%token<str> yP_TICK "'"%token<str> yP_TICKBRA "'{"%token<str> yP_OROR "||"%token<str> yP_ANDAND "&&"%token<str> yP_NOR "~|"%token<str> yP_XNOR "^~"%token<str> yP_NAND "~&"%token<str> yP_EQUAL "=="%token<str> yP_NOTEQUAL "!="%token<str> yP_CASEEQUAL "==="%token<str> yP_CASENOTEQUAL "!=="%token<str> yP_WILDEQUAL "==?"%token<str> yP_WILDNOTEQUAL "!=?"%token<str> yP_GTE ">="%token<str> yP_LTE "<="%token<str> yP_SLEFT "<<"%token<str> yP_SRIGHT ">>"%token<str> yP_SSRIGHT ">>>"%token<str> yP_POW "**"%token<str> yP_PAR__STRENGTH "(-for-strength"%token<str> yP_PLUSCOLON "+:"%token<str> yP_MINUSCOLON "-:"%token<str> yP_MINUSGT "->"%token<str> yP_MINUSGTGT "->>"%token<str> yP_EQGT "=>"%token<str> yP_ASTGT "*>"%token<str> yP_ANDANDAND "&&&"%token<str> yP_POUNDPOUND "##"%token<str> yP_DOTSTAR ".*"%token<str> yP_ATAT "@@"%token<str> yP_COLONCOLON "::"%token<str> yP_COLONEQ ":="%token<str> yP_COLONDIV ":/"%token<str> yP_ORMINUSGT "|->"%token<str> yP_OREQGT "|=>"%token<str> yP_PLUSPLUS "++"%token<str> yP_MINUSMINUS "--"%token<str> yP_PLUSEQ "+="%token<str> yP_MINUSEQ "-="%token<str> yP_TIMESEQ "*="%token<str> yP_DIVEQ "/="%token<str> yP_MODEQ "%="%token<str> yP_ANDEQ "&="%token<str> yP_OREQ "|="%token<str> yP_XOREQ "^="%token<str> yP_SLEFTEQ "<<="%token<str> yP_SRIGHTEQ ">>="%token<str> yP_SSRIGHTEQ ">>>="// [* is not a operator, as "[ * ]" is legal// [= and [-> could be repitition operators, but to match [* we don't add them.// '( is not a operator, as "' (" is legal//********************// Verilog op precedence%token<str> prUNARYARITH%token<str> prREDUCTION%token<str> prNEGATION%token<str> prEVENTBEGIN%left ':'%left '?'%left yP_OROR%left yP_ANDAND%left '|' yP_NOR%left '^'%left yP_XNOR%left '&' yP_NAND%left yP_EQUAL yP_NOTEQUAL yP_CASEEQUAL yP_CASENOTEQUAL yP_WILDEQUAL yP_WILDNOTEQUAL%left '>' '<' yP_GTE yP_LTE yINSIDE yDIST%left yP_SLEFT yP_SRIGHT yP_SSRIGHT%left '+' '-'%left '*' '/' '%'%left yP_POW%left '{' '}'%left prUNARYARITH yP_MINUSMINUS yP_PLUSPLUS%left prREDUCTION%left prNEGATION%left prEVENTBEGIN%nonassoc prLOWER_THAN_ELSE%nonassoc yELSE//BISONPRE_TYPES// Blank lines for type insertion// Blank lines for type insertion// Blank lines for type insertion// Blank lines for type insertion// Blank lines for type insertion// Blank lines for type insertion%start source_text%%//**********************************************************************// Feedback to the Lexer// Note we read a parenthesis ahead, so this may not change the lexer at the right point.statePushVlg: // For PSL lexing, escape current state into Verilog state /* empty */ { } ;statePop: // Return to previous lexing state /* empty */ { } ;//**********************************************************************// Filessource_text: // ==IEEE: source_text /* empty */ { } | timeunits_declarationE descriptionList { } ;descriptionList: // IEEE: part of source_text description { } | descriptionList description { } ;description: // ==IEEE: description // // IEEE: udp_declaration - aliased to module in lexer module_declaration { } | interface_declaration { }// | program_declaration { } | package_declaration { } | package_item { }// | bind_directive { } // unsupported // IEEE: config_declaration | error { } ;timeunits_declarationE: // IEEE: timeunits_declaration + empty /*empty*/ { } | yTIMEUNIT yaTIMENUM ';' { } | yTIMEPRECISION yaTIMENUM ';' { } | yTIMEUNIT yaTIMENUM ';' yTIMEPRECISION yaTIMENUM ';' { }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -