public bool Visit(AST_Root node) { CurrContext = new Contexts(); CurrErrorLoger = new ErrorLoger(); All_Types = SemanticType.BuildAllType(node.class_list); return(node.class_list.Visit(this)); }
public string Visit(AST_Root node) { foreach (var item in node.Children) { item?.Visit(this); } return(""); }
public void AST_Build_test() { string text = @"1+1; (2+4)*3 + 1; true + false -1;"; AST_Root r = BuildAST_Cool.BUILD(text); Assert.IsNotNull(r); Assert.AreEqual(r.Children[0].Children.Count, 3); }
public void AST_If_Else_test() { string text = @"a <- 0; if a = 1 then { a <- 2; } else {a <- 3} fi; a * 2;"; AST_Root r = BuildAST_Cool.BUILD(text); AST_Execute_Interpreter v = new AST_Execute_Interpreter(); Assert.IsNotNull(r); Assert.AreEqual(v.Visit(r), 6); }
public void AST_Asignation_test() { string text = @"b <- 11; a <- b + 2; b <- 1; a + b + 1;"; AST_Root r = BuildAST_Cool.BUILD(text); AST_Execute_Interpreter v = new AST_Execute_Interpreter(); Assert.IsNotNull(r); Assert.AreEqual(v.Visit(r), 15); }
public void AST_STRCte() { string text = "id <- \"string separate space\"; a <- \"other\nstr\n\";"; AST_Root r = BuildAST_Cool.BUILD(text); var v = (AST_StringCte)r.Children[0].Children[0].Children[0]; var v2 = (AST_StringCte)r.Children[0].Children[1].Children[0]; Assert.AreEqual("string separate space", v.ToString()); Assert.AreEqual("other\nstr\n", v2.ToString()); }
public bool Visit(AST_Root node) { All_Types = SemanticType.BuildAllType(node.class_list); CurrErrorLoger = new ErrorLoger(); hs = new HashSet <string>(); var graph = Utils.BuildGraph(All_Types); if (!ACycle(graph)) { return(false); } return(node.class_list.Visit(this)); }
public bool Visit(AST_Root node) { CurrErrorLoger = new ErrorLoger(); Types = new HashSet <string>(); ReservedWords = new HashSet <string>(new List <string>() { "class", "else", "fi", "if", "in", "inherits", "isvoid", "let", "loop", "pool", "then", "while", "case", "esac", "new", "of", "not", "Class", "Else", "Fi", "If", "In", "Inherits", "Isvoid", "Let", "Loop", "Pool", "Then", "While", "Case", "Esac", "New", "Of", "Not", "true", "false", "Int", "Bool", "Object", "String", "IO" }); return(node.class_list.Visit(this)); }
public void AST_While_Fib_test() { string text = @" a <- 0; b <- 1; n <- 2; while n < 9 loop { c <- a + b; a <- b; b <- c; n <- n + 1; } pool; b; "; AST_Root r = BuildAST_Cool.BUILD(text); AST_Execute_Interpreter v = new AST_Execute_Interpreter(); Assert.IsNotNull(r); Assert.AreEqual(v.Visit(r), 21); }
public static CIL_AST_Root Build(AST_Root root) { // SectionTypes var inst = new CILCompiler(); inst.semantictypes = SemanticType.BuildAllType(root.class_list); // SectionData inst.label_data_gen = new GenerateContinuosLabel("str"); inst.Visit(root.class_list); List <CIL_DataElement> listdata = new List <CIL_DataElement>(inst.data.Select(x => new CIL_DataElement(x.Value, x.Key))); foreach (var typ in inst.semantictypes) { var t = typ.Value; bool isbasic = typ.Key != "SELF_TYPE"; foreach (var item in inst.listtypes) { isbasic &= item.Id != typ.Key; } if (!isbasic) { continue; } List <CIL_ClassAttr> lattr = new List <CIL_ClassAttr>(); foreach (var item in t.GetAllAttr()) { lattr.Add(new CIL_ClassAttr(item.Id)); } List <CIL_ClassMethod> lmeth = new List <CIL_ClassMethod>(); if (t.Father != null) { foreach (var item in t.Father.GetAllMethods()) { if (t._find_method(item.Name) == -1) { lmeth.Add(new CIL_ClassMethod(item.Name, item.Label())); } } } foreach (var item in t.Methods) { lmeth.Add(new CIL_ClassMethod(item.Name, item.Label())); } inst.listtypes.Add(new CIL_ClassDef(typ.Key, new CIL_ListNode <CIL_ClassAttr>(lattr), new CIL_ListNode <CIL_ClassMethod>(lmeth))); } // agregar los str types al data foreach (var item in inst.listtypes) { listdata.Add(new CIL_DataElement("type_" + item.Id, item.Id)); } listdata.Add(new CIL_DataElement("error_null", "Null Reference Exception")); listdata.Add(new CIL_DataElement("error_div0", "Divition By Zero Exception")); listdata.Add(new CIL_DataElement("error_indexout", "Index Out Range Exception")); inst.methods.Add(SystemCallGenerator.GeneratePrint()); inst.methods.Add(SystemCallGenerator.GeneratePrintInt()); inst.methods.Add(SystemCallGenerator.Descend()); inst.methods.Add(SystemCallGenerator.Abort()); inst.methods.Add(SystemCallGenerator.TypeName()); inst.methods.Add(SystemCallGenerator.StrLenght()); inst.methods.Add(SystemCallGenerator.StrConcat()); inst.methods.Add(SystemCallGenerator.Copy()); inst.methods.Add(SystemCallGenerator.StrSubstr()); inst.methods.Add(SystemCallGenerator.GenerateReadInt()); inst.methods.Add(SystemCallGenerator.Entry()); return(new CIL_AST_Root(new CIL_SectionData(listdata), new CIL_SectionTypes(inst.listtypes), new CIL_SectionFunction(inst.methods))); }
public Base_Object_Value Visit(AST_Root node) { return(node.Children[0].Visit(this)); }