Ejemplo n.º 1
0
        private AstItem ReadVector(TokenIterator tokens)
        {
            var name = tokens.Pop();

            var bracket = tokens.Pop();

            if (bracket.Kind != TokenKind.RoundBracketOpen)
            {
                throw new Exception("Unexcepted token after vector name! Expected '(', found: " + bracket);
            }

            var vectorValues   = new List <List <Token> >();
            var valueTokens    = new List <Token>();
            var bracketCounter = 0;
            var token          = tokens.Pop();

            while (token != null)
            {
                if (token.Kind == TokenKind.RoundBracketOpen)
                {
                    bracketCounter += 1;
                    valueTokens.Add(token);
                }
                else if (token.Kind == TokenKind.RoundBracketClose)
                {
                    if (bracketCounter <= 0)
                    {
                        vectorValues.Add(valueTokens);
                        break;
                    }
                    else
                    {
                        bracketCounter -= 1;
                        valueTokens.Add(token);
                    }
                }
                else if (token.Kind == TokenKind.Comma)
                {
                    vectorValues.Add(valueTokens);
                    valueTokens = new List <Token>();
                }
                else
                {
                    valueTokens.Add(token);
                }

                token = tokens.Pop();
            }

            var paramExpressions = new List <AstItem>(vectorValues.Count);

            foreach (var values in vectorValues)
            {
                var expression = ReadExpression(new TokenIterator(values), null);
                paramExpressions.Add(expression);
            }

            //Need to pass the name so SemanticAnalysis knows if "vec" or (i.e.) "vec4f" was used
            return(AstItem.Vector(name.Value, paramExpressions));
        }