I am trying to write an MSBuild parser. The conditions are described here .
So, I came up with a grammar that looks fine:
S -> !S
S -> S == S
S -> S != S
S -> S && S
S -> S || S
S -> Fn( str )
S -> str == str
S -> str != str
S -> n < n
S -> n <= n
S -> n > n
S -> n >= n
This is similar to my needs, and I came up with a set of C ++ classes that define this simple language. those. I can create classes to match above, and then I can call “run” in the base expression, and I get a boolean value from the other end.
Using this language, do the following:
(!Exists( "C:\\config.sys" ) && 14 < 17) || (AString == AString2 && HasTrailingSlash( "C:" ))
defined as (and forgive the huge line of code !;)):
Statement baseStatement( new StatementOrStatement( new StatementAndStatement( new NotStatement( new ExistsFunctionStatement( "C:\\Config.sys" ) ), new NumberLessThanNumberStatement( 14.0, 17.0 ) ), new StatementAndStatement( new StringEqualStringStatement( "AString", "AString2" ), new HasTrailingSlashFunctionStatement( "C:\\" ) ) ) );
I can simply run the above statement as follows:
const bool result = baseStatement.Run();
, . , "", , .
. . , . - ++ ? .
, , , .
!