public static void CheckBlock(AstNode node, Context context) { for (int crutch = 0; crutch < node.ChildCount; crutch++) { //AstNodePrinter.Print(node); Check((AstNode)node.GetChild(crutch), context); AstNodePrinter.Print(node); } }
public static void Main(string[] args) { try { // в зависимости от наличия параметров командной строки разбираем // либо файл с именем, переданным первым параметром, либо стандартный ввод Context context = new Context(null); string src = @" void printInt(int a) { } void printDouble(double a) { } double sqrt(double a) { } double sqr(double a) { } int readInt() { } double readDouble() { } "; //Check(src, context); src = args.Length == 1 ? new StreamReader(args[0]).ReadToEnd() : Console.In.ReadToEnd(); ICharStream input = new ANTLRStringStream(src); MathExprLexer lexer = new MathExprLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); MathExprParser parser = new MathExprParser(tokens); parser.TreeAdaptor = new AstNodeTreeAdapter(); ITree program = (ITree)parser.execute().Tree; AstNodePrinter.Print(program); Console.WriteLine(); SemanticChecker.Check((AstNode)program, context); AstNodePrinter.Print(program); //Console.ReadLine(); AstNodePrinter.Print(program); Console.WriteLine(); string msil = MSILGenerator.GenerateMSIL(program, context); Console.WriteLine(msil); Console.WriteLine(); Console.ReadLine(); } catch (Exception e) { Console.WriteLine("Error: {0}", e); Console.ReadLine(); } }