Closed aleksmelnikov closed 4 years ago
Maybe the Program.cs
should be:
using System;
using Hime.Redist; // the namespace for the Hime Runtime
using MathExp; // default namespace for the parser is the grammar's name
namespace TestHime
{
class Program
{
public static void Main(string[] args)
{
// Creates the lexer and parser
MathExpLexer lexer = new MathExpLexer("2 + 3");
MathExpParser parser = new MathExpParser(lexer);
// Executes the parsing
ParseResult result = parser.Parse();
// Prints the produced syntax tree
ASTNode root = result.Root; <-------------------
Print(root, new bool[] {});
}
private static void Print(ASTNode node, bool[] crossings)
{
for (int i = 0; i < crossings.Length - 1; i++)
Console.Write(crossings[i] ? "| " : " ");
if (crossings.Length > 0)
Console.Write("+-> ");
Console.WriteLine(node.ToString());
for (int i = 0; i != node.Children.Count; i++)
{
bool[] childCrossings = new bool[crossings.Length + 1];
Array.Copy(crossings, childCrossings, crossings.Length);
childCrossings[childCrossings.Length - 1] = (i < node.Children.Count - 1);
Print(node.Children[i], childCrossings);
}
}
}
}
Good catch, thanks for reporting this. Interestingly, the longer tutorial looks fine. This should be fixed now.
Yes, with this patch it works fine:
$ dotnet bin/Debug/netcoreapp3.0/TestHime.dll
exp
+-> exp_term
+-> exp_term
| +-> exp_factor
| +-> exp_atom
| +-> NUMBER = 2
+-> + = +
+-> exp_factor
+-> exp_atom
+-> NUMBER = 3
https://cenotelie.fr/projects/hime/tutorials/net-kickstart.html
Step 7 Set the minimal Program.cs:
Step 8 Build the test project: