Skip to content

Commit 6308f3c

Browse files
committed
started debuggin process and work on parser, currently not compyling because of a bug with boost x3 parser that we were unable to fix.
1 parent 7c065f4 commit 6308f3c

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

src/netlist/boolean_function/parser_standard.cpp

+26-18
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace hal
1414
// stores the list of tokens that are generated and filled during the
1515
// parsing process adn the different semantic actions
1616
std::vector<Token> tokens;
17+
std::stringstream name;
1718

1819
////////////////////////////////////////////////////////////////////////
1920
// (1) Semantic actions to generate tokens
@@ -27,29 +28,33 @@ namespace hal
2728
const auto BracketOpenAction = [&tokens](auto& /* ctx */) { tokens.emplace_back(BooleanFunctionParser::Token::BracketOpen()); };
2829
const auto BracketCloseAction = [&tokens](auto& /* ctx */) { tokens.emplace_back(BooleanFunctionParser::Token::BracketClose()); };
2930

30-
const auto VariableAction = [&tokens](auto& ctx) {
31+
const auto VariableStartAction = [&tokens, &name](auto& ctx) {
3132
// # Developer Note
3233
// We combine the first matched character with the remaining
3334
// string and do not remove any preceding '/' character.
34-
std::stringstream name;
35-
name << std::string(1, boost::fusion::at_c<0>(_attr(ctx)));
35+
36+
name.str("");
37+
3638
name << boost::fusion::at_c<1>(_attr(ctx));
39+
name << boost::fusion::at_c<2>(_attr(ctx));
3740

38-
tokens.emplace_back(BooleanFunctionParser::Token::Variable(name.str(), 1));
41+
std::cout << "Start: " << name.str() << std::endl;
3942
};
40-
const auto VariableIndexAction = [&tokens](auto& ctx) {
41-
// # Developer Note
42-
// Since the first character is an optional '\' character and
43-
// generally escaped a.k.a. removed within HAL, we also do not
44-
// touch the part and only assemble the remaining string.
45-
std::stringstream name;
46-
name << std::string(1, boost::fusion::at_c<1>(_attr(ctx)));
43+
const auto VariableBracketAction = [&tokens, &name](auto& ctx) {
44+
name << boost::fusion::at_c<0>(_attr(ctx));
45+
name << boost::fusion::at_c<1>(_attr(ctx));
4746
name << boost::fusion::at_c<2>(_attr(ctx));
4847
name << boost::fusion::at_c<3>(_attr(ctx));
49-
name << boost::fusion::at_c<4>(_attr(ctx));
50-
name << boost::fusion::at_c<5>(_attr(ctx));
48+
49+
std::cout << "Bracket: " << name.str() << std::endl;
50+
};
51+
const auto VariableAction = [&tokens, &name](auto& /*ctx*/) {
52+
std::cout << "Push:" << name.str() << std::endl;
53+
5154
tokens.emplace_back(BooleanFunctionParser::Token::Variable(name.str(), 1));
55+
name.str("");
5256
};
57+
5358
const auto ConstantAction = [&tokens](auto& ctx) {
5459
const auto value = (_attr(ctx) == '0') ? BooleanFunction::Value::ZERO : BooleanFunction::Value::ONE;
5560
tokens.emplace_back(BooleanFunctionParser::Token::Constant({value}));
@@ -69,10 +74,13 @@ namespace hal
6974
const auto BracketOpenRule = x3::lit("(")[BracketOpenAction];
7075
const auto BracketCloseRule = x3::lit(")")[BracketCloseAction];
7176

72-
const auto VariableRule = x3::lexeme[(x3::char_("a-zA-Z") >> *x3::char_("a-zA-Z0-9_"))][VariableAction];
73-
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];
74-
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];
75-
const auto VariableIndexRule = VariableIndexRoundBracketRule | VariableIndexSquareBracketRule;
77+
const auto VariableStartRule = x3::lexeme[(-(x3::char_("\\")) >> x3::char_("a-zA-Z")) >> *x3::char_("a-zA-Z")];
78+
const auto VariableRoundBracketRule = x3::lexeme[(x3::char_("(") >> x3::int_ >> x3::char_(")") >> *x3::char_("a-zA-Z0-9_"))] ;
79+
const auto VariableSquareBracketRule = x3::lexeme[(x3::char_("[") >> x3::int_ >> x3::char_("]") >> *x3::char_("a-zA-Z0-9_"))] [VariableBracketAction];
80+
81+
//const auto VariableRule3 = ;
82+
//const auto VariableRule2 = VariableRule2 ;
83+
const auto VariableRule = (VariableStartRule >> *(VariableRoundBracketRule[VariableBracketAction] | VariableSquareBracketRule[VariableStartAction]))[VariableAction];
7684

7785
const auto ConstantRule = x3::lexeme[x3::char_("0-1")][ConstantAction];
7886
const auto ConstantPrefixRule = x3::lit("0b") >> x3::lexeme[x3::char_("0-1")][ConstantAction];
@@ -85,7 +93,7 @@ namespace hal
8593
////////////////////////////////////////////////////////////////////
8694
// (3) Parsing Expression Grammar
8795
////////////////////////////////////////////////////////////////////
88-
+(AndRule | NotRule | OrRule | XorRule | VariableIndexRule | VariableRule | ConstantSuffixRule | ConstantPrefixRule | ConstantRule | BracketOpenRule | BracketCloseRule),
96+
+(AndRule | NotRule | OrRule | XorRule | VariableRule | ConstantSuffixRule | ConstantPrefixRule | ConstantRule | BracketOpenRule | BracketCloseRule),
8997
x3::space // skips any whitespace in between boolean function
9098
);
9199

tests/netlist/boolean_function.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ namespace hal {
191191
{"(a & bb) | (ccc & dddd)",
192192
(BooleanFunction::Var("a") & BooleanFunction::Var("bb")) | (BooleanFunction::Var("ccc") & BooleanFunction::Var("dddd"))
193193
},
194-
{"A(1) ^ B(1)",
194+
{"A(1) ^ B(1) ",
195195
BooleanFunction::Var("A(1)") ^ BooleanFunction::Var("B(1)")
196196
},
197197
{"!(a ^ a) ^ !(!(b ^ b))",
@@ -208,6 +208,16 @@ namespace hal {
208208
((BooleanFunction::Const(1, 1) & BooleanFunction::Var("O[0]")) & BooleanFunction::Var("c3"))
209209
| (BooleanFunction::Var("RDATA[0]") & (~ BooleanFunction::Var("c3")))
210210
},
211+
{"s4r17_i__[3]__",
212+
(BooleanFunction::Var("s4r17_i__[3]__"))
213+
},
214+
{"(! s4r17_i__[3]__)",
215+
(~BooleanFunction::Var("s4r17_i__[3]__"))
216+
},
217+
// {"((((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]__))",
218+
// (~BooleanFunction::Var("s4r17_i__[3]__"))
219+
// },
220+
211221
////////////////////////////////////////////////////////////////////
212222
// LIBERTY PARSER
213223
////////////////////////////////////////////////////////////////////
@@ -235,6 +245,7 @@ namespace hal {
235245
};
236246

237247
for (const auto& [s, expected] : data) {
248+
std::cout << s << std::endl;
238249
auto function = BooleanFunction::from_string(s);
239250
ASSERT_TRUE(function.is_ok());
240251
ASSERT_EQ(function.get(), expected);

0 commit comments

Comments
 (0)