예제 #1
0
        public PegAstNode Add(Parser p, Object label)
        {
            PegAstNode ret = new PegAstNode(p.GetPos(), msText, this, label);

            mChildren.Add(ret);
            return(ret);
        }
예제 #2
0
 public Parser(string s)
 {
     mIndex = 0;
     mData  = s;
     mTree  = new PegAstNode(0, mData, null, null);
     mCur   = mTree;
 }
예제 #3
0
 public Parser(string s)
 {
     mIndex = 0;
     mData = s;
     mTree = new PegAstNode(0, mData, null, null);
     mCur = mTree;
 }
예제 #4
0
 public PegAstNode CreateNode(Object label)
 {
     Trace.Assert(mCur != null);
     mCur = mCur.Add(this, label);
     Trace.Assert(mCur != null);
     return(mCur);
 }
예제 #5
0
 public void CompleteNode()
 {
     Trace.Assert(mCur != null);
     mCur.Complete(this);
     mCur = mCur.GetParent();
     Trace.Assert(mCur != null);
 }
예제 #6
0
 public PegAstNode(int n, String text, PegAstNode p, Object label)
 {
     msText   = text;
     mnBegin  = n;
     mnCount  = -1;
     mpParent = p;
     mLabel   = label;
 }
예제 #7
0
 public AstProgram(Peg.PegAstNode node)
     : base(node)
 {
     foreach (Peg.PegAstNode child in node.GetChildren())
     {
         CatAstNode statement = CatAstNode.Create(child);
         mStatements.Add(statement);
     }
 }
예제 #8
0
        public void AbandonNode()
        {
            Trace.Assert(mCur != null);
            PegAstNode tmp = mCur;

            mCur = mCur.GetParent();
            Trace.Assert(mCur != null);
            mCur.Remove(tmp);
        }
예제 #9
0
 public AstMetaDataBlock(PegAstNode node)
     : base(node)
 {
     CheckLabel(AstLabel.MetaDataBlock);
 }
예제 #10
0
 public AstMetaDataLabel(PegAstNode node)
     : base(node)
 {
     CheckLabel(AstLabel.MetaDataLabel);
     CheckIsLeaf(node);
     Trace.Assert(children.Count == 0);
 }
예제 #11
0
 public AstHex(PegAstNode node)
     : base(node)
 {
     CheckLabel(AstLabel.Hex);
     CheckIsLeaf(node);
     value = int.Parse(ToString(), NumberStyles.AllowHexSpecifier);
 }
예제 #12
0
 public AstType(PegAstNode node)
     : base(node)
 {
 }
예제 #13
0
 public PegAstNode Add(Parser p, Object label)
 {
     PegAstNode ret = new PegAstNode(p.GetPos(), msText, this, label);
     mChildren.Add(ret);
     return ret;
 }
예제 #14
0
 public AstStackVar(PegAstNode node)
     : base(node)
 {
     CheckLabel(AstLabel.StackVar);
     CheckChildCount(node, 0);
 }
예제 #15
0
 public AstStack(PegAstNode node)
     : base(node)
 {
     CheckLabel(AstLabel.Stack);
     foreach (PegAstNode child in node.GetChildren())
     {
         CatAstNode tmp = Create(child);
         if (!(tmp is AstType))
             throw new Exception("stack AST node should only have type AST nodes as children");
         mTypes.Add(tmp as AstType);
     }
 }
예제 #16
0
 public AstMacroPattern(PegAstNode node)
     : base(node)
 {
     CheckLabel(AstLabel.MacroPattern);
     foreach (PegAstNode child in node.GetChildren())
     {
         AstMacroTerm tmp = CatAstNode.Create(child) as AstMacroTerm;
         if (tmp == null)
             throw new Exception("invalid grammar: only macro terms can be children of an ast macro mPattern");
         mPattern.Add(tmp);
     }
 }
예제 #17
0
 public AstMacroTerm(PegAstNode node)
     : base(node)
 {
 }
예제 #18
0
 public AstMacroProperty(PegAstNode node)
     : base(node)
 {
 }
예제 #19
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));
 }
예제 #20
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));
 }
예제 #21
0
 public CatAstNode(PegAstNode node)
 {
     if (node.GetLabel() != null)
         mLabel = (AstLabel)node.GetLabel();
     else
         mLabel = AstLabel.AstRoot;
     
     msText = node.ToString();
 }
