📄 compilevhdl.java
字号:
// next is bodyName (identifier) TokenList bodyName = null; if (nextToken.token != TOKEN_IDENTIFIER) { reportErrorMsg(nextToken, "Expecting an identifier"); } else { bodyName = nextToken; } getNextToken(); // check for keyword OF if (!isKeySame(nextToken, KEY_OF)) { reportErrorMsg(nextToken, "Expecting keyword OF"); } getNextToken(); // next is design entity reference for this body (simple_name) SimpleName entityName = parseSimpleName(); // check for keyword IS if (!isKeySame(nextToken, KEY_IS)) { reportErrorMsg(nextToken, "Expecting keyword IS"); } getNextToken(); // body declaration part BodyDeclare bodyDeclare = parseBodyDeclare(); // should be at keyword BEGIN if (!isKeySame(nextToken, KEY_BEGIN)) { reportErrorMsg(nextToken, "Expecting keyword BEGIN"); } getNextToken(); // statements of body Statements statements = parseSetOfStatements(); // should be at keyword END if (!isKeySame(nextToken, KEY_END)) { reportErrorMsg(nextToken, "Expecting keyword END"); } getNextToken(); // optional body name if (nextToken.token == TOKEN_IDENTIFIER) { if (!nextToken.pointer.equals(bodyName.pointer)) { reportErrorMsg(nextToken, "Body name mismatch"); } getNextToken(); } // should be at final semicolon if (nextToken.token != TOKEN_SEMICOLON) { reportErrorMsg(nextToken, "Expecting a semicolon"); } nextToken = nextToken.next; // create body parse tree Body body = new Body(); body.name = bodyName; body.entity = entityName; body.bodyDeclare = bodyDeclare; body.statements = statements; return body; } /** * Method to parse a package declaration. * It has the form: * package_declaration ::= PACKAGE identifier IS * package_declarative_part * END [simple_name] ; * @return the package declaration. */ private Package parsePackage() throws ParseException { Package vPackage = null; // should be at keyword package if (!isKeySame(nextToken, KEY_PACKAGE)) { reportErrorMsg(nextToken, "Expecting keyword PACKAGE"); getNextToken(); return vPackage; } getNextToken(); // should be package identifier if (nextToken.token != TOKEN_IDENTIFIER) { reportErrorMsg(nextToken, "Expecting an identifier"); getNextToken(); return vPackage; } TokenList identifier = nextToken; getNextToken(); // should be at keyword IS if (!isKeySame(nextToken, KEY_IS)) { reportErrorMsg(nextToken, "Expecting keyword IS"); getNextToken(); return vPackage; } getNextToken(); // package declarative part PackagedPart declarePart = parsePackageDeclarePart(); // should be at keyword END if (!isKeySame(nextToken, KEY_END)) { reportErrorMsg(nextToken, "Expecting keyword END"); getNextToken(); return vPackage; } getNextToken(); // check for optional end identifier if (nextToken.token == TOKEN_IDENTIFIER) { if (!nextToken.pointer.equals(identifier.pointer)) { reportErrorMsg(nextToken, "Name mismatch"); getNextToken(); return vPackage; } getNextToken(); } // should be at semicolon if (nextToken.token != TOKEN_SEMICOLON) { reportErrorMsg(nextToken, "Expecting a semicolon"); getNextToken(); return vPackage; } getNextToken(); // create package structure vPackage = new Package(); vPackage.name = identifier; vPackage.declare = declarePart; return vPackage; } /** * Method to parse a use clause. * It has the form: * use_clause ::= USE unit {,unit} ; * unit ::= package_name.ALL * @return the use clause structure. */ private Use parseUse() throws ParseException { Use use = null; // should be at keyword USE if (!isKeySame(nextToken, KEY_USE)) { reportErrorMsg(nextToken, "Expecting keyword USE"); getNextToken(); return use; } getNextToken(); // must be at least one unit if (nextToken.token != TOKEN_IDENTIFIER) { reportErrorMsg(nextToken, "Bad unit name for use clause"); getNextToken(); return use; } use = new Use(); use.unit = nextToken; use.next = null; Use endUse = use; getNextToken(); // IEEE version uses form unit.ALL only for(;;) { if (nextToken.token != TOKEN_PERIOD) { reportErrorMsg(nextToken, "Expecting period"); break; } getNextToken(); if (isKeySame(nextToken, KEY_ALL)) { getNextToken(); break; } if (nextToken.token != TOKEN_IDENTIFIER) { reportErrorMsg(nextToken, "Bad unit name for use clause"); break; } getNextToken(); } while (nextToken.token == TOKEN_COMMA) { getNextToken(); if (nextToken.token != TOKEN_IDENTIFIER) { reportErrorMsg(nextToken, "Bad unit name for use clause"); getNextToken(); return use; } Use newUse = new Use(); newUse.unit = nextToken; newUse.next = null; endUse.next = newUse; endUse = newUse; getNextToken(); // IEEE version uses form unit.ALL only if (nextToken.token == TOKEN_PERIOD) getNextToken(); else reportErrorMsg(nextToken, "Expecting period"); if (isKeySame(nextToken, KEY_ALL)) getNextToken(); else reportErrorMsg(nextToken, "Expecting keyword ALL"); } // should be at semicolon if (nextToken.token != TOKEN_SEMICOLON) { reportErrorMsg(nextToken, "Expecting a semicolon"); } getNextToken(); return use; } /** * Method to parse a package declarative part. * It has the form: * package_declarative_part ::= package_declarative_item {package_declarative_item} * package_declarative_item ::= basic_declaration | function_declaration * Note: Currently only support basic declarations. * @return the package declarative part. */ private PackagedPart parsePackageDeclarePart() throws ParseException { PackagedPart dPart = null; // should be at least one if (isKeySame(nextToken, KEY_END)) { reportErrorMsg(nextToken, "No Package declarative part"); return dPart; } BasicDeclare dItem = parseBasicDeclare(); dPart = new PackagedPart(); dPart.item = dItem; dPart.next = null; PackagedPart endPart = dPart; while (!isKeySame(nextToken, KEY_END)) { dItem = parseBasicDeclare(); PackagedPart newpart = new PackagedPart(); newpart.item = dItem; newpart.next = null; endPart.next = newpart; endPart = newpart; } return dPart; } /** * Method to parse the body statements and return pointer to the parse tree. * The form of body statements are: * set_of_statements :== architectural_statement {architectural_statement} * architectural_statement :== generate_statement | signal_assignment_statement | architectural_if_statement | architectural_case_statement | component_instantiation_statement | null_statement * @return the statements parse tree. */ private Statements parseSetOfStatements() throws ParseException { Statements statements = null; Statements endState = null; while (!isKeySame(nextToken, KEY_END)) { int type = NOARCHSTATE; Object pointer = null; // check for case statement if (isKeySame(nextToken, KEY_CASE)) { // EMPTY } // check for null statement else if (isKeySame(nextToken, KEY_NULL)) { type = ARCHSTATE_NULL; pointer = null; getNextToken(); // should be a semicolon if (nextToken.token != TOKEN_SEMICOLON) { reportErrorMsg(nextToken, "Expecting a semicolon"); } getNextToken(); } // check for label else if (nextToken.token == TOKEN_IDENTIFIER && nextToken.next != null && nextToken.next.token == TOKEN_COLON) { TokenList label = nextToken; getNextToken(); getNextToken(); // check for generate statement if (isKeySame(nextToken, KEY_IF)) { type = ARCHSTATE_GENERATE; pointer = parseGenerate(label, GENSCHEME_IF); } else if (isKeySame(nextToken, KEY_FOR)) { type = ARCHSTATE_GENERATE; pointer = parseGenerate(label, GENSCHEME_FOR); } // should be component_instantiation_declaration else { nextToken = label; type = ARCHSTATE_INSTANCE; pointer = parseInstance(); } } // add statement if found if (type != NOARCHSTATE) { Statements newState = new Statements(); newState.type = type; newState.pointer = pointer; newState.next = null; if (endState == null) { statements = endState = newState; } else { endState.next = newState; endState = newState; } } else { reportErrorMsg(nextToken, "Invalid ARCHITECTURAL statement"); nextToken = nextToken.next; break; } } return statements; } /** * Method to parse a component instantiation statement. * It has the form: * component_instantiation_statement :== label : simple_name PORT MAP(actual_port_list); * @return the instance parse tree. */ private VInstance parseInstance() throws ParseException { VInstance inst = null; // check for identifier if (nextToken.token != TOKEN_IDENTIFIER) { reportErrorMsg(nextToken, "Expecting an identifier"); getNextToken(); return inst; } TokenList name = nextToken; getNextToken(); // if colon, previous token was the label if (nextToken.token == TOKEN_COLON) { getNextToken(); } else { nextToken = name; name = null; } // should be at component reference SimpleName entity = parseSimpleName(); // Require PORT MAP if (isKeySame(nextToken, KEY_PORT)) getNextToken(); else reportErrorMsg(nextToken, "Expecting keyword PORT"); if (isKeySame(nextToken, KEY_MAP)) getNextToken(); else reportErrorMsg(nextToken, "Expecting keyword MAP"); // should be at left bracket if (nextToken.token != TOKEN_LEFTBRACKET) { reportErrorMsg(nextToken, "Expecting a left bracket"); } getNextToken(); APortList ports = parseActualPortList(); // should be at right bracket if (nextToken.token != TOKEN_RIGHTBRACKET) { reportErrorMsg(nextToken, "Expecting a right bracket"); } getNextToken(); // should be at semicolon if (nextToken.token != TOKEN_SEMICOLON) { reportErrorMsg(nextToken, "Expecting a semicolon"); } getNextToken(); inst = new VInstance(); inst.name = name; inst.entity = entity; inst.ports = ports; return inst; } /** * Method to parse an actual port list. * It has the form: * actual_port_list ::= port_association {, port_association} * port_association ::= name | OPEN * @return the actual port list structure. */ private APortList parseActualPortList() throws ParseException { APortList lastPort = null; // should be at least one port association APortList apList = new APortList(); apList.type = APORTLIST_NAME; if (nextToken.token != TOKEN_COMMA && nextToken.token != TOKEN_RIGHTBRACKET) { if (isKeySame(nextToken, KEY_OPEN)) { apList.pointer = null; getNextToken(); } else { apList.pointer = parseName(); if (nextToken.token == TOKEN_ARROW) { getNextToken(); apList.pointer = parseName(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -