public static AstNode Check(string src, Context context) { ICharStream input = new ANTLRStringStream(src); MathExprLexer lexer = new MathExprLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); MathExprParser parser = new MathExprParser(tokens); parser.TreeAdaptor = new AstNodeTreeAdapter(); AstNode program = (AstNode)parser.execute().Tree; SemanticChecker.Check((AstNode)program, context); return(program); }
public void ReturnFromValue(AstNode node) { AstNode tempNode = node; int count = 0; SimpleDataType = SemanticChecker.strToDataType(tempNode.Text); while (tempNode.ChildCount > 0) { count++; tempNode = (AstNode)tempNode.GetChild(0); } ArrayCount = count; }
public override string ToString() { string result = base.ToString(); if (ODataType.SimpleDataType != DataType.Void) { result += ", " + SemanticChecker.dataTypeToStr(ODataType.SimpleDataType); } if (ODataType.ArrayCount != 0) { result += ", " + Convert.ToString(ODataType.ArrayCount); } return(result); }
public void ReturnFromType(AstNode node) { AstNode tempNode = node; int count = 0; while (tempNode.ChildCount > 0) { count++; tempNode = (AstNode)tempNode.GetChild(0); } ArrayCount = count - 1; alength = Convert.ToInt32(node.GetChild(1).Text); SimpleDataType = SemanticChecker.strToDataType(tempNode.Text); //return null; }
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(); } }