bool group_tokens_into_statements(evl_statements &statements, evl_tokens &tokens) { for (; !tokens.empty();) { // generate one statement per iteration evl_token token = tokens.front(); evl_token token = tokens.front(); if (token.type != evl_token::NAME) { std::cerr << "Need a NAME token but found '" << token.str << "' on line " << token.line_no << std::endl; return false; } if (token.str == "module") // MODULE statement { evl_statement module; module.type = evl_statement::MODULE; if (!move_tokens_to_statement(module.tokens, tokens)) return false; statements.push_back(module); } else if (token.str == "endmodule") // ENDMODULE statement { evl_statement endmodule; endmodule.type = evl_statement::ENDMODULE; endmodule.tokens.push_back(token); tokens.erase(tokens.begin()); statements.push_back(endmodule); } else if (token.str == "wire") // WIRE statement { evl_statement wire; wire.type = evl_statement::WIRE; if (!move_tokens_to_statement(wire.tokens, tokens)) return false; statements.push_back(wire); } //ASSIGN statement else if (token.str == "assign"){ evl_statement assign; assign.type = evl_statement::ASSIGN; if (!move_tokens_to_statement(assign.tokens, tokens)) return false; statements.push_back(assign); } else // COMPONENT statement { evl_statement component; component.type = evl_statement::COMPONENT; if (!move_tokens_to_statement(component.tokens, tokens)) return false; statements.push_back(component); } } return true; }
bool group_tokens_into_statements(evl_statements &statements, evl_tokens &tokens) { assert(statements.empty()); for(; !tokens.empty();) { //generates one statement per iteration evl_token token = tokens.front(); if (token.type != evl_token::NAME) { std::cerr << "Need a NAME token but found '" << token.str << "' on line" << token.line_no << std::endl; return false; } if ((token.str == "INPUT") || (token.str == "OUTPUT") || (token.str == "AND") || (token.str == "NAND") || (token.str == "OR") || (token.str == "NOR") || (token.str == "DFF") || (token.str == "NOT")) { evl_statement component; component.type = evl_statement::COMPONENT; if(!move_comp_to_statement(component.tokens, tokens)) { return false; } //INPUT and OUTPUT are both components and wires; if ((token.str == "INPUT") || (token.str == "OUTPUT")) { evl_statement wire; wire.type = evl_statement::WIRE; wire.tokens = component.tokens; statements.push_back(wire); } statements.push_back(component); } else { evl_statement wire; wire.type = evl_statement::WIRE; if(!move_wire_to_statement(wire.tokens, tokens)) { return false; } statements.push_back(wire); } } return true; }