/// <summary> /// Flattens the result of the linearization /// </summary> /// <param name="v">LinTriple to flatten</param> /// <returns>List of flattened strings</returns> private List<string> RenderLin(LinTriple v) { List<string> rez = new List<string>(); List<List<BracketedToken>> vtemp = v.LinTable; string after = string.Empty; for (int k = vtemp.ElementAt(0).Count - 1; k >= 0; k--) { rez.AddRange(this.Untokn(vtemp.ElementAt(0).ElementAt(k), after)); after = rez.Last(); } rez.Reverse(); return rez; }
/// <summary> /// Main Linearization function /// </summary> /// <param name="xs">list of bound variables (from lambdas)</param> /// <param name="ys">list of strings?</param> /// <param name="mbcty">Concrete type</param> /// <param name="mbfid">Function id</param> /// <param name="tree">Tree to linearize</param> /// <returns>List of all possible linearized tuples</returns> private List<LinTriple> Lin0(List<string> xs, List<string> ys, ConcreteType mbcty, int mbfid, Tree tree) { // if tree is a lambda, we add the variable to the list of bound // variables and we linearize the subtree. if (tree is Lambda) { xs.Add(((Lambda)tree).Ident_); List<LinTriple> tmp = this.Lin0(xs, ys, mbcty, mbfid, ((Lambda)tree).Tree_); return tmp; } else if (xs.Count == 0) { List<Tree> es = new List<Tree>(); if (tree is Application) { do { es.Add(((Application)tree).Tree_2); tree = ((Application)tree).Tree_1; } while (tree is Application); } if (tree is Function) { return this.Apply(xs, mbcty, mbfid, ((Function)tree).Ident_, es); } else if (tree is Trees.Absyn.Literal) { // TODO check if correct? var lit = (Trees.Absyn.Literal)tree; string token = "?"; if (lit.Lit_ is FloatLiteral) { token = ((FloatLiteral)lit.Lit_).Double_.ToString(CultureInfo.InvariantCulture); } else if (lit.Lit_ is IntLiteral) { token = ((IntLiteral)lit.Lit_).Integer_.ToString(CultureInfo.InvariantCulture); } else if (lit.Lit_ is StringLiteral) { token = ((StringLiteral)lit.Lit_).String_; } string[] tokens = { token }; List<BracketedToken> bt = new List<BracketedToken>() { new LeafKS(tokens) }; List<List<BracketedToken>> btt = new List<List<BracketedToken>>() { bt }; LinTriple lt = new LinTriple(mbfid, mbcty, btt); List<LinTriple> llt = new List<LinTriple>() { lt }; return llt; } else { throw new LinearizerException("Undefined construction for expressions !!!"); } } else { xs.AddRange(ys); List<Tree> exprs = new List<Tree> { tree }; foreach (string str in xs) { exprs.Add(new Trees.Absyn.Literal(new StringLiteral(str))); } return this.Apply(xs, mbcty, mbfid, "_B", exprs); } }