Beispiel #1
0
        private VariableDeclaration ParseVariableDeclaration()
        {
            VariableDeclaration variableDeclaration = null;

            if (_currentToken.TheTokenType.Equals(Token.TokenType.VARIABLE_TYPE))
            {
                var variableType = new VariableType(Accept(Token.TokenType.VARIABLE_TYPE));
                var variableName = new UserCreatableID(Accept(Token.TokenType.USER_CREATABLE_ID));


                Expression1 expression = null;
                if (_currentToken.TheTokenType.Equals(Token.TokenType.ASSIGNMENT))
                {
                    Accept(Token.TokenType.ASSIGNMENT);
                    expression = ParseExpression1();
                }

                variableDeclaration = new VariableDeclarationSimple(variableType, variableName, expression);
            }
            else if (Token.TokenType.COOK == _currentToken.TheTokenType)
            {
                variableDeclaration =
                    new VariableDeclarationStructVariableDeclaration(ParseStructVariableDeclaration());
            }

            Accept(Token.TokenType.SEMICOLON);
            return(variableDeclaration);
        }
Beispiel #2
0
        public object VisitArgumentList(ArgumentList argumentList, object o) //this should be good
        {
            var parameterList = o as ParameterList;

            if (parameterList.Parameters.Count != argumentList.Arguments.Count)
            {
                throw new Exception("Length of argument list does not match length of parameter list");
            }


            for (int i = 0; i < argumentList.Arguments.Count; i++)
            {
                var expressionType = (VariableType.ValueTypeEnum)argumentList.Arguments[i].Visit(this);
                var parameterType  = parameterList.Parameters[i].ParameterType.VariableType_;

                if (parameterType == VariableType.ValueTypeEnum.ANY || expressionType == parameterType)
                {
                    // bind to idTable
                    var decl = new VariableDeclarationSimple(parameterList.Parameters[i].ParameterType,
                                                             parameterList.Parameters[i].ParameterName, argumentList.Arguments[i]);
                    idTable.Add(parameterList.Parameters[i].ParameterName, decl, IDTable.DeclarationType.VARIABLE);
                }
                else
                {
                    throw new Exception("Type of argument not as expected ");
                }
            }

            return(null);
        }
Beispiel #3
0
        public object VisitParameter(Parameter parameter, object o)
        {
            var decl = new VariableDeclarationSimple(parameter.ParameterType, parameter.ParameterName, null);

            idTable.Add(parameter.ParameterName, decl, IDTable.DeclarationType.VARIABLE);
            decl.Address.Offset = (int)o;
            return(null);
        }
Beispiel #4
0
 public object VisitVariableDeclarationSimple(VariableDeclarationSimple variableDeclarationSimple, object o)
 {
     variableDeclarationSimple.Address.Offset = _stackManager.CurrentOffset;
     if (variableDeclarationSimple.Expression == null)
     {
         Emit(Machine.PUSHop, 0, 0, 1);
     }
     else
     {
         variableDeclarationSimple.Expression.Visit(this);
     }
     return(null);
 }
Beispiel #5
0
        public object VisitVariableDeclarationSimple(VariableDeclarationSimple variableDeclarationSimple, object o)
        {
            idTable.Add(variableDeclarationSimple.VariableName, variableDeclarationSimple, IDTable.DeclarationType.VARIABLE);

            if (variableDeclarationSimple.Expression == null)
            {
                return(null);
            }
            else
            {
                var declaration = idTable.Lookup(variableDeclarationSimple.Name, IDTable.DeclarationType.VARIABLE);
                var t1          = (VariableType.ValueTypeEnum)variableDeclarationSimple.Expression.Visit(this, declaration);
                var t2          = variableDeclarationSimple.VariableType.VariableType_;

                if (t1 != t2)
                {
                    throw new Exception("Type is not as expected; Actual: " + t1 + "; Expected: " + t2);
                }

                return(null);
            }
        }