Example #1
0
        public static DoWhile Parse(Block parent, ref List <Token> .Enumerator tokens)
        {
            Debug.Assert(tokens.Current.Text == "do");
            tokens.MoveNext();

            Debug.Assert(tokens.Current.Text == "{");
            tokens.MoveNext();

            Block body = Block.ParseBlock(ref tokens, parent);

            tokens.MoveNext();

            Debug.Assert(tokens.Current.Text == "while");

            tokens.MoveNext();
            Debug.Assert(tokens.Current.Text == "(");
            tokens.MoveNext();
            List <Token> conditionList = Tokenizer.GetArgument(ref tokens);

            tokens.MoveNext();
            Debug.Assert(tokens.Current.Type == TokenType.StatementEnd);
            tokens.MoveNext();

            var   condDecl  = parent.CreateTempDeclaration(new BuiltInType("int"));
            Block condBlock = new Block();

            condBlock.Parent = parent;
            condBlock.TempDeclarationNumber = parent.TempDeclarationNumber;
            StatementHelper.Parse(condBlock, condDecl, conditionList);

            return(new DoWhile(parent, condDecl, condBlock, body));
        }
Example #2
0
        public static List <Declaration> BuildParams(Block block, FunctionType funcType, List <Expression> args)
        {
            if (funcType.Params.Count == 0)
            {
                return(new List <Declaration>());
            }
            var tokenList = new List <Declaration>();
            int nCount    = 0;

            foreach (Expression arg in args)
            {
                Declaration decl = block.CreateTempDeclaration(funcType.Params[nCount].Type);

                StatementHelper.Parse(block, decl, arg.Tokens);

                tokenList.Add(decl);
            }
            return(tokenList);
        }
Example #3
0
        public static If ParseIf(Block parent, ref List <Token> .Enumerator tokens)
        {
            Debug.Assert(tokens.Current.Text == "if");

            tokens.MoveNext();
            Debug.Assert(tokens.Current.Text == "(");
            tokens.MoveNext();

            List <Token> conditionList = Tokenizer.GetArgument(ref tokens);

            var         condBlock = new Block(parent);
            Declaration condDecl  = parent.CreateTempDeclaration(new BuiltInType("int"));

            StatementHelper.Parse(condBlock, condDecl, conditionList);

            tokens.MoveNext();
            Debug.Assert(tokens.Current.Text == "{");
            tokens.MoveNext();

            Block trueCase = Block.ParseBlock(ref tokens, parent);

            tokens.MoveNext();

            Block falseCase = null;

            if (tokens.Current.Text == "else")
            {
                tokens.MoveNext();
                Debug.Assert(tokens.Current.Text == "{");
                tokens.MoveNext();

                falseCase = Block.ParseBlock(ref tokens, parent);
                tokens.MoveNext();
            }

            return(new If(parent, condDecl, condBlock, trueCase, falseCase));
        }
Example #4
0
        public static List <Declaration> BuildParams(Block block, FunctionType funcType, ref List <Token> .Enumerator tokens)
        {
            var tokenList = new List <Declaration>();
            int nCount    = 0;

            while (tokens.Current.Type != TokenType.CloseParen)
            {
                Declaration decl = block.CreateTempDeclaration(funcType.Params[nCount].Type);

                var valueList = Tokenizer.GetArgument(ref tokens);

                StatementHelper.Parse(block, decl, valueList);

                tokenList.Add(decl);

                Debug.Assert(tokens.Current.Text == "," || tokens.Current.Text == ")");

                if (tokens.Current.Text == ",")
                {
                    tokens.MoveNext();
                }
            }
            return(tokenList);
        }