示例#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);
        }
示例#2
0
        public AstLambda(PegAstNode node)
            : base(node)
        {
            CheckLabel(AstLabel.Lambda);
            CheckChildCount(node, 2);

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

            mIdentifiers.Add(name.ToString());
            CatAstNode tmp = Create(node.GetChild(1));

            // lambda nodes either contain quotes or other lambda nodes
            if (!(tmp is AstQuote))
            {
                if (!(tmp is AstLambda))
                {
                    throw new Exception("expected lambda expression or quotation");
                }
                AstLambda lambda = tmp as AstLambda;
                mIdentifiers.AddRange(lambda.mIdentifiers);

                // Take ownership of the terms from the child lambda expression
                mTerms = lambda.mTerms;
            }
            else
            {
                AstQuote q = tmp as AstQuote;

                // Take ownership of the terms from the quote
                mTerms = q.mTerms;
            }
        }
示例#3
0
 public AstMacro(PegAstNode node)
     : base(node)
 {
     CheckChildCount(node, 2);
     CheckLabel(AstLabel.MacroRule);
     mSrc  = new AstMacroPattern(node.GetChild(0));
     mDest = new AstMacroPattern(node.GetChild(1));
 }
示例#4
0
 public AstFxnType(PegAstNode node)
     : base(node)
 {
     CheckLabel(AstLabel.FxnType);
     CheckChildCount(node, 3);
     mCons         = new AstStack(node.GetChild(0));
     mbSideEffects = node.GetChild(1).ToString().Equals("~>");
     mProd         = new AstStack(node.GetChild(2));
 }
示例#5
0
 public AstMacroTypeVar(PegAstNode node)
     : base(node)
 {
     CheckChildCount(node, 1);
     msName = node.GetChild(0).ToString();
     CheckLabel(AstLabel.MacroTypeVar);
 }
示例#6
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++;
            }
        }