IsValidSymbol() 개인적인 메소드

private IsValidSymbol ( FastToken symb, int arity ) : bool
symb FastToken
arity int
리턴 bool
예제 #1
0
        internal override void SetConstructorSort(AlphabetDef alph)
        {
            for (int i=0; i < args.Count; i++)
                args[i].SetConstructorSort(alph);

            if (func.name.Kind == Tokens.ID && alph.IsValidSymbol(func.name, func.arity))
            {
                func.alph = alph;
                func.isConstructor = true;
            }
        }
예제 #2
0
        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));
                    }
                }
            }
        }