diff --git a/pya2l/aml.g4 b/pya2l/aml.g4 index 1ab90ee..5cb6126 100644 --- a/pya2l/aml.g4 +++ b/pya2l/aml.g4 @@ -88,11 +88,12 @@ struct_type_name: ; struct_member: - m = member | block_definition ';' + m = member';' ; member: t = type_name (a += array_specifier)* + | b = block_definition ; array_specifier: @@ -106,9 +107,9 @@ taggedstruct_type_name: taggedstruct_member: ts1 = taggedstruct_definition ';' - | '(' ts0 = taggedstruct_definition ')' '*' ';' + | '(' ts0 = taggedstruct_definition ';'? ')' '*' ';' | bl1 = block_definition ';' - | '(' bl0 = block_definition ')' '*' ';' + | '(' bl0 = block_definition ';'? ')' '*' ';' ; taggedstruct_definition: diff --git a/pya2l/aml_parser.cpp b/pya2l/aml_parser.cpp index e8a3d55..f2a1f33 100644 --- a/pya2l/aml_parser.cpp +++ b/pya2l/aml_parser.cpp @@ -12,9 +12,8 @@ using namespace antlr4; void marshal(std::stringstream& ss, const AmlFile& amlf); -const std::string BASE{ "C:/csProjects/" }; -//const std::string BASE{ ""C:/Users/HP/PycharmProjects/" }; - +// const std::string BASE{ "C:/csProjects/" }; +const std::string BASE{ "C:/Users/HP/PycharmProjects/" }; int main(int argc, const char* argv[]) { std::ifstream stream; diff --git a/pya2l/if_data_parser.cpp b/pya2l/if_data_parser.cpp index b7f1a53..6fd56c3 100644 --- a/pya2l/if_data_parser.cpp +++ b/pya2l/if_data_parser.cpp @@ -111,13 +111,13 @@ class IfDataParser { } else if (member) { const auto mem_real = *member; if (mem_real->aml_type() == Node::AmlType::TAGGED_STRUCT_MEMBER) { - const auto& def = mem_real->map().at("DEFINITION"); + const auto& def = mem_real->map().at("DEFINITION"); const auto& [mmultiple, mmember, mtype] = def.member_or_type(); m_grammar.push(*mtype); do_type(); m_grammar.pop(); } - //m_grammar.push(*member); + // m_grammar.push(*member); } m_grammar.pop(); } @@ -141,7 +141,7 @@ class IfDataParser { void struct_type() { const auto tos = top(); - for (const auto& member: tos->get_members()) { + for (const auto& member : tos->get_members()) { auto token = current_token(); if (token) { auto [tp, text] = *token; @@ -153,25 +153,24 @@ class IfDataParser { void tagged_struct_type() { auto token = current_token(); if (token) { - auto [tp, text] = *token; - const auto tos = top(); - const auto& ts_members = tos->get_tagged_struct_members(); + auto [tp, text] = *token; + const auto tos = top(); + const auto& ts_members = tos->get_tagged_struct_members(); const auto& [member, b0, b1] = ts_members.at(text); const auto& [arr_spec, type] = member->get_type(); m_grammar.push(type); consume(); do_type(); m_grammar.pop(); - } } void tagged_union_type() { auto token = current_token(); if (token) { - auto [tp, text] = *token; - const auto tu_member = top()->find_tag(text); - const auto& member = tu_member->map().at("MEMBER"); + auto [tp, text] = *token; + const auto tu_member = top()->find_tag(text); + const auto& member = tu_member->map().at("MEMBER"); const auto& [arr_spec, type] = member.get_type(); m_grammar.push(type); consume(); @@ -181,17 +180,17 @@ class IfDataParser { } void do_type() { - const auto tos = top(); - auto token = current_token(); + const auto tos = top(); + auto token = current_token(); if (token) { auto [type, text] = *token; switch (type) { - case a2llg::BEGIN: - consume(); - block_type(); - break; - default: - std::cerr << "Unknown token type: " << type << std::endl; + case a2llg::BEGIN: + consume(); + block_type(); + break; + default: + std::cerr << "Unknown token type: " << type << std::endl; } } @@ -214,7 +213,7 @@ class IfDataParser { default: std::cerr << "Unknown type: " << std::endl; break; - } + } } void enumeration_type() { @@ -233,134 +232,132 @@ class IfDataParser { token_t m_current_token; }; -const std::string BASE{ "C:/csProjects/" }; -//const std::string BASE{ ""C:/Users/HP/PycharmProjects/" }; - -const std::string CPLX_TEXT{ - "" \ -" /begin IF_DATA ASAP1B_CCP" \ -" /begin SOURCE" \ -" \"segment synchronous event channel\"" \ -" 103" \ -" 1" \ -" /begin QP_BLOB" \ -" 0" \ -" LENGTH 8" \ -" CAN_ID_FIXED 0x330" \ -" FIRST_PID 0" \ -" RASTER 0" \ -" /end QP_BLOB" \ -" /end SOURCE" \ -" " \ -" /begin SOURCE" \ -" \"10ms time synchronous event channel\"" \ -" 4" \ -" 1" \ -" /begin QP_BLOB" \ -" 1" \ -" LENGTH 12" \ -" CAN_ID_FIXED 0x340" \ -" FIRST_PID 8" \ -" RASTER 1" \ -" /end QP_BLOB" \ -" /end SOURCE" \ -" " \ -" /begin SOURCE" \ -" \"100ms time synchronous event channel\"" \ -" 4" \ -" 10" \ -" /begin QP_BLOB" \ -" 2" \ -" LENGTH 8" \ -" CAN_ID_FIXED 0x350" \ -" FIRST_PID 20" \ -" RASTER 2" \ -" /end QP_BLOB" \ -" /end SOURCE" \ -" " \ -" /begin RASTER" \ -" \"segment synchronous event channel\"" \ -" \"seg_sync\"" \ -" 0" \ -" 103" \ -" 1" \ -" /end RASTER" \ -" " \ -" /begin RASTER" \ -" \"10ms time synchronous event channel\"" \ -" \"10_ms\"" \ -" 1" \ -" 4" \ -" 1" \ -" /end RASTER" \ -" " \ -" /begin RASTER" \ -" \"100ms time synchronous event channel\"" \ -" \"100_ms\"" \ -" 2" \ -" 4" \ -" 10" \ -" /end RASTER" \ -" " \ -" /begin SEED_KEY" \ -" \"\"" \ -" \"\"" \ -" \"\"" \ -" /end SEED_KEY" \ -" " \ -" /begin TP_BLOB" \ -" 0x200" \ -" 0x202" \ -" 0x200" \ -" 0x210" \ -" 0x1234" \ -" 1" \ -" " \ -" /begin CAN_PARAM" \ -" 0x3E8" \ -" 0x40" \ -" 0x16" \ -" /end CAN_PARAM" \ -" " \ -" DAQ_MODE BURST" \ -" CONSISTENCY DAQ" \ -" " \ -" /begin CHECKSUM_PARAM " \ -" 0xC001" \ -" 0xFFFFFFFF" \ -" CHECKSUM_CALCULATION ACTIVE_PAGE" \ -" /end CHECKSUM_PARAM " \ -" " \ -" /begin DEFINED_PAGES" \ -" 1" \ -" \"reference page\"" \ -" 0x00" \ -" 0x8E0670" \ -" 0x1C26C" \ -" ROM" \ -" /end DEFINED_PAGES" \ -" " \ -" /begin DEFINED_PAGES" \ -" 2" \ -" \"working page\"" \ -" 0x00" \ -" 0x808E0670" \ -" 0x1C26C" \ -" RAM" \ -" RAM_INIT_BY_ECU" \ -" /end DEFINED_PAGES" \ -" " \ -" OPTIONAL_CMD 0x11 " \ -" OPTIONAL_CMD 0xE " \ -" OPTIONAL_CMD 0x19 " \ -" OPTIONAL_CMD 0x9 " \ -" OPTIONAL_CMD 0xC " \ -" OPTIONAL_CMD 0xD " \ -" OPTIONAL_CMD 0x12 " \ -" OPTIONAL_CMD 0x13 " \ -" /end TP_BLOB" \ -" /end IF_DATA" -}; +// const std::string BASE{ "C:/csProjects/" }; +const std::string BASE{ "C:/Users/HP/PycharmProjects/" }; + +const std::string CPLX_TEXT{ "" + " /begin IF_DATA ASAP1B_CCP" + " /begin SOURCE" + " \"segment synchronous event channel\"" + " 103" + " 1" + " /begin QP_BLOB" + " 0" + " LENGTH 8" + " CAN_ID_FIXED 0x330" + " FIRST_PID 0" + " RASTER 0" + " /end QP_BLOB" + " /end SOURCE" + " " + " /begin SOURCE" + " \"10ms time synchronous event channel\"" + " 4" + " 1" + " /begin QP_BLOB" + " 1" + " LENGTH 12" + " CAN_ID_FIXED 0x340" + " FIRST_PID 8" + " RASTER 1" + " /end QP_BLOB" + " /end SOURCE" + " " + " /begin SOURCE" + " \"100ms time synchronous event channel\"" + " 4" + " 10" + " /begin QP_BLOB" + " 2" + " LENGTH 8" + " CAN_ID_FIXED 0x350" + " FIRST_PID 20" + " RASTER 2" + " /end QP_BLOB" + " /end SOURCE" + " " + " /begin RASTER" + " \"segment synchronous event channel\"" + " \"seg_sync\"" + " 0" + " 103" + " 1" + " /end RASTER" + " " + " /begin RASTER" + " \"10ms time synchronous event channel\"" + " \"10_ms\"" + " 1" + " 4" + " 1" + " /end RASTER" + " " + " /begin RASTER" + " \"100ms time synchronous event channel\"" + " \"100_ms\"" + " 2" + " 4" + " 10" + " /end RASTER" + " " + " /begin SEED_KEY" + " \"\"" + " \"\"" + " \"\"" + " /end SEED_KEY" + " " + " /begin TP_BLOB" + " 0x200" + " 0x202" + " 0x200" + " 0x210" + " 0x1234" + " 1" + " " + " /begin CAN_PARAM" + " 0x3E8" + " 0x40" + " 0x16" + " /end CAN_PARAM" + " " + " DAQ_MODE BURST" + " CONSISTENCY DAQ" + " " + " /begin CHECKSUM_PARAM " + " 0xC001" + " 0xFFFFFFFF" + " CHECKSUM_CALCULATION ACTIVE_PAGE" + " /end CHECKSUM_PARAM " + " " + " /begin DEFINED_PAGES" + " 1" + " \"reference page\"" + " 0x00" + " 0x8E0670" + " 0x1C26C" + " ROM" + " /end DEFINED_PAGES" + " " + " /begin DEFINED_PAGES" + " 2" + " \"working page\"" + " 0x00" + " 0x808E0670" + " 0x1C26C" + " RAM" + " RAM_INIT_BY_ECU" + " /end DEFINED_PAGES" + " " + " OPTIONAL_CMD 0x11 " + " OPTIONAL_CMD 0xE " + " OPTIONAL_CMD 0x19 " + " OPTIONAL_CMD 0x9 " + " OPTIONAL_CMD 0xC " + " OPTIONAL_CMD 0xD " + " OPTIONAL_CMD 0x12 " + " OPTIONAL_CMD 0x13 " + " /end TP_BLOB" + " /end IF_DATA" }; int main() { std::ifstream stream; @@ -379,8 +376,8 @@ int main() { "0x10000\n" "0x1E8\n" "/end IF_DATA"); - //auto lex = IfDataParser(root, TEXT); - auto lex = IfDataParser(root, CPLX_TEXT); + // auto lex = IfDataParser(root, TEXT); + auto lex = IfDataParser(root, CPLX_TEXT); lex.parse();