From 6308f3c443cc09bfb547b089ee24eeac7cfd66d7 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 5 Dec 2022 22:23:56 +0100 Subject: [PATCH] started debuggin process and work on parser, currently not compyling because of a bug with boost x3 parser that we were unable to fix. --- .../boolean_function/parser_standard.cpp | 44 +++++++++++-------- tests/netlist/boolean_function.cpp | 13 +++++- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/netlist/boolean_function/parser_standard.cpp b/src/netlist/boolean_function/parser_standard.cpp index 6feb0c13e3e..561146a2482 100644 --- a/src/netlist/boolean_function/parser_standard.cpp +++ b/src/netlist/boolean_function/parser_standard.cpp @@ -14,6 +14,7 @@ namespace hal // stores the list of tokens that are generated and filled during the // parsing process adn the different semantic actions std::vector tokens; + std::stringstream name; //////////////////////////////////////////////////////////////////////// // (1) Semantic actions to generate tokens @@ -27,29 +28,33 @@ namespace hal const auto BracketOpenAction = [&tokens](auto& /* ctx */) { tokens.emplace_back(BooleanFunctionParser::Token::BracketOpen()); }; const auto BracketCloseAction = [&tokens](auto& /* ctx */) { tokens.emplace_back(BooleanFunctionParser::Token::BracketClose()); }; - const auto VariableAction = [&tokens](auto& ctx) { + const auto VariableStartAction = [&tokens, &name](auto& ctx) { // # Developer Note // We combine the first matched character with the remaining // string and do not remove any preceding '/' character. - std::stringstream name; - name << std::string(1, boost::fusion::at_c<0>(_attr(ctx))); + + name.str(""); + name << boost::fusion::at_c<1>(_attr(ctx)); + name << boost::fusion::at_c<2>(_attr(ctx)); - tokens.emplace_back(BooleanFunctionParser::Token::Variable(name.str(), 1)); + std::cout << "Start: " << name.str() << std::endl; }; - const auto VariableIndexAction = [&tokens](auto& ctx) { - // # Developer Note - // Since the first character is an optional '\' character and - // generally escaped a.k.a. removed within HAL, we also do not - // touch the part and only assemble the remaining string. - std::stringstream name; - name << std::string(1, boost::fusion::at_c<1>(_attr(ctx))); + const auto VariableBracketAction = [&tokens, &name](auto& ctx) { + name << boost::fusion::at_c<0>(_attr(ctx)); + name << boost::fusion::at_c<1>(_attr(ctx)); name << boost::fusion::at_c<2>(_attr(ctx)); name << boost::fusion::at_c<3>(_attr(ctx)); - name << boost::fusion::at_c<4>(_attr(ctx)); - name << boost::fusion::at_c<5>(_attr(ctx)); + + std::cout << "Bracket: " << name.str() << std::endl; + }; + const auto VariableAction = [&tokens, &name](auto& /*ctx*/) { + std::cout << "Push:" << name.str() << std::endl; + tokens.emplace_back(BooleanFunctionParser::Token::Variable(name.str(), 1)); + name.str(""); }; + const auto ConstantAction = [&tokens](auto& ctx) { const auto value = (_attr(ctx) == '0') ? BooleanFunction::Value::ZERO : BooleanFunction::Value::ONE; tokens.emplace_back(BooleanFunctionParser::Token::Constant({value})); @@ -69,10 +74,13 @@ namespace hal const auto BracketOpenRule = x3::lit("(")[BracketOpenAction]; const auto BracketCloseRule = x3::lit(")")[BracketCloseAction]; - const auto VariableRule = x3::lexeme[(x3::char_("a-zA-Z") >> *x3::char_("a-zA-Z0-9_"))][VariableAction]; - const auto VariableIndexRoundBracketRule = x3::lexeme[(-(x3::char_("\\")) >> x3::char_("a-zA-Z") >> *x3::char_("a-zA-Z0-9_") >> x3::char_("(") >> x3::int_ >> x3::char_(")"))] [VariableIndexAction]; - const auto VariableIndexSquareBracketRule = x3::lexeme[(-(x3::char_("\\")) >> x3::char_("a-zA-Z") >> *x3::char_("a-zA-Z0-9_") >> x3::char_("[") >> x3::int_ >> x3::char_("]"))] [VariableIndexAction]; - const auto VariableIndexRule = VariableIndexRoundBracketRule | VariableIndexSquareBracketRule; + const auto VariableStartRule = x3::lexeme[(-(x3::char_("\\")) >> x3::char_("a-zA-Z")) >> *x3::char_("a-zA-Z")]; + const auto VariableRoundBracketRule = x3::lexeme[(x3::char_("(") >> x3::int_ >> x3::char_(")") >> *x3::char_("a-zA-Z0-9_"))] ; + const auto VariableSquareBracketRule = x3::lexeme[(x3::char_("[") >> x3::int_ >> x3::char_("]") >> *x3::char_("a-zA-Z0-9_"))] [VariableBracketAction]; + + //const auto VariableRule3 = ; + //const auto VariableRule2 = VariableRule2 ; + const auto VariableRule = (VariableStartRule >> *(VariableRoundBracketRule[VariableBracketAction] | VariableSquareBracketRule[VariableStartAction]))[VariableAction]; const auto ConstantRule = x3::lexeme[x3::char_("0-1")][ConstantAction]; const auto ConstantPrefixRule = x3::lit("0b") >> x3::lexeme[x3::char_("0-1")][ConstantAction]; @@ -85,7 +93,7 @@ namespace hal //////////////////////////////////////////////////////////////////// // (3) Parsing Expression Grammar //////////////////////////////////////////////////////////////////// - +(AndRule | NotRule | OrRule | XorRule | VariableIndexRule | VariableRule | ConstantSuffixRule | ConstantPrefixRule | ConstantRule | BracketOpenRule | BracketCloseRule), + +(AndRule | NotRule | OrRule | XorRule | VariableRule | ConstantSuffixRule | ConstantPrefixRule | ConstantRule | BracketOpenRule | BracketCloseRule), x3::space // skips any whitespace in between boolean function ); diff --git a/tests/netlist/boolean_function.cpp b/tests/netlist/boolean_function.cpp index de04a1225be..cf67c9b6364 100644 --- a/tests/netlist/boolean_function.cpp +++ b/tests/netlist/boolean_function.cpp @@ -191,7 +191,7 @@ namespace hal { {"(a & bb) | (ccc & dddd)", (BooleanFunction::Var("a") & BooleanFunction::Var("bb")) | (BooleanFunction::Var("ccc") & BooleanFunction::Var("dddd")) }, - {"A(1) ^ B(1)", + {"A(1) ^ B(1) ", BooleanFunction::Var("A(1)") ^ BooleanFunction::Var("B(1)") }, {"!(a ^ a) ^ !(!(b ^ b))", @@ -208,6 +208,16 @@ namespace hal { ((BooleanFunction::Const(1, 1) & BooleanFunction::Var("O[0]")) & BooleanFunction::Var("c3")) | (BooleanFunction::Var("RDATA[0]") & (~ BooleanFunction::Var("c3"))) }, + {"s4r17_i__[3]__", + (BooleanFunction::Var("s4r17_i__[3]__")) + }, + {"(! s4r17_i__[3]__)", + (~BooleanFunction::Var("s4r17_i__[3]__")) + }, + // {"((((0b0 | ((((0b1 & (! s2r_RNI7LA61(0))) & (! s4r17_i__[3]__)) & (! s2d2r(0)__[3]__)) & s2r(16)__[3]__)) | ((((0b1 & s2r_RNI7LA61(0)) & (! s4r17_i__[3]__)) & (! s2d2r(0)__[3]__)) & s2r(16)__[3]__)) | ((((0b1 & (! s2r_RNI7LA61(0))) & s4r17_i__[3]__) & (! s2d2r(0)__[3]__)) & s2r(16)__[3]__)) | ((((0b1 & (! s2r_RNI7LA61(0))) & (! s4r17_i__[3]__)) & s2d2r(0)__[3]__) & s2r(16)__[3]__))", + // (~BooleanFunction::Var("s4r17_i__[3]__")) + // }, + //////////////////////////////////////////////////////////////////// // LIBERTY PARSER //////////////////////////////////////////////////////////////////// @@ -235,6 +245,7 @@ namespace hal { }; for (const auto& [s, expected] : data) { + std::cout << s << std::endl; auto function = BooleanFunction::from_string(s); ASSERT_TRUE(function.is_ok()); ASSERT_EQ(function.get(), expected);