예제 #1
0
파일: Parser.cs 프로젝트: xxy1991/cozy
        private static TempNode Parse(IEnumerator<Token> e)
        {
            if (e.Current.Type == TokenType.Identifier)
            {
                var node = new TempNode { Type = AstNodeType.Identifier, Value = e.Current.Value };
                e.MoveNext();
                node.AddNode(Parse(e));
                return node;
            }
            if (e.Current.Type == TokenType.Dot)
            {
                var callNode = new TempNode { Type = AstNodeType.Call };
                callNode.AddNode(ParseCallNode(e));
                return callNode;
            }
            if (e.Current.Type == TokenType.String || e.Current.Type == TokenType.Number)
            {
                return new TempNode { Type = AstNodeType.Literal, Value = e.Current.Value };
            }

            if (e.MoveNext())
                return Parse(e);

            return null;
        }
예제 #2
0
        private static TempNode Parse(IEnumerator <Token> e)
        {
            if (e.Current.Type == TokenType.Identifier)
            {
                var node = new TempNode {
                    Type = AstNodeType.Identifier, Value = e.Current.Value
                };
                e.MoveNext();
                node.AddNode(Parse(e));
                return(node);
            }
            if (e.Current.Type == TokenType.Dot)
            {
                var callNode = new TempNode {
                    Type = AstNodeType.Call
                };
                callNode.AddNode(ParseCallNode(e));
                return(callNode);
            }
            if (e.Current.Type == TokenType.String || e.Current.Type == TokenType.Number)
            {
                return(new TempNode {
                    Type = AstNodeType.Literal, Value = e.Current.Value
                });
            }

            if (e.MoveNext())
            {
                return(Parse(e));
            }

            return(null);
        }
예제 #3
0
 public void AddNode(TempNode node)
 {
     if (node != null)
     {
         _nodes.Add(node);
     }
 }
예제 #4
0
파일: Parser.cs 프로젝트: xxy1991/cozy
 private static void ParseArguments(IEnumerator<Token> e, TempNode methodNode)
 {
     e.MoveNext();
     while (e.Current.Type != TokenType.CloseParen)
     {
         methodNode.AddNode(Parse(e));
         e.MoveNext();
     }
 }
예제 #5
0
 private static void ParseArguments(IEnumerator <Token> e, TempNode methodNode)
 {
     e.MoveNext();
     while (e.Current.Type != TokenType.CloseParen)
     {
         methodNode.AddNode(Parse(e));
         e.MoveNext();
     }
 }
예제 #6
0
파일: Parser.cs 프로젝트: xxy1991/cozy
 private static TempNode ParseCallNode(IEnumerator<Token> e)
 {
     TempNode currentNode;
     e.MoveNext();
     string identifier = e.Current.Value.ToString();
     e.MoveNext();
     if (e.Current.Type == TokenType.OpenParen)
     {
         currentNode = new TempNode { Type = AstNodeType.Method, Value = identifier };
         ParseArguments(e, currentNode);
     }
     else
     {
         currentNode = new TempNode { Type = AstNodeType.PropertyGetter, Value = identifier };
     }
     return currentNode;
 }
예제 #7
0
        private static TempNode ParseCallNode(IEnumerator <Token> e)
        {
            TempNode currentNode;

            e.MoveNext();
            string identifier = e.Current.Value.ToString();

            e.MoveNext();
            if (e.Current.Type == TokenType.OpenParen)
            {
                currentNode = new TempNode {
                    Type = AstNodeType.Method, Value = identifier
                };
                ParseArguments(e, currentNode);
            }
            else
            {
                currentNode = new TempNode {
                    Type = AstNodeType.PropertyGetter, Value = identifier
                };
            }
            return(currentNode);
        }
예제 #8
0
파일: TempNode.cs 프로젝트: xxy1991/cozy
 public void AddNode(TempNode node)
 {
     if (node != null)
         _nodes.Add(node);
 }