internal abstract void CheckTransformation(HashSet<string> subs, AlphabetDef domAlph, AlphabetDef rangeAlph, FastPgm pgm);
internal abstract void BTECheckSorts(Dictionary<string, Def> defs, FastPgm pgm);
/// <summary> /// Generate a FastTransducerInstance from a Fast program /// </summary> /// <param name="fpg">the fast program</param> public static FastTransducerInstance MkFastTransducerInstance(FastPgm fpg) { return MkFastTransducerInstance(fpg, Console.Out, LogLevel.Normal); }
internal override void CheckFunctionExpr(Dictionary<string, FastSort> vars, HashSet<string> attrNames, HashSet<string> patternTrees, FastPgm pgm) { //Check whether the current tree name is bounded if (!patternTrees.Contains(this.treeNodeName.text)) throw new FastParseException(treeNodeName.Location, string.Format("unexpected tree identifier '{0}'", treeNodeName.text)); //Check whether the current tree name has any of these attributes if (!attrNames.Contains(token.text)) throw new FastParseException(token.Location, string.Format("the tree '{0}' does not have an attribute '{0}'", treeNodeName.text, token.text)); if (_sort == null) _sort = vars[token.text]; else if (!_sort.name.text.Equals(vars[token.text].name)) throw new FastParseException(token.Location, string.Format("unexpected sort '{1}' of '{0}', expecting '{2}'", token.text, _sort.name, vars[token.text].name)); }
internal override void CheckTransformation(HashSet<string> subs, AlphabetDef domAlph, AlphabetDef rangeAlph, FastPgm pgm) { if (subs.Contains(this.token.text)) { _sort = domAlph.sort; } else { //Check if the current variable is a constant FastSort s; foreach (var def in pgm.defs) { if (def.kind == DefKind.Const && ((ConstDef)def).id.text == this.token.text) { s = ((ConstDef)def).sort; if (s == null || (_sort != null && s.name.text != _sort.name.text)) throw new FastParseException(token.Location, string.Format("unexpected identifier '{0}'", token.text)); _sort = s; return; } } //Oterwise look for attr symbol if (Array.Exists(rangeAlph.symbols.ToArray(), x => x.name.text == this.token.text)) throw new FastParseException(this.token.Location, string.Format("the constructor '{0}' is not applied to a tuple", this.token.text)); if (domAlph == null) throw new FastParseException(this.token.Location, string.Format("the variable '{0}' is not defined", this.token.text)); s = domAlph.attrSort.getSort(this.token); if (s == null || (_sort != null && s.name.text != _sort.name.text)) throw new FastParseException(token.Location, string.Format("unexpected identifier '{0}'", token.text)); _sort = s; } }
internal override void CheckFunctionExpr(Dictionary<string, FastSort> vars, HashSet<string> attrNames, HashSet<string> patternTrees, FastPgm pgm) { foreach (var expr in args) expr.CheckFunctionExpr(vars, attrNames, patternTrees, pgm); //check standard operations, allow no other ops bool ok = CheckStandardOps(vars); if (!ok) throw new FastParseException(func.name.Location, string.Format("unknown function '{0}'", func.name)); }
internal override void CheckTransformation(HashSet<string> subs, AlphabetDef domAlph, AlphabetDef rangeAlph, FastPgm pgm) { foreach (var expr in args) expr.CheckTransformation(subs, domAlph, rangeAlph, pgm); var constsAndFuns = new Dictionary<string, FastSort>(); foreach (var def in pgm.defs) { if (def.kind == DefKind.Function) constsAndFuns.Add(((FunctionDef)def).name.text, ((FunctionDef)def).sort); if (def.kind == DefKind.Const) constsAndFuns.Add(((ConstDef)def).name.text, ((ConstDef)def).sort); } bool ok = CheckStandardOps(constsAndFuns); if (!ok) { string f = func.name.text; if (this is RecordExp) // --- record constrctor --- { if (rangeAlph.attrSort.fields.Count != args.Count) throw new FastParseException(func.name.Location, string.Format("unxecpected nr of attribute fields {0}, expecting {1}", args.Count, rangeAlph.attrSort.fields.Count)); for (int i = 0; i < args.Count; i++) { if (args[i].sort.name.text != rangeAlph.attrSort.fields[i].Value.name.text) throw new FastParseException(args[i].sort.name.Location, string.Format("invalid argument sort '{0}' of field '{1}', expecting sort '{2}'", args[i].sort.name.text, rangeAlph.attrSort.fields[i].Key.text, rangeAlph.attrSort.fields[i].Value.name.text)); } _sort = rangeAlph.attrSort; } else if (rangeAlph.symbols.Exists(_f => func.name.text == _f.name.text)) // --- tree constructor --- { if (!rangeAlph.IsValidSymbol(func.name, func.arity)) { throw new FastParseException(func.name.Location, string.Format("wrong number of arguments of constructor '{0}'", func.name)); } for (int i = 1; i < args.Count; i++) { if (args[i].sort.name.text != rangeAlph.id.text) throw new FastParseException(func.name.Location, string.Format("unexected argument of function '{0}'", func.name)); } _sort = rangeAlph.sort; } else { var def = pgm.FindDef(func.name); if (def.kind == DefKind.Trans) { if (args.Count != 1) throw new FastParseException(func.name.Location, string.Format("transduction '{0}' is unary", func.name)); var tdef = def as TransDef; if (tdef.domain.name.text != args[0].sort.name.text) throw new FastParseException(args[0].sort.name.Location, string.Format("transduction '{0}' has unexpected argument of sort '{1}', expecting sort '{2}'", func.name, args[0].sort.name.text, tdef.domain.name.text)); _sort = tdef.range; isTranDef = true; if (args[0].kind == FExpKind.App) throw new FastParseException(func.name.Location, string.Format("Transduction '{0}' cannot be nested inside another Transduction", func.name)); } else { throw new FastParseException(func.name.Location, string.Format("ID '{0}' is not a Transduction", func.name)); } } } }
internal override void BTECheckSorts(Dictionary<string, Def> defs, FastPgm pgm) { //Check wheter the variable is defined if (!defs.ContainsKey(func.name.text)) throw new FastParseException(func.name.Location, string.Format("undefined name '{0}'", func.name.text)); var def = defs[func.name.text]; if (def is TransDef) { var defCast = def as TransDef; //Set to public if forgot defCast.isPublic = true; this.domain = defCast.domain; this.range = defCast.range; } else { if (def is TransDefDef) { var defCast = def as TransDefDef; this.domain = defCast.domain; this.range = defCast.range; } else throw new FastParseException(func.name.Location, string.Format("the name '{0}' does not define a transformation", func.name.text)); } }
internal override void Typecheck(FastPgm pgm) { var domAlph = pgm.FindAlphabetDef(domain.name); string dom = "", ran = ""; var defs = new Dictionary<string, Def>(); bool skipNextDef = false; foreach (var d in pgm.defs) { if (d.id.text == func.name.text) skipNextDef = true; else if (!skipNextDef) defs[d.id.text] = d; else if (d.kind != DefKind.Def) defs[d.id.text] = d; } transducer.BTECheckSorts(defs, pgm); dom = transducer.domain.name.text; ran = transducer.range.name.text; if (ran != domain.name.text) throw new FastParseException(domain.name.Location, string.Format("wrong range '{1}' of '{0}'", transducer, domain.name.text)); var subs = new HashSet<string>(); if (expr.kind != FExpKind.Var) expr.CheckTransformation(subs, null, domAlph, pgm); else { foreach (var d in pgm.defs) { if ((expr as Variable).token.text == d.id.text) { if (d.kind == DefKind.Def && (d as DefDef).ddkind == DefDefKind.Tree) { if ((d as TreeDef).domain.name.text != dom) throw new FastParseException(expr.token.Location, string.Format("'{0}' does not have domain '{1}'", expr.token.text, dom)); return; } else throw new FastParseException(expr.token.Location, string.Format("'{0}' is not a tree", expr.token.text)); } } throw new FastParseException(expr.token.Location, string.Format("expression '{0}' is undefined", expr.token.text)); } }
internal override void Typecheck(FastPgm pgm) { }
internal override void Typecheck(FastPgm pgm) { var rangeAlph = pgm.FindAlphabetDef(range.name); var domAlph = pgm.FindAlphabetDef(domain.name); var defs = new Dictionary<string, Def>(); bool skipNextDef = false; foreach (var d in pgm.defs) { if (d.id.text == func.name.text) skipNextDef = true; else if (!skipNextDef) defs[d.id.text] = d; else if (d.kind != DefKind.Def) defs[d.id.text] = d; } expr.BTECheckSorts(defs, pgm); //Check that type of expr is same as type of signature if (expr.domain.name.text != domain.name.text) throw new FastParseException(expr.func.name.Location, string.Format("'{0}' has domain '{1}' but the inside expression has domain '{2}'", func.name.text, domain.name.text, expr.domain.name.text)); if (expr.range.name.text != range.name.text) throw new FastParseException(expr.func.name.Location, string.Format("'{0}' has range '{1}' but the inside expression has range '{2}'", func.name.text, range.name.text, expr.range.name.text)); }
internal override void Typecheck(FastPgm pgm) { AlphabetDef adef = pgm.FindAlphabetDef(domain.name); foreach (var c in cases) { Func<FastToken, FastSort> context = x => { if (treeMatchName != null && x.text.Equals(this.treeMatchName.name.text)) return domain; if (c.pat.Contains(x.text)) return adef.sort; else return adef.attrSort.getSort(x); }; if (!adef.IsValidSymbol(c.pat.symbol, c.pat.children.Count + 1)) throw new FastParseException(c.pat.symbol.Location, string.Format("Symbol '{0}' of rank {1} does not exist in alphabet '{2}'", c.pat.symbol.text, c.pat.children.Count, domain.name.text)); c.where.CalcSort(context, pgm); foreach (var g in c.given) { g.CalcSort(context, pgm); if (g.sort.kind != FastSortKind.Bool) throw new FastParseException(g.token.Location, string.Format("Wrong sort '{0}', expecting 'bool'", g.sort.name.text)); } if (c.to != null) { if (this.range == null) throw new FastException(FastExceptionKind.InternalError); AlphabetDef range_adef = pgm.FindAlphabetDef(this.range.name); //sets sorts of constructor symbols of the output alphabet c.to.SetConstructorSort(range_adef);//??? c.to.CalcSort(context, pgm); if (!range.name.text.Equals(c.to.sort.name.text)) throw new FastParseException(c.to.token.Location, string.Format("Wrong target sort '{0}', expecting '{1}'", c.to.sort.name.text, range.name.text)); } } }
internal override void CalcSort(Func<FastToken, FastSort> context, FastPgm program) { foreach (var arg in this.args) arg.CalcSort(context, program); if (func.alph != null) //func is a costructor { if (args.Count != func.arity) throw new FastParseException(func.name.Location, string.Format("Invalid use of constructor '{0}' of alphabet '{1}', wrong nr of arguments", func.name.text, func.alph.sort)); if (!args[0].sort.Equals(func.alph.attrSort)) throw new FastParseException(func.name.Location, string.Format("Invalid use of constructor '{0}' of alphabet '{1}', wrong attribute sort", func.name.text, func.alph.sort)); for (int i = 1; i < args.Count; i++) if (!args[i].sort.Equals(func.alph.sort)) throw new FastParseException(func.name.Location, string.Format("Invalid use of constructor '{0}' of alphabet '{1}', subtree nr {2} has unexpected sort '{3}'", func.name.text, func.alph.sort, i, args[i].sort)); _sort = func.alph.sort; return; } switch (func.name.Kind) { case (Tokens.EQ): case (Tokens.NE): { if (this.args.Count != 2) throw new FastParseException(func.name.Location, "Wrong nr of arguments, expecting 2 arguments"); if (!args[0].sort.name.text.Equals(args[1].sort.name.text)) throw new FastParseException(func.name.Location, "Both arguments must have the same sort"); _sort = FastSort.Bool; break; } case (Tokens.LE): case (Tokens.GE): case (Tokens.LT): case (Tokens.GT): { if (this.args.Count != 2) throw new FastParseException(func.name.Location, "Wrong nr of arguments, expecting 2 arguments"); if (!args[0].sort.name.text.Equals(args[1].sort.name.text)) throw new FastParseException(func.name.Location, "Both arguments must have the same sort"); if (!(args[0].sort.kind == FastSortKind.Char || args[0].sort.kind == FastSortKind.Int || args[0].sort.kind == FastSortKind.Real)) throw new FastParseException(func.name.Location, "Arguments have wrong sort, expecting numeric sort"); _sort = FastSort.Bool; break; } case (Tokens.AND): case (Tokens.OR): case (Tokens.IMPLIES): { if (this.args.Count != 2) throw new FastParseException(func.name.Location, "Wrong nr of arguments, expecting 2 arguments"); if (!args[0].sort.name.text.Equals(args[1].sort.name.text)) throw new FastParseException(func.name.Location, "Both arguments must have the same sort"); if (!(args[0].sort.kind == FastSortKind.Bool)) throw new FastParseException(func.name.Location, "Arguments must be Boolean"); _sort = FastSort.Bool; break; } case (Tokens.PLUS): case (Tokens.MINUS): case (Tokens.TIMES): case (Tokens.DIV): { if (this.args.Count != 2) throw new FastParseException(func.name.Location, "Wrong nr of arguments, expecting 2 arguments"); if (!args[0].sort.name.text.Equals(args[1].sort.name.text)) throw new FastParseException(func.name.Location, "Both arguments must have the same sort"); if (!(args[0].sort.kind == FastSortKind.Char || args[0].sort.kind == FastSortKind.Int || args[0].sort.kind == FastSortKind.Real)) throw new FastParseException(func.name.Location, "Wrong argument sorts"); _sort = args[0].sort; break; } case (Tokens.MOD): case (Tokens.SHL): case (Tokens.SHR): case (Tokens.BVAND): case (Tokens.BAR): case (Tokens.BVXOR): { if (this.args.Count != 2) throw new FastParseException(func.name.Location, "Wrong nr of arguments, expecting 2 arguments"); if (!args[0].sort.name.text.Equals(args[1].sort.name.text)) throw new FastParseException(func.name.Location, "Both arguments must have the same sort"); if (!(args[0].sort.kind == FastSortKind.Char || args[0].sort.kind == FastSortKind.Int)) throw new FastParseException(func.name.Location, "Wrong argument sorts"); _sort = args[0].sort; break; } case (Tokens.NOT): { if (this.args.Count != 1) throw new FastParseException(func.name.Location, "Wrong nr of arguments, expecting 1 argument"); if (!(args[0].sort.kind == FastSortKind.Bool)) throw new FastParseException(func.name.Location, string.Format("Wrong argument sort, expecting '{0}'",FastSort.Bool.name.text)); _sort = args[0].sort; break; } case (Tokens.BVNOT): { if (this.args.Count != 1) throw new FastParseException(func.name.Location, "Wrong nr of arguments, expecting 1 argument"); if (!(args[0].sort.kind == FastSortKind.Char || args[0].sort.kind == FastSortKind.Int)) throw new FastParseException(func.name.Location, "Wrong argument sort, expecting 'char' or 'int'"); _sort = args[0].sort; break; } case (Tokens.COMPLEMENT): { if (this.args.Count != 1) throw new FastParseException(func.name.Location, "Wrong nr of arguments, expecting 1 argument"); if (!(args[0].sort.kind == FastSortKind.Tree)) throw new FastParseException(func.name.Location, "Wrong argument sort, expecting a tree sort"); _sort = args[0].sort; break; } case (Tokens.INTERSECT): case (Tokens.UNION): { if (this.args.Count != 2) throw new FastParseException(func.name.Location, "Wrong nr of arguments, expecting 2 arguments"); if (!(args[0].sort.kind == FastSortKind.Tree && args[1].sort.kind == FastSortKind.Tree)) throw new FastParseException(func.name.Location, "Wrong argument sort, expecting a tree sort"); if (!(args[0].sort.name.Equals(args[1].sort.name))) throw new FastParseException(func.name.Location, "Both arguments must have the same tree sort"); _sort = args[0].sort; break; } case (Tokens.EQ_LANG): { if (this.args.Count != 2) throw new FastParseException(func.name.Location, "Wrong nr of arguments, expecting 2 arguments"); if (!(args[0].sort.kind == FastSortKind.Tree && args[1].sort.kind == FastSortKind.Tree)) throw new FastParseException(func.name.Location, "Wrong argument sort, expecting a tree sort"); if (!(args[0].sort.name.Equals(args[1].sort.name))) throw new FastParseException(func.name.Location, "Both arguments must have the same tree sort"); _sort = FastSort.Bool; break; } case (Tokens.ITE): { if (this.args.Count != 3) throw new FastParseException(func.name.Location, "Wrong nr of arguments of If-Then-Else expression, expecting 3 arguments"); if (!(args[0].sort.kind == FastSortKind.Bool)) throw new FastParseException(func.name.Location, string.Format("If-Then-Else condition has wrong sort '{0}' expecting '{1}'", args[0].sort.name.text, FastSort.Bool.name.text)); if (!(args[1].sort.name.text.Equals(args[2].sort.name.text))) throw new FastParseException(func.name.Location, string.Format("If-Then-Else true and false cases have different sorts '{0}' and '{1}' but must have the same sort", args[1].sort.name.text, args[2].sort.name.text)); _sort = args[1].sort; break; } case (Tokens.ID): { var fdef = program.FindDef(func.name); var tdef = fdef as TransDef; if (tdef != null) { if (1 != args.Count) throw new FastParseException(func.name.Location, string.Format("Transduction '{0}' arity is 1 not {2}", func.name.text, 1, args.Count)); if (!args[0].sort.Equals(tdef.domain)) throw new FastParseException(func.name.Location, string.Format("Transduction '{0}' has domain '{0}' not '{1}'", func.name.text, tdef.domain, args[0].sort)); _sort = tdef.range; isTranDef = true; } else { var ldef = fdef as LangDef; if (ldef != null) { if (1 != args.Count) throw new FastParseException(func.name.Location, string.Format("Acceptor '{0}' arity is 1 not {2}", func.name.text, 1, args.Count)); if (!args[0].sort.Equals(ldef.domain)) throw new FastParseException(func.name.Location, string.Format("Acceptor '{0}' has domain '{0}' not '{1}'", func.name.text, ldef.domain, args[0].sort)); _sort = FastSort.Bool; isLangDef = true; } else { FunctionDef d = fdef as FunctionDef; if (d == null) throw new FastParseException(func.name.Location, string.Format("Unexpected ID '{0}' ", func.name.text)); if (d.inputVariables.Count != args.Count) throw new FastParseException(func.name.Location, string.Format("Function '{0}' arity is {1} not {2}", func.name.text, d.inputVariables.Count, args.Count)); for (int i = 0; i < args.Count; i++) { var expectedSort = d.inputVariables[i].Value; var actualSort = args[i].sort; if (expectedSort.kind != actualSort.kind || !expectedSort.name.text.Equals(actualSort.name.text)) throw new FastParseException(func.name.Location, string.Format("Function '{0}' parameter (#{4}) '{3}' has sort '{1}' not '{2}'", func.name.text, d.inputVariables[i].Key.text, expectedSort.name.text, actualSort.name.text, i + 1)); } _sort = d.outputSort; } } break; } case (Tokens.LBRACKET): //Record constructor { List<KeyValuePair<FastToken, FastSort>> sorts = new List<KeyValuePair<FastToken, FastSort>>(); for (int i = 0; i < args.Count; i++) sorts.Add(new KeyValuePair<FastToken, FastSort>(new FastToken("_" + (1+i).ToString()), args[i].sort)); _sort = new RecordSort(sorts); break; } default: throw new FastParseException(func.name.Location, string.Format("Unexpected function '{0}'", func.name.text)); } }
internal override void Typecheck(FastPgm pgm) { if (this.expr != null) //else constructor { Func<FastToken, FastSort> context = x => { if (varSortMap.ContainsKey(x.text)) return varSortMap[x.text]; else return pgm.GetConstantSort(x); }; this.expr.CalcSort(context, pgm); if (!this.outputSort.name.text.Equals(this.expr.sort.name.text)) throw new FastParseException(this.expr.token.Location, string.Format("Wrong sort '{0}', expecting '{1}'", expr.sort.name, outputSort.name.text)); } }
internal override void CalcSort(Func<FastToken, FastSort> context, FastPgm program) { if (program.defsMap.ContainsKey(this._token.text)) _sort = program.GetConstantSort(this._token); else _sort = context(this._token); }
internal override void Typecheck(FastPgm pgm) { var domAlph = pgm.FindAlphabetDef(domain.name); var subs = new HashSet<string>(); if (expr.kind != FExpKind.Var) expr.CheckTransformation(subs, null, domAlph, pgm); else { foreach (var d in pgm.defs) { if ((expr as Variable).token.text == d.id.text) { if (d.kind == DefKind.Def && (d as DefDef).ddkind == DefDefKind.Tree) { if ((d as TreeDef).domain.name.text != domain.name.text) throw new FastParseException((d as TreeDef).domain.name.Location, string.Format("wrong dommain '{1}' of '{0}'", expr.token.text, domain.name.text)); return; } else throw new FastParseException(expr.token.Location, string.Format("'{0}' is not a tree", expr.token.text)); } } throw new FastParseException(expr.token.Location, string.Format("'{0}' is undefined", expr.token.text)); } }
internal override void CheckFunctionExpr(Dictionary<string, FastSort> vars, HashSet<string> attrNames, HashSet<string> patternTrees, FastPgm pgm) { if (!vars.ContainsKey(token.text)) throw new FastParseException(token.Location, string.Format("unexpected identifier '{0}'", token.text)); if (_sort == null) _sort = vars[token.text]; else if (!_sort.name.text.Equals(vars[token.text].name)) throw new FastParseException(token.Location, string.Format("unexpected sort '{1}' of '{0}' expecting '{2}'", token.text, _sort.name, vars[token.text].name)); }
internal override void Typecheck(FastPgm pgm) { var domAlph = pgm.FindAlphabetDef(domain.name); string dom = ""; var defs = new Dictionary<string, Def>(); bool skipNextDef = false; foreach (var d in pgm.defs) { if (d.id.text == func.name.text) skipNextDef = true; else if (!skipNextDef) defs[d.id.text] = d; else if (d.kind != DefKind.Def) defs[d.id.text] = d; } language.BLECheckSorts(defs, pgm); dom = language.domain.name.text; if (dom != domain.name.text) throw new FastParseException(domain.name.Location, string.Format("wrong domain '{1}' of '{0}'", language, domain.name.text)); }
internal override void CheckSubtreeGuard(Dictionary<string, FastSort> subs, AlphabetDef alph, FastPgm pgm) { Predicate<FExp> IsNotBool = (x => { return x.sort == null || x.sort.kind != FastSortKind.Bool; }); foreach (var expr in args) expr.CheckSubtreeGuard(subs, alph, pgm); if (func.name.text != "and" && func.name.text != "or" && !pgm.defs.Exists(d => d.id.text == func.name.text && d.kind == DefKind.Lang && ((LangDef)d).domain.name.text == alph.sort.name.text)) throw new FastParseException(func.name.Location, string.Format("illeagal identifier '{0}'", func.name.text)); if ((func.name.text == "and" || func.name.text == "or") && args.Exists(IsNotBool)) throw new FastParseException(func.name.Location, string.Format("arguments of '{0}' must be Boolean", func.name.text)); if (pgm.defs.Exists(d => d.id.text == func.name.text && d.kind == DefKind.Lang && ((LangDef)d).domain.name.text == alph.sort.name.text)) isLangDef = true; _sort = FastSort.Bool; }
internal override void Typecheck(FastPgm pgm) { var defs = new Dictionary<string, Def>(); foreach (var d in pgm.defs) { if (!(d is QueryDef)) if (d.id.text == func.name.text) break; else defs[d.id.text] = d; } input.BLECheckSorts(defs, pgm); trans.BTECheckSorts(defs, pgm); output.BLECheckSorts(defs, pgm); }
internal override void CalcSort(Func<FastToken, FastSort> context, FastPgm program) { var alph = context(treeNodeName); if (alph.kind != FastSortKind.Tree) throw new FastParseException(this.treeNodeName.Location, string.Format("Invalid input tree variable '{0}'", this.treeNodeName.text)); var alphdef = program.FindAlphabetDef(alph.name); var s = alphdef.attrSort.getSort(_token); _sort = s; }
internal override void BLECheckSorts(Dictionary<string, Def> defs, FastPgm pgm) { arg1.BLECheckSorts(defs, pgm); arg2.BLECheckSorts(defs, pgm); if (arg1.domain.name.text != arg2.domain.name.text) throw new FastParseException(arg1.func.name.Location, string.Format("the domain of '{0}' is different from the domain of '{1}'", arg1.func.name.text, arg2.func.name.text)); this.domain = arg1.domain; }
internal override void CheckSubtreeGuard(Dictionary<string, FastSort> subs, AlphabetDef alph, FastPgm pgm) { //Double check if (!subs.ContainsKey(token.text)) throw new FastParseException(token.Location, string.Format("unexpected identifier '{0}', expecting a subtree parameter", token.text)); else _sort = subs[token.text]; }
internal override void CheckFunctionExpr(Dictionary<string, FastSort> vars, HashSet<string> attrNames, HashSet<string> patternTrees, FastPgm pgm) { }
internal override void CalcSort(Func<FastToken, FastSort> context, FastPgm program) { }
internal override void CheckSubtreeGuard(Dictionary<string, FastSort> subs, AlphabetDef alph, FastPgm pgm) { }
internal override void BLECheckSorts(Dictionary<string, Def> defs, FastPgm pgm) { arg1.BLECheckSorts(defs, pgm); this.domain = arg1.domain; }
internal override void CheckTransformation(HashSet<string> subs, AlphabetDef domAlph, AlphabetDef rangeAlph, FastPgm pgm) { }
/// <summary> /// Generate a FastTransducerInstance from a Fast program /// </summary> /// <param name="fpg">the fast program</param> public static FastTransducerInstance MkFastTransducerInstance(FastPgm fpg,TextWriter tw, LogLevel lv) { FastTransducerInstance fti = new FastTransducerInstance(tw); fti.fastLog.setLogLevel(lv); z3p = new Z3Provider(); Dictionary<string, Def> definitions = new Dictionary<string, Def>(); List<EnumDef> enumDefs = new List<EnumDef>(); List<Def> constFunDefs = new List<Def>(); List<AlphabetDef> alphabetDefs = new List<AlphabetDef>(); List<QueryDef> queryDefs = new List<QueryDef>(); foreach (var def in fpg.defs) { switch(def.kind){ case DefKind.Query: { queryDefs.Add(def as QueryDef); break; } case DefKind.Alphabet: { alphabetDefs.Add(def as AlphabetDef); break; } case DefKind.Enum: { enumDefs.Add(def as EnumDef); break; } case DefKind.Const: case DefKind.Function:{ constFunDefs.Add(def); break; } } if(def.kind!=DefKind.Query) definitions[def.id.text] = def; } if (!GenerateEnumSorts(enumDefs, fti)) return null; if (!GenerateConstsAndFunctions(constFunDefs, fti)) return null; if (!GenerateAlphabetSorts(alphabetDefs, fti)) return null; if (!GenerateTreeClasses(definitions, fti)) return null; if (!GenerateQueryResults(queryDefs, definitions, fti)) return null; return fti; }
internal abstract void CheckSubtreeGuard(Dictionary<string, FastSort> subs, AlphabetDef alph, FastPgm pgm);