Esempio n. 1
0
        public AstMacroStackVar(PegAstNode node)
            : base(node)
        {
            if (node.GetNumChildren() < 1)
            {
                throw new Exception("invalid macro stack variable");
            }

            if (node.GetNumChildren() > 2)
            {
                throw new Exception("invalid macro stack variable");
            }

            msName = node.GetChild(0).ToString();

            if (node.GetNumChildren() == 2)
            {
                AstFxnType typeNode = new AstFxnType(node.GetChild(1));
                mType = CatFxnType.Create(typeNode) as CatFxnType;
                if (mType == null)
                {
                    throw new Exception("expected function type " + typeNode.ToString());
                }
            }

            CheckLabel(AstLabel.MacroStackVar);
        }
Esempio n. 2
0
        public static CatFxnType Create(string sType)
        {
            if (sType.Length == 0)
            {
                return(null);
            }

            Peg.Parser p = new Peg.Parser(sType);
            try {
                if (!p.Parse(CatGrammar.FxnType()))
                {
                    throw new Exception("no additional information");
                }
            } catch (Exception e) {
                throw new Exception(sType + " is not a valid function type ", e);
            }

            Peg.PegAstNode ast = p.GetAst();
            if (ast.GetNumChildren() != 1)
            {
                throw new Exception("invalid number of children in abstract syntax tree");
            }
            AstFxnType node = new AstFxnType(ast.GetChild(0));
            CatFxnType ret  = new CatFxnType(node);

            return(ret);
        }
Esempio n. 3
0
 public CatFxnType(AstFxnType node)
 {
     mbSideEffects = node.HasSideEffects();
     mCons         = new CatTypeVector(node.mCons);
     mProd         = new CatTypeVector(node.mProd);
     SetChildFxnParents();
     ComputeFreeVars();
 }
Esempio n. 4
0
        public static CatFxnType Create(string sType)
        {
            if (sType.Length == 0)
                return null;

            Peg.Parser p = new Peg.Parser(sType);
            try
            {
                if (!p.Parse(CatGrammar.FxnType()))
                    throw new Exception("no additional information");
            }
            catch (Exception e)
            {
                throw new Exception(sType + " is not a valid function type ", e);
            }

            Peg.PegAstNode ast = p.GetAst();
            if (ast.GetNumChildren() != 1)
                throw new Exception("invalid number of children in abstract syntax tree");
            AstFxnType node = new AstFxnType(ast.GetChild(0));
            CatFxnType ret = new CatFxnType(node);
            
            return ret;
        }
Esempio n. 5
0
        public AstDef(PegAstNode node)
            : base(node)
        {
            CheckLabel(AstLabel.Def);

            if (node.GetNumChildren() == 0)
            {
                throw new Exception("invalid function definition node");
            }

            AstName name = new AstName(node.GetChild(0));

            mName = name.ToString();

            int n = 1;

            // Look to see if a type is defined
            if ((node.GetNumChildren() >= 2) && (node.GetChild(1).GetLabel().Equals(AstLabel.FxnType)))
            {
                mType = new AstFxnType(node.GetChild(1));
                ++n;
            }

            while (n < node.GetNumChildren())
            {
                PegAstNode child = node.GetChild(n);

                if (!child.GetLabel().Equals(AstLabel.Param))
                {
                    break;
                }

                mParams.Add(new AstParam(child));
                n++;
            }

            while (n < node.GetNumChildren())
            {
                PegAstNode child = node.GetChild(n);

                if (!child.GetLabel().Equals(AstLabel.Param))
                {
                    break;
                }

                mParams.Add(new AstParam(child));
                n++;
            }

            while (n < node.GetNumChildren())
            {
                PegAstNode child = node.GetChild(n);

                if (!child.GetLabel().Equals(AstLabel.MetaDataBlock))
                {
                    break;
                }

                mpMetaData = new AstMetaDataBlock(child);
                n++;
            }

            while (n < node.GetNumChildren())
            {
                PegAstNode child = node.GetChild(n);

                if (!child.GetLabel().Equals(AstLabel.Def))
                {
                    break;
                }

                mLocals.Add(new AstDef(child));
                n++;
            }

            while (n < node.GetNumChildren())
            {
                PegAstNode child = node.GetChild(n);
                CatAstNode expr  = Create(child);

                if (!(expr is AstExpr))
                {
                    throw new Exception("expected expression node");
                }

                mTerms.Add(expr as AstExpr);
                n++;
            }
        }
Esempio n. 6
0
 public CatFxnType(AstFxnType node)
 {
     mbSideEffects = node.HasSideEffects();
     mCons = new CatTypeVector(node.mCons);
     mProd = new CatTypeVector(node.mProd);
     SetChildFxnParents();
     ComputeFreeVars();
 }
Esempio n. 7
0
        public AstMacroStackVar(PegAstNode node)
            : base(node)
        {
            if (node.GetNumChildren() < 1)
                throw new Exception("invalid macro stack variable");

            if (node.GetNumChildren() > 2)
                throw new Exception("invalid macro stack variable");

            msName = node.GetChild(0).ToString();

            if (node.GetNumChildren() == 2)
            {
                AstFxnType typeNode = new AstFxnType(node.GetChild(1));
                mType = CatFxnType.Create(typeNode) as CatFxnType;
                if (mType == null) throw new Exception("expected function type " + typeNode.ToString());
            }

            CheckLabel(AstLabel.MacroStackVar);
        }
Esempio n. 8
0
        public AstDef(PegAstNode node)
            : base(node)
        {
            CheckLabel(AstLabel.Def);

            if (node.GetNumChildren() == 0)
                throw new Exception("invalid function definition node");

            AstName name = new AstName(node.GetChild(0));
            mName = name.ToString();

            int n = 1;

            // Look to see if a type is defined
            if ((node.GetNumChildren() >= 2) && (node.GetChild(1).GetLabel().Equals(AstLabel.FxnType)))
            {
                mType = new AstFxnType(node.GetChild(1));
                ++n;
            }

            while (n < node.GetNumChildren())
            {
                PegAstNode child = node.GetChild(n);

                if (!child.GetLabel().Equals(AstLabel.Param))
                    break;

                mParams.Add(new AstParam(child));
                n++;
            }

            while (n < node.GetNumChildren())
            {
                PegAstNode child = node.GetChild(n);

                if (!child.GetLabel().Equals(AstLabel.Param))
                    break;

                mParams.Add(new AstParam(child));
                n++;
            }

            while (n < node.GetNumChildren())
            {
                PegAstNode child = node.GetChild(n);

                if (!child.GetLabel().Equals(AstLabel.MetaDataBlock))
                    break;

                mpMetaData = new AstMetaDataBlock(child);
                n++;
            }

            while (n < node.GetNumChildren())
            {
                PegAstNode child = node.GetChild(n);

                if (!child.GetLabel().Equals(AstLabel.Def))
                    break;

                mLocals.Add(new AstDef(child));
                n++;
            }

            while (n < node.GetNumChildren())
            {
                PegAstNode child = node.GetChild(n);
                CatAstNode expr = Create(child);

                if (!(expr is AstExpr))
                    throw new Exception("expected expression node");

                mTerms.Add(expr as AstExpr);
                n++;
            }
        }