Skip to content

Commit 98843c4

Browse files
committed
Change prefix to postfix
1 parent b24c640 commit 98843c4

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

BooleanExpressionParser/.vscode/launch.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@
88
"preLaunchTask": "build",
99
"program": "${workspaceFolder}/bin/Debug/net7.0/BooleanExpressionParser.dll",
1010
"args": [
11-
"-o",
12-
"basic",
13-
"table",
11+
// "-o",
12+
// "basic",
13+
// "table",
1414
// "-t ✅",
1515
// "-f ❌",
16-
"A.B+!A",
17-
"A+B+C",
18-
"D_0.D_1",
19-
// "convert",
16+
// "A.B+!A",
17+
// "A+B+C",
18+
// "D_0.D_1",
19+
"convert",
2020
// "A.B",
2121
// "A+B",
22-
// "!(A+B+C)",
22+
"!(A+B+C)",
23+
"A.B",
24+
"(p=>!s) or (!p and !s)"
2325
// "(((A.B&C) OR A) AND (NOT B + !C)) AND NOT D",
2426
// "[D_0 . !S] + [D_1 . S];S,D_0,D_1",
2527
],

BooleanExpressionParser/Formatters/BasicFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public string FormatTokens(IEnumerable<Token> tokens)
1212
foreach (var token in tokens)
1313
{
1414
string s = token.ToString()!;
15-
if (token is not VariableToken && s.Length > 1) s = $"[{s}]";
15+
if (token is not VariableToken && s.Length > 1) s = $"[[{s}]]";
1616
sb.Append(s);
1717
}
1818

BooleanExpressionParser/Formatters/DisplayFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public string FormatTokens(IEnumerable<Token> tokens)
3434
foreach (var token in tokens)
3535
{
3636
string s = token.ToString()!;
37-
if (token is not VariableToken && s.Length > 1) s = $"[{s}]";
37+
if (token is not VariableToken && s.Length > 1) s = $"[[{s}]]";
3838
sb.Append(s);
3939
}
4040

BooleanExpressionParser/Parser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ public Parser()
77
}
88

99
/// <summary>
10-
/// Converts a list of tokens in infix notation to a list of tokens in prefix notation.
10+
/// Converts a list of tokens in infix notation to a list of tokens in postfix notation.
1111
/// </summary>
1212
/// <param name="tokens">The tokens to parse.</param>
1313
/// <returns>The root node of the expression tree.</returns>
14-
public IEnumerable<Token> InfixToPrefix(IEnumerable<Token> tokens)
14+
public IEnumerable<Token> InfixToPostfix(IEnumerable<Token> tokens)
1515
{
1616
var output = new Queue<Token>();
1717
var stack = new Stack<Token>();

BooleanExpressionParser/Program.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ private static void Main(string[] args)
5151
rootCommand.AddCommand(tableCommand);
5252

5353
// Convert command
54-
// Takes in a list of expressions, and converts them to prefix notation.
55-
var convertCommand = new Command("convert", description: "Converts a boolean expression(s) to prefix notation. If none are provided, the user will be prompted to enter them.")
54+
// Takes in a list of expressions, and converts them to postfix notation.
55+
var convertCommand = new Command("convert", description: "Converts a boolean expression(s) to postfix notation. If none are provided, the user will be prompted to enter them.")
5656
{
5757
// outputTypeOption,
5858
expressionsArgument
@@ -88,9 +88,9 @@ private static void TableHandler(OutputType outputType, string @true, string @fa
8888
var infixTokens = tokeniser.Tokenise();
8989

9090
var parser = new Parser();
91-
var prefixTokens = parser.InfixToPrefix(infixTokens);
91+
var postfixTokens = parser.InfixToPostfix(infixTokens);
9292

93-
var ast = parser.GrowAst(prefixTokens, expression.VariableOrder);
93+
var ast = parser.GrowAst(postfixTokens, expression.VariableOrder);
9494

9595
int numCombinations = (int)Math.Pow(2, ast.Variables.Count);
9696
var table = new List<bool[]>();
@@ -131,9 +131,9 @@ private static void ConvertHandler(OutputType outputType, string[] args)
131131
var infixTokens = tokeniser.Tokenise();
132132

133133
var parser = new Parser();
134-
var prefixTokens = parser.InfixToPrefix(infixTokens);
134+
var postfixTokens = parser.InfixToPostfix(infixTokens);
135135

136-
AnsiConsole.MarkupLine($"{expression.Expression} -> [bold]{formatter.FormatTokens(prefixTokens)}[/]");
136+
AnsiConsole.MarkupLine($"{expression.Expression} -> [bold]{formatter.FormatTokens(postfixTokens)}[/]");
137137
}
138138
}
139139

0 commit comments

Comments
 (0)