예제 #22
0
 public AstString(PegAstNode node)
     : base(node)
 {
     CheckLabel(AstLabel.String);
     CheckIsLeaf(node);
     // strip quotes
     string s = ToString();
     value = s.Substring(1, s.Length - 2);
 }
예제 #23
0
 public AstFloat(PegAstNode node)
     : base(node)
 {
     CheckLabel(AstLabel.Float);
     CheckIsLeaf(node);
     value = double.Parse(ToString());
 }
예제 #24
0
 public void CompleteNode()
 {
     Trace.Assert(mCur != null);
     mCur.Complete(this);
     mCur = mCur.GetParent();
     Trace.Assert(mCur != null);
 }
예제 #25
0
 public void Remove(PegAstNode x)
 {
     mChildren.Remove(x);
 }
예제 #26
0
 public AstSimpleType(PegAstNode node)
     : base(node)
 {
     CheckLabel(AstLabel.TypeName);
     CheckChildCount(node, 0);
 }
예제 #27
0
 public AstMacroQuote(PegAstNode node)
     : base(node)
 {
     CheckLabel(AstLabel.MacroQuote);
     foreach (PegAstNode child in node.GetChildren())
     {
         AstMacroTerm term = Create(child) as AstMacroTerm;
         if (term == null)
             throw new Exception("internal grammar error: macro quotations can only contain macro terms");
         mTerms.Add(term);
     }
 }
예제 #28
0
 public AstChar(PegAstNode node)
     : base(node)
 {
     CheckLabel(AstLabel.Char);
     CheckIsLeaf(node);
     string s = ToString();
     s = s.Substring(1, s.Length - 2);
     switch (s)
     {
         case "\\t": value = '\t'; break;
         case "\\n": value = '\n'; break;
         case "\\'": value = '\''; break;
         case "\\\"": value = '\"'; break;
         case "\\r": value = '\r'; break;
         default: value = char.Parse(s); break;
     }
 }
예제 #29
0
 public AstMacroTypeVar(PegAstNode node)
     : base(node)
 {
     CheckChildCount(node, 1);
     msName = node.GetChild(0).ToString();
     CheckLabel(AstLabel.MacroTypeVar);
 }
예제 #30
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);
        }
예제 #31
0
 public void AbandonNode()
 {
     Trace.Assert(mCur != null);
     PegAstNode tmp = mCur;
     mCur = mCur.GetParent();
     Trace.Assert(mCur != null);
     mCur.Remove(tmp);
 }
예제 #32
0
 public AstMacroName(PegAstNode node)
     : base(node)
 {
     CheckChildCount(node, 0);
     CheckLabel(AstLabel.MacroName);
 }
예제 #33
0
 public PegAstNode(int n, String text, PegAstNode p, Object label)
 {
     msText = text;
     mnBegin = n;
     mnCount = -1;
     mpParent = p;
     mLabel = label;
 }
예제 #34
0
 public AstMetaData(PegAstNode node)
     : base(node)
 {
     foreach (PegAstNode child in node.GetChildren())
     {
         AstMetaData x = Create(child) as AstMetaData;
         if (x == null)
             throw new Exception("Meta data-nodes can only have meta-data nodes as children");
         children.Add(x);
     }
 }
예제 #35
0
 public void Remove(PegAstNode x)
 {
     mChildren.Remove(x);
 }
예제 #36
0
 public AstMetaDataContent(PegAstNode node)
     : base(node)
 {
     CheckLabel(AstLabel.MetaDataContent);
 }
예제 #37
0
 public PegAstNode CreateNode(Object label)
 {
     Trace.Assert(mCur != null);
     mCur = mCur.Add(this, label);
     Trace.Assert(mCur != null);
     return mCur;
 }
예제 #38
0
 public AstBin(PegAstNode node)
     : base(node)
 {
     CheckLabel(AstLabel.Bin);
     CheckIsLeaf(node);
     string s = ToString();
     int n = 0;
     int place = 1;
     for (int i = s.Length; i > 0; --i)
     {
         if (s[i - 1] == '1')
         {
             n += place;
         }
         else
         {
             if (s[i - 1] != '0')
                 throw new Exception("Invalid binary number");
         }
         place *= 2;
     }
     value = n;
 }