public override string Compile(int tabs = 0) { if (assingBlock.Type != Block.BlockType.CLASS) { return(""); } if (isOneNotDefined) { return(""); } if (variable is Variable) { ((Variable)variable).Check(); } if (this.setter is Block) { ((Block)this.setter).variables.Add("value", new Assign(new Variable(new Token(Token.Type.STRING, "value"), assingBlock, ((Variable)variable).GetDateType()), new Token(Token.Type.ASIGN, "="), new Null(), assingBlock)); } string var_name = variable.TryVariable().Value; string tab = DoTabs(tabs + 1); string ret = ""; ret += assingBlock.getClass() + ".prototype.Property$" + var_name + " = {\n"; if (isAutoDefined) { ret += " $value: ''" + (this.setter != null || this.getter != null?",\n":""); } if (this.getter != null) { ret += " get: function(){\n"; if (isAutoDefined) { ret += " return this.$value;\n"; } else { ret += getter.Compile(tabs + 2); } ret += " }" + (this.setter != null?",":"") + "\n"; } if (this.setter != null) { ret += " set: function(value){\n"; if (isAutoDefined) { ret += " this.$value = value;\n"; } else { ret += setter.Compile(tabs + 2); } ret += " }\n"; } ret += "}"; return(ret); }
public override string Compile(int tabs = 0) { string ret = ""; string tab = DoTabs(tabs + 1); expr.endit = false; ret = tab + "while(" + expr.Compile() + "){\n"; ret += block.Compile(tabs + 3); ret += tab + " }"; return(ret); }
public override string Compile(int tabs = 0) { condition.endit = false; return("(" + condition.Compile() + " ? " + left.Compile() + ": " + right.Compile() + ")"); }
public override string Compile(int tabs = 0) { if (right != null) { right.assingBlock = assingBlock; right.endit = false; } left.assingBlock = assingBlock; left.endit = false; if (right is Variable) { ((Variable)right).Check(); } if (left is Variable) { ((Variable)left).Check(); } Variable v = null; string o = Variable.GetOperatorStatic(op.type); if (o == "is") { right = block.SymbolTable.Get(rtok.Value); string vname = left.TryVariable().Value; string classname = right.TryVariable().Value; string rt = ""; if (right is Generic) { rt = "(" + vname + ".constructor.name == this.generic$" + classname + " ? true : false)"; } else { rt = "(" + vname + ".constructor.name == '" + classname + "' ? true : false)"; } outputType = new Token(Token.Type.BOOL, "bool"); return((inParen ? "(" : "") + rt + (inParen ? ")" : "")); } if (left is Number) { v = new Variable(((Number)left).getToken(), block, new Token(Token.Type.CLASS, "int")); var saveOut = outputType; outputType = v.OutputType(op.type, left, right); if (outputType.type == Token.Type.CLASS && outputType.Value == "int") { outputType = saveOut; } } else if (left is CString) { v = new Variable(((CString)left).getToken(), block, new Token(Token.Type.CLASS, "string")); outputType = v.OutputType(op.type, left, right); if (right is UnaryOp ruop) { ruop.isInString = true; } } else if (left is Variable) { v = ((Variable)left); if (v.GetDateType().Value == "auto") { v.Check(); } outputType = ((Variable)left).OutputType(op.type, left, right); } else if (left is UnaryOp leuo) { if (leuo.Op == "call") { if (leuo.usingFunction == null) { leuo.Compile(); } if (leuo.usingFunction != null) { Function f = leuo.usingFunction; outputType = f.Returnt; } } if (leuo.Op == "..") { if (assingBlock?.SymbolTable.Get("Range") != null) { outputType = ((Class)assingBlock?.SymbolTable.Get("Range")).Name; } } if (op.Value == "dot" && right is UnaryOp riuo) { riuo.Block = assingBlock?.SymbolTable.Get(outputType.Value).assingBlock; } else if (op.Value == "dot" && right is Variable riva) { var fnd = assingBlock?.SymbolTable.Get(leuo.OutputType.Value); if (fnd != null && !(fnd is Error)) { Types t = ((Class)fnd).Block.SymbolTable.Get(riva.Value); if (t is Assign ta) { if (ta.Left is Variable tav) { riva.setType(tav.GetDateType()); } } else if (t is Variable tv) { riva.setType(tv.GetDateType()); } outputType = riva.GetDateType(); } } v = left.TryVariable(); } else if (left is BinOp) { left.Compile(); v = left.TryVariable(); } else { left.Compile(); v = left.TryVariable(); } if (((v._class != null && v.class_ == null) || (v.class_ != null && v.class_.JSName != ""))) { if (op.Value == "dot") { return((inParen ? "(" : "") + left.Compile(0) + Variable.GetOperatorStatic(op.type) + right.Compile(0) + (inParen ? ")" : "")); } else { return((inParen ? "(" : "") + left.Compile(0) + " " + Variable.GetOperatorStatic(op.type) + " " + right.Compile(0) + (inParen ? ")" : "")); } } else if (v.class_ != null) { if (op.Value == "dot") { return((inParen ? "(" : "") + left.Compile(0) + "." + right.Compile(0) + (inParen ? ")" : "")); } Types oppq = v.class_.block.SymbolTable.Get("operator " + Variable.GetOperatorNameStatic(op.type)); if (oppq is Error) { return(""); } Function opp = (Function)oppq; if (op.type == Token.Type.NOTEQUAL) { return((inParen ? "(" : "") + "!(" + left.Compile(0) + "." + opp.Name + "(" + right.Compile(0) + "))" + (inParen ? ")" : "")); } else if (op.type == Token.Type.MORE || op.type == Token.Type.LESS) { if (op.type == Token.Type.MORE) { return((inParen ? "(" : "") + left.Compile(0) + "." + opp.Name + "(" + right.Compile(0) + ") > 0" + (inParen ? ")" : "")); } else { return((inParen ? "(" : "") + left.Compile(0) + "." + opp.Name + "(" + right.Compile(0) + ") < 0" + (inParen ? ")" : "")); } } else { return((inParen ? "(" : "") + left.Compile(0) + "." + opp.Name + "(" + right.Compile(0) + ")" + (inParen ? ")" : "")); } } return(""); }
public override string Compile(int tabs = 0) { if (isNormalLambda) { string tbs = DoTabs(tabs); string ret = ""; if (plist.assingToType == null) { plist.assingToType = predicate; } if (plist.assingBlock == null) { plist.assingBlock = assingBlock; } if (plist.assingToToken == null) { plist.assingToToken = assingToToken; } ret += "function(" + plist.Compile() + ")"; expresion.assingToType = this; if (expresion is Block block) { foreach (var v in plist.Parameters) { if (v is Variable va) { va.setType(new Token(Token.Type.CLASS, "object")); block.SymbolTable.Add(va.Value, va); } } ret += "{"; ret += "\n" + expresion.Compile(tabs + 2); ret += tbs + "}"; } else { if (replaceThis != null && expresion is UnaryOp uoe) { uoe.replaceThis = replaceThis; } var res = expresion.Compile(); ret += "{ return " + res + (res[res.Length - 1] == ';' ? "" : ";") + " }"; } return(ret); } else { foreach (var v in plist.Parameters) { if (v is Variable va) { va.setType(new Token(Token.Type.CLASS, "object")); } } if (isInArgumentList) { return("lambda$" + name.Value); } if (isCallInArgument) { return("function(" + plist.Compile() + "){ return " + expresion.Compile() + "; }"); } if (name.Value.Contains(".")) { return(DoTabs(tabs) + "var " + string.Join(".", name.Value.Split('.').Take(name.Value.Split('.').Length - 1)) + ".lambda$" + name.Value.Split('.').Skip(name.Value.Split('.').Length - 1) + " = function(" + plist.Compile() + "){ return " + expresion.Compile() + "; };"); } return(DoTabs(tabs) + "var lambda$" + name.Value + " = function(" + plist.Compile() + "){ return " + expresion.Compile() + "; };"); } }
public override string Compile(int tabs = 0) { string ret = ""; if (source is Variable) { ((Variable)source).Check(); Types to = block.SymbolTable.Get(((Variable)source).GetDateType().Value); if (to is Class && ((Class)to).haveParent("IIterable")) { isIterable = true; className = ((Class)to).Name.Value; } if (to is Interface && ((Interface)to).haveParent("IIterable")) { isIterable = true; className = ((Interface)to).Name.Value; } } if (source is UnaryOp uop && ((UnaryOp)source).Op == "new") { Types to = block.SymbolTable.Get(uop.Name.Value); if (((Class)to).haveParent("IIterable")) { isIterable = true; } className = ((Class)to).Name.Value; } if (source is UnaryOp uoq && ((UnaryOp)source).Op == "call") { Types t1 = block.SymbolTable.Get(uoq.Name.Value); Types to = block.SymbolTable.Get(((Function)t1).Returnt.Value); if (((Class)to).haveParent("IIterable")) { isIterable = true; } className = ((Class)to).Name.Value; } if (source is UnaryOp uor && ((UnaryOp)source).Op == "..") { Types to = block.SymbolTable.Get("Range"); if (((Class)to).haveParent("IIterable")) { isIterable = true; } className = ((Class)to).Name.Value; } if (isIterable) { int tmpc = block.Interpret.tmpcount++; source.endit = false; string tab = DoTabs(tabs); var s = source.Compile(0).Replace("\n", ""); if (s.Substring(s.Length - 1, 1) == ";") { s = s.Substring(0, s.Length - 1); } ret = tab + "var $tmp" + tmpc + " = " + s + ".iterator();\n"; ret += tab + " while($tmp" + tmpc + ".hasNext()){\n"; ret += tab + " var " + variable.Value + " = $tmp" + tmpc + ".next();\n"; ret += block.Compile(tabs + 2); ret += tab + " }"; } return(ret); }