예제 #1
0
        public static ExpressionNode ResolveAtomicExpression <TSymbol>(IParseTree <TSymbol> parseTree) where TSymbol : ISymbol <TSymbol>
        {
            // AtomicExpression -> BlockExpression | ObjectDefinitionExpression | ArrayLiteralExpression | ObjectUseExpression |
            //                     IfExpression | WhileExpression | LoopControlExpression
            var            node = ASTBuilder.FirstChild(parseTree); // AtomicExpression -> one of available symbols
            ExpressionNode atomic;

            switch (ASTBuilder.GetName(node.Symbol))
            {
            case "BlockExpression":
                atomic = new BlockExpressionNode();
                break;

            case "ArrayLiteralExpression":
                throw new System.NotImplementedException();     // TODO: arrays implementation

            case "ObjectUseExpression":
                // ObjectUseExpression -> ObjectName | Literals
                node = ASTBuilder.FirstChild(node);
                if (node.Symbol.IsTerminal)       // ObjectName
                {
                    atomic = new VariableUseNode();
                }
                else                                      // Literals
                {
                    node   = ASTBuilder.FirstChild(node); // Literals -> one of available literals
                    atomic = ConstNode.GetConstNode(node);
                }
                break;

            case "LoopControlExpression":
                atomic = new LoopControlNode();
                break;

            default:
                throw new System.ArgumentException();
            }
            atomic.BuildNode(node);
            return(atomic);
        }