예제 #1
0
파일: Sta.cs 프로젝트: pBactusp/Shpoon
        public static StatementNode Parse(TokenString tStr, ref int index)
        {
            switch (tStr[index].Type)
            {
            case TokenType.cBraceOpen:
                return(CompoundStaNode.Parse(tStr, ref index));

            case TokenType.ifStatement:
                return(ConditionalStaNode.Parse(tStr, ref index));

            case TokenType.doStatement:
                return(DoLoopStaNode.Parse(tStr, ref index));

            case TokenType.whileStatement:
                return(WhileLoopStaNode.Parse(tStr, ref index));

            case TokenType.forStatement:
                return(ForLoopStaNode.Parse(tStr, ref index));

            case TokenType.returnStatement:
                return(ReturnStaNode.Parse(tStr, ref index));

            case TokenType.lineEnd:
                return(NopStaNode.Parse(tStr, ref index));

            default:
                return(ExpressionStaNode.Parse(tStr, ref index));
            }
        }
예제 #2
0
        public static CompoundStaNode Parse(TokenString tStr, ref int index)
        {
            if (!tStr.Match(index, TokenType.cBraceOpen))
            {
                return(null);
            }

            index++;

            CompoundStaNode node = new CompoundStaNode();

            while (!tStr.Match(index, TokenType.cBraceClose))
            {
                var statementNode = Sta.Parse(tStr, ref index);

                if (statementNode != null)
                {
                    node.AddStatement(statementNode);
                }
                else
                {
                    index++;
                }
            }

            index++;
            return(node);
        }
예제 #3
0
        protected MethodNode(string type, string name, List <string> accessors, List <ArgumentNode> arguments, CompoundStaNode compoundStatement) : base(accessors)
        {
            Name      = name;
            Type      = type;
            Accessors = accessors;
            Arguments = arguments;

            Statements = compoundStatement;

            Class = null;
        }
예제 #4
0
파일: CtorNode.cs 프로젝트: pBactusp/Shpoon
        public static CtorNode Parse(string className, TokenString tStr, ref int index)
        {
            int startIndex = index;

            var accessors = new List <string>();

            while (tStr[index].Type == TokenType.accessor)
            {
                accessors.Add(tStr[index].Value);
                index++;
            }

            if (!(tStr.Match(index, TokenType.identifier, TokenType.rBraceOpen) && tStr[index].Value == className))
            {
                index = startIndex;
                return(null);
            }

            string type = tStr[index].Value;
            string name = "ctor";

            index++;

            var args = new List <ArgumentNode>();

            var argTokens = tStr.GetRangeInBrackets(ref index);

            if (argTokens != null && argTokens.Count > 0)
            {
                var argTokensSep = argTokens.Split(false, TokenType.comma);

                foreach (var argTs in argTokensSep)
                {
                    args.Add(new ArgumentNode(argTs[0].Value, argTs[1].Value));
                }
            }

            index = tStr.FindNextIndex(index, TokenType.cBraceOpen);

            var sta = CompoundStaNode.Parse(tStr, ref index);

            if (sta == null)
            {
                index = startIndex;
                return(null);
            }

            CtorNode node = new CtorNode(type, name, accessors, args, sta);

            return(node);
        }
예제 #5
0
        public static MethodNode Parse(TokenString tStr, ref int index)
        {
            int startIndex = index;

            var accessors = AccessibleNode.GetAccessors(tStr, ref index);

            if (!tStr.Match(index, TokenType.typeSpecifier, TokenType.identifier, TokenType.rBraceOpen))
            {
                return(null);
            }

            string type = tStr[index].Value;

            index++;
            string name = tStr[index].Value;

            index++;

            var args = new List <ArgumentNode>();

            var argTokens = tStr.GetRangeInBrackets(ref index).Split(false, TokenType.comma);

            foreach (var argTs in argTokens)
            {
                args.Add(new ArgumentNode(argTs[0].Value, argTs[1].Value));
            }

            index = tStr.FindNextIndex(index, TokenType.cBraceOpen);

            var sta = CompoundStaNode.Parse(tStr, ref index);

            if (sta == null)
            {
                index = startIndex;
                return(null);
            }

            MethodNode node = new MethodNode(type, name, accessors, args, sta);

            return(node);
        }
예제 #6
0
파일: CtorNode.cs 프로젝트: pBactusp/Shpoon
 private CtorNode(string type, string name, List <string> accessors, List <ArgumentNode> arguments, CompoundStaNode compoundStatement) : base(type, name, accessors, arguments, compoundStatement)
 {
 }