internal STModel GetST(Identifier name) { STModel st = null; if (stMap.TryGetValue(name.Name, out st)) { return(st); } else { BekProgram prog = null; if (bekMap.TryGetValue(name.Name, out prog)) { if (converter == null) //same local functions for all bek programs { converter = BekConverter.MkBekToSTbConverter(solver, prog.ast.funcs, prog.ast.name); } st = converter.Convert(prog).ExploreBools().ToST(); st.Name = name.Name; stMap[name.Name] = st; return(st); } else { throw new QueryParseException(name.Line, name.Pos, string.Format("Undefined transducer: {0}", name)); } } }
/// <summary> /// Converts a given bek program to an STb by using the given solver. /// </summary> /// <param name="solver">given solver</param> /// <param name="pgm">given bek program</param> /// <returns>STb encoding of the bek program</returns> public static STbModel BekToSTb(IContext <FuncDecl, Expr, Sort> solver, BekProgram pgm) { var conv = BekConverter.MkBekToSTbConverter(solver, pgm.ast.funcs, pgm.ast.name); var st = conv.Convert(pgm); return(st); }
/// <summary> /// Converts a given bek program to an ST by using the given solver. /// </summary> /// <param name="solver">given solver</param> /// <param name="bek">given bek program</param> /// <returns>ST encoding of the bek program</returns> public static STModel BekToST(IContext <FuncDecl, Expr, Sort> solver, BekProgram bek) { //use the STb converter to support ite and exception rules var conv = BekConverter.MkBekToSTbConverter(solver, bek.ast.funcs, bek.ast.name); var st = conv.Convert(bek); return(st.ToST()); //flatten the STb rules }
public override STModel Convert(BekProgram a) { expr bek = ((returnstmt)a.ast.body).val; if (bek is replace) { return(ConvertReplace(bek as replace)); } else { return(base.Convert(a)); } }
private void GenerateJavaScript(EvaluationContext ec, BekProgram bekpgm) { var js = new StringBuilder(); var bek = bekpgm.ast; var oldname = bek.name; bek.name = "bek"; bek.GenerateCode("JS", js); bek.name = oldname; string bek_js_master = (ec.bek_js_master_file != "" ? System.IO.File.ReadAllText(ec.bek_js_master_file) : "BEKJSCODE"); string bek_js = bek_js_master.Replace("BEKJSCODE", js.ToString()); System.IO.StreamWriter sw = new System.IO.StreamWriter("c.htm"); sw.WriteLine(bek_js.ToString()); sw.Close(); ec.tw.WriteLine("Generated JavaScript for {0}:", subexpressions[0].ToString()); ec.tw.WriteLine(js); }
public virtual STModel Convert(BekProgram a) { var stringdic = new Dictionary <int, S>(); Func <ident, S> strmapping = x => stringdic[a.stab.Get(x).id]; var ast = a.ast; var inputvar = ast.input; // should be exactly one return; this is checked // earlier so we assume it here var retfilter = new Filter <returnstmt>(); if (ast.body is returnstmt) { returnstmt e = ast.body as returnstmt; return(this.ReturnModel(a, str_handler.Convert(e.val, strmapping, a.stab))); } else { throw new BekException("Bek program not supported."); } }
protected override STModel ReturnModel(BekProgram p, STModel res) { res.Name = p.ast.name; return(res); }
//protected abstract S InputModel(ident i); protected abstract STModel ReturnModel(BekProgram p, S res);