Esempio n. 1
0
        private void GetInitialValues(List <TokenExpression> result)
        {
            var secondPass = new SecondPass(this);

            if (this.Error != null)
            {
                secondPass.Error += this.Error;
            }

            secondPass.GetInitialValues(result);
        }
Esempio n. 2
0
        private bool CompileSecondPass()
        {
            var secondPass = new SecondPass(this);

            if (this.Error != null)
            {
                secondPass.Error += this.Error;
            }
            secondPass.CompileSecondPass();
            if (secondPass.Errors.Count == 0)
            {
                return(true);
            }
            else
            {
                this.Errors.AddRange(secondPass.Errors);
                return(false);
            }
        }
Esempio n. 3
0
        private Variable[] GetVariablesInVariableDeclaration(TokenExpression variableDeclarationToken)
        {
            var dataTypeToken = variableDeclarationToken.Subexpressions[0];
            var variablesList = variableDeclarationToken.Subexpressions[1].Subexpressions;

            var dataType = GetDataType(dataTypeToken);

            List <Variable> variables = new List <Variable>();

            foreach (var entry in variablesList)
            {
                string variableName = entry.Subexpressions[0].Token.Value;
                var    newVariable  = new Variable(variableName, dataType.DataType, dataType.StructType, dataType.ArrayDimensions);
                newVariable.Root = ainFile;
                variables.Add(newVariable);
                if (entry.Subexpressions.Count > 1 && entry.Subexpressions[1].TokenType == TokenType.ArrayBoundsDeclaration)
                {
                    //due to bugs, it is treating expressions as separate dimension values, so parse it with the second pass first
                    var boundsDeclaration = entry.Subexpressions[1];
                    if (boundsDeclaration.Subexpressions.Count > 1)
                    {
                        var secondPass = new SecondPass(this);
                        var sizeTokens = secondPass.CompileTokens(boundsDeclaration.Subexpressions);
                        boundsDeclaration.Subexpressions.Clear();
                        boundsDeclaration.Subexpressions.AddRange(sizeTokens);
                    }

                    this.ArraySizeExpressions[newVariable] = boundsDeclaration;
                }
                if (newVariable.DataType.IsPrimitiveRefType())
                {
                    newVariable      = new Variable("<void>", DataType.Void, 0, 0);
                    newVariable.Root = ainFile;
                    variables.Add(newVariable);
                }
            }

            return(variables.ToArray());
        }
Esempio n. 4
0
        private void AddArrayDeclarationToBlock(TokenExpression block, IVariable member)
        {
            block.Subexpressions.Add(new TokenExpression(member.Name));
            block.Subexpressions.Add(new TokenExpression("."));
            block.Subexpressions.Add(new TokenExpression("Alloc"));
            block.Subexpressions.Add(new TokenExpression("("));
            int count = 0;

            foreach (var numberFromForEach in this.ArraySizeExpressions[member].Subexpressions)
            {
                var number = numberFromForEach;
                if (count > 0)
                {
                    block.Subexpressions.Add(new TokenExpression(TokenType.Comma));
                }
                if (number.TokenType != TokenType.Number)
                {
                    var secondPass   = new SecondPass(this);
                    var initialValue = secondPass.EvaluateConstExpression(number, DataType.Int, true);
                    if (initialValue != null && initialValue.DataType == DataType.Int)
                    {
                        number = new TokenExpression(initialValue.IntValue.ToString());
                    }
                    else
                    {
                        RaiseError("Unable to parse array size as a constant", number);
                    }
                }

                block.Subexpressions.Add(number.Clone());
                count++;
            }

            //block.Subexpressions.Add(this.ArraySizeExpressions[member].Clone());
            block.Subexpressions.Add(new TokenExpression(")"));
            block.Subexpressions.Add(new TokenExpression(";"));
        }