예제 #1
0
파일: Block.cs 프로젝트: Hyosya/Yoron
        private void TokenToStatements()
        {
            while (TokenList.Count > 0)
            {
                switch (TokenList[0])
                {
                case EndOfLine _:
                case BlockEnd _:
                    TokenList.RemoveAt(0);
                    break;

                case VarDeclaration _:
                    var varList = TokenList.Take(TokenList.FindIndex(t => t is EndOfLine) + 1).ToList();
                    TokenList.RemoveRange(0, varList.Count);
                    Statements.Add(new VarStatement(ExistLocalVariables, varList));
                    break;

                case IfKeyword _:
                    var ifCondition = TokenList.Skip(1).TakeWhile(t => !(t is BlockBegin)).ToList();
                    var ifBlock     = ParseBlock(TokenList.Skip(TokenList.FindIndex(t => t is BlockBegin)).ToList());
                    TokenList.RemoveRange(0, ifCondition.Count + ifBlock.Count + 2);
                    Statements.Add(new IfStatement(ExistLocalVariables, ifCondition, ifBlock));
                    break;

                case WhileKeyword _:
                    var whileCondition = TokenList.Skip(1).TakeWhile(t => !(t is BlockBegin)).ToList();
                    var whileBlock     = ParseBlock(TokenList.Skip(TokenList.FindIndex(t => t is BlockBegin)).ToList());
                    TokenList.RemoveRange(0, whileCondition.Count + whileBlock.Count + 2);
                    Statements.Add(new WhileStatement(ExistLocalVariables, whileCondition, whileBlock));
                    break;

                case BreakKeyword _:
                    TokenList.RemoveAt(0);
                    Statements.Add(new BreakStatement(ExistLocalVariables));
                    break;

                case ContinueKeyword _:
                    TokenList.RemoveAt(0);
                    Statements.Add(new ContinueStatement(ExistLocalVariables));
                    break;

                default:
                    var list = TokenList.Take(TokenList.FindIndex(t => t is EndOfLine) + 1).ToList();
                    TokenList.RemoveRange(0, list.Count);
                    Statements.Add(new Statement(ExistLocalVariables, list));
                    break;
                }
            }
        }