Inheritance: BuiltinExp
 internal static TreeTransducer getTreeAutomatonFromExpr(BuiltinLangExp expr, FastTransducerInstance fti, Dictionary<string, Def> defs)
 {
     Stopwatch stopwatch = new Stopwatch();
     switch (expr.kind)
     {
         case (BuiltinLangExpKind.Intersection):
             {
                 var castExpr = expr as IntersectionExp;
                 var a = getTreeAutomatonFromExpr(castExpr.arg1, fti, defs);
                 var b = getTreeAutomatonFromExpr(castExpr.arg2, fti, defs);
                 stopwatch.Start();
                 var inters = a.Intersect(b).RemoveMultipleInitialStates();
                 stopwatch.Stop();
                 fti.fastLog.WriteLog(LogLevel.Normal, string.Format("intersection of {0} and {1}: {2} ms", castExpr.arg1.ToString(), castExpr.arg2.ToString(), stopwatch.ElapsedMilliseconds));
                 return inters;
             }
         case (BuiltinLangExpKind.Difference):
             {
                 var castExpr = expr as DifferenceExp;
                 var a = getTreeAutomatonFromExpr(castExpr.arg1, fti, defs);
                 var b = getTreeAutomatonFromExpr(castExpr.arg2, fti, defs);
                 stopwatch.Start();
                 var inters = a.Intersect(b.Complement()).RemoveMultipleInitialStates();
                 stopwatch.Stop();
                 fti.fastLog.WriteLog(LogLevel.Normal, string.Format("difference of {0} and {1}: {2} ms", castExpr.arg1.ToString(), castExpr.arg2.ToString(), stopwatch.ElapsedMilliseconds));
                 return inters;
             }
         case (BuiltinLangExpKind.Union):
             {
                 var castExpr = expr as UnionExp;
                 var a = getTreeAutomatonFromExpr(castExpr.arg1, fti, defs);
                 var b = getTreeAutomatonFromExpr(castExpr.arg2, fti, defs);
                 stopwatch.Start();
                 var res = a.Union(b).RemoveMultipleInitialStates();
                 stopwatch.Stop();
                 fti.fastLog.WriteLog(LogLevel.Normal, string.Format("union of {0} and {1}: {2} ms", castExpr.arg1.ToString(), castExpr.arg2.ToString(), stopwatch.ElapsedMilliseconds));
                 return res;
             }
         case (BuiltinLangExpKind.Domain):
             {
                 var castExpr = expr as DomainExp;
                 var a = getTreeAutomatonFromExpr(castExpr.arg1, fti, defs);
                 stopwatch.Start();
                 var res = a.ComputeDomainAcceptor().RemoveMultipleInitialStates();
                 stopwatch.Stop();
                 fti.fastLog.WriteLog(LogLevel.Normal, string.Format("domain of {0}: {1} ms", castExpr.arg1.ToString(), stopwatch.ElapsedMilliseconds));
                 return res;
             }
         case (BuiltinLangExpKind.Preimage):
             {
                 var castExpr = expr as PreimageExp;
                 var t = getTreeAutomatonFromExpr(castExpr.arg1, fti, defs);
                 var output = getTreeAutomatonFromExpr(castExpr.arg2, fti, defs);
                 stopwatch.Start();
                 var res = t.RestrictRange(output).ComputeDomainAcceptor().RemoveMultipleInitialStates();
                 stopwatch.Stop();
                 fti.fastLog.WriteLog(LogLevel.Normal, string.Format("preimage of {0}: {1} ms", castExpr.arg1.ToString(), stopwatch.ElapsedMilliseconds));
                 return res;
             }
         case (BuiltinLangExpKind.Complement):
             {
                 var castExpr = expr as ComplementExp;
                 var a =  getTreeAutomatonFromExpr(castExpr.arg1, fti, defs);
                 stopwatch.Start();
                 var res = a.Complement().RemoveMultipleInitialStates();
                 stopwatch.Stop();
                 fti.fastLog.WriteLog(LogLevel.Normal, string.Format("complement of {0}: {1} ms", castExpr.arg1.ToString(), stopwatch.ElapsedMilliseconds));
                 return res;
             }
         case (BuiltinLangExpKind.Minimization):
             {
                 var castExpr = expr as MinimizeExp;
                 var a = getTreeAutomatonFromExpr(castExpr.arg1, fti, defs);
                 stopwatch.Start();
                 var res = a.Minimize().RemoveMultipleInitialStates();
                 stopwatch.Stop();
                 fti.fastLog.WriteLog(LogLevel.Normal, string.Format("minimization of {0}: {1} ms", castExpr.arg1.ToString(), stopwatch.ElapsedMilliseconds));
                 return res;
             }
         case (BuiltinLangExpKind.Var):
             {
                 var castExpr = expr as LangNameExp;
                 return fti.treeDefinitions[castExpr.domain.name.text].acceptors[castExpr.func.name.text];
             }
         default:
             {
                 throw new FastException(FastExceptionKind.NotImplemented);
             }
     }
     throw new FastException(FastExceptionKind.InternalError);
 }
Ejemplo n.º 2
0
 public UnionExp(FastToken func, BuiltinLangExp arg1, BuiltinLangExp arg2)
     : base(func, 2, BuiltinLangExpKind.Union)
 {
     this.arg1 = arg1;
     this.arg2 = arg2;
 }
Ejemplo n.º 3
0
 public ComplementExp(FastToken func, BuiltinLangExp arg1)
     : base(func, 1, BuiltinLangExpKind.Complement)
 {
     this.arg1 = arg1;
 }
Ejemplo n.º 4
0
 public TreeWitnessDef(FastToken acc, FastToken alphabet, BuiltinLangExp language)
     : base(acc, alphabet, TreeDefKind.Witness)
 {
     this.language = language;
 }
Ejemplo n.º 5
0
 public TypecheckQueryDef(FastToken isempty, BuiltinLangExp input, BuiltinTransExp trans, BuiltinLangExp output)
     : base(isempty)
 {
     this.trans = trans;
     this.input = input;
     this.output = output;
 }
Ejemplo n.º 6
0
 public PreimageExp(FastToken func, BuiltinTransExp arg1, BuiltinLangExp arg2)
     : base(func, 2, BuiltinLangExpKind.Preimage)
 {
     this.arg1 = arg1;
     this.arg2 = arg2;
 }
Ejemplo n.º 7
0
 public RestrictionOutExp(FastToken func, BuiltinTransExp arg1, BuiltinLangExp arg2)
     : base(func, 2, BuiltinTransExpKind.RestrictionOut)
 {
     this.arg1 = arg1;
     this.arg2 = arg2;
 }
Ejemplo n.º 8
0
 public LangEquivQueryDef(FastToken equiv, BuiltinLangExp lang1, BuiltinLangExp lang2)
     : base(equiv, lang1, lang2, false)
 {
     this.lang1 = lang1;
     this.lang2 = lang2;
 }
Ejemplo n.º 9
0
 public MinimizeExp(FastToken func, BuiltinLangExp arg1)
     : base(func, 1, BuiltinLangExpKind.Minimization)
 {
     this.arg1 = arg1;
 }
Ejemplo n.º 10
0
 public LangDefDef(FastToken acc, FastToken alphabet, BuiltinLangExp expr)
     : base(DefDefKind.Lang, new FastSort(alphabet, FastSortKind.Tree))
 {
     this.func = new FuncSymbol(acc, 1, false, true);
     this.expr = expr;
 }
Ejemplo n.º 11
0
 public IsEmptyLangQueryDef(FastToken isempty, BuiltinLangExp lang)
     : base(isempty, lang, false)
 {
     this.lang = lang;
 }
Ejemplo n.º 12
0
 public DifferenceExp(FastToken func, BuiltinLangExp arg1, BuiltinLangExp arg2)
     : base(func, 2, BuiltinLangExpKind.Difference)
 {
     this.arg1 = arg1;
     this.arg2 = arg2;
 }
Ejemplo n.º 13
0
 public ContainsQueryDef(FastToken print, BuiltinLangExp lang, FExp tree)
     : base(print)
 {
     this.language = lang;
     this.expr = tree;
 }
Ejemplo n.º 14
0
        //Generate CSharp for lang expr inside a definition
        private static bool GenerateDefExpr(BuiltinLangExp expr, StringBuilder sb, string tree, int varIndex, out int nextVar)
        {
            switch (expr.kind)
            {
                case (BuiltinLangExpKind.Union):
                    {
                        var ce = expr as UnionExp;
                        int x, y;
                        sb.AppendLine(string.Format("bool b{0};", varIndex + 1));
                        GenerateDefExpr(ce.arg1, sb, tree, varIndex + 1, out x);
                        sb.AppendLine(string.Format("bool b{0};", x));
                        GenerateDefExpr(ce.arg2, sb, tree, x, out y);
                        if (varIndex != 0)
                            sb.AppendLine(string.Format("b{0}=b{1}||b{2};", varIndex));
                        else
                            sb.AppendLine(string.Format("return b{0}||b{1};", varIndex + 1, x));

                        nextVar = y;
                        break;
                    }
                case (BuiltinLangExpKind.Intersection):
                    {
                        var ce = expr as IntersectionExp;
                        int x, y;
                        sb.AppendLine(string.Format("bool b{0};", varIndex + 1));
                        GenerateDefExpr(ce.arg1, sb, tree, varIndex + 1, out x);
                        sb.AppendLine(string.Format("bool b{0};", x));
                        GenerateDefExpr(ce.arg2, sb, tree, x, out y);
                        if(varIndex!=0)
                            sb.AppendLine(string.Format("b{0}=b{1}&&b{2};", varIndex,varIndex + 1, x));
                        else
                            sb.AppendLine(string.Format("return b{0}&&b{1};", varIndex + 1, x));

                        nextVar = y;
                        break;
                    }
                case (BuiltinLangExpKind.Domain):
                    {
                        var ce = expr as DomainExp;
                        int x;
                        sb.AppendLine(string.Format("List<Tree{0}> o{1} = new List<Tree{0}>();", ce.arg1.range.name, varIndex + 1));
                        GenerateDefExpr(ce.arg1, sb, tree, varIndex + 1, out x);
                        if (varIndex != 0)
                            sb.AppendLine(string.Format("b{0}=o{1}.Count>0;", varIndex, varIndex + 1));
                        else
                            sb.AppendLine(string.Format("return o{0}.Count>0;", varIndex + 1));

                        nextVar = x;
                        break;
                    }
                case (BuiltinLangExpKind.Var):
                    {
                        var ce = expr as LangNameExp;
                        if(varIndex==0)
                            sb.AppendLine(string.Format("return {0}.{1}();", tree, ce.func.name.text));
                        else
                            sb.AppendLine(string.Format("b{0} = {1}.{2}();", varIndex, tree, ce.func.name.text));

                        nextVar = varIndex + 1; ;
                        break;
                    }
                default:
                    {
                        throw new FastException(FastExceptionKind.NotImplemented);
                    }

            }
            return true;
        }