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 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 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 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) { 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)); } } }