Exemple #1
0
 public InterVar(string name, InterVarType type, bool changeable)
 {
     this.name       = name;
     this.type       = type;
     this.changeable = changeable;
     depthInBrackets = 0;
 }
Exemple #2
0
        public static ICommand Build(List <Token> tokens)
        {
            tokens.RemoveAt(0);

            if (tokens.Count() > 3)
            {
                throw new SyntaxErrorException("ERROR! Command 'swap' is too long.");
            }

            if (tokens.Count() < 3)
            {
                throw new SyntaxErrorException("ERROR! Command 'swap' do not contain all necessary information.");
            }

            if (!tokens[1].GetTokenType().Equals(TokenType.With) && !tokens[1].GetTokenType().Equals(TokenType.And))
            {
                throw new SyntaxErrorException("ERROR! Command 'swap' do not have variables separated by keyword 'with' or 'and'.");
            }

            if (!tokens[0].GetTokenType().Equals(TokenType.Variable))
            {
                throw new SyntaxErrorException("ERROR! Command 'swap' do not have name of first variable to swap.");
            }

            if (!tokens[2].GetTokenType().Equals(TokenType.Variable))
            {
                throw new SyntaxErrorException("ERROR! Command 'swap' do not have name of second variable to swap.");
            }

            string leftVariable  = tokens[2].GetContent();
            string rightVariable = tokens[0].GetContent();

            if (!InterVariables.GetInstance().Contains(leftVariable))
            {
                throw new SyntaxErrorException("ERROR! In command 'swap' variable " + leftVariable + " do not exist.");
            }

            if (!InterVariables.GetInstance().Contains(rightVariable))
            {
                throw new SyntaxErrorException("ERROR! In command 'swap' variable " + rightVariable + " do not exist.");
            }

            InterVarType leftType  = InterVariables.GetInstance().GetVarType(leftVariable);
            InterVarType rightType = InterVariables.GetInstance().GetVarType(rightVariable);

            if (!leftType.Equals(rightType))
            {
                throw new SyntaxErrorException("ERROR! Variables " + leftVariable + " and " + rightVariable + " cannot be swapped, because they are of different type.");
            }

            return(new Swap(leftVariable, rightVariable));
        }
        public bool ContainsChangable(string name, InterVarType type)
        {
            if (!Contains(name, type))
            {
                return(false);
            }

            InterVar iv = variables.First(v => name.Equals(v.GetName()));

            if (iv.IsChangeable())
            {
                return(true);
            }
            return(false);
        }
        public bool Contains(string name, InterVarType type)
        {
            if (variables.Where(v => name.Equals(v.GetName())).Count() == 0)
            {
                return(false);
            }

            InterVar iv = variables.First(v => name.Equals(v.GetName()));

            switch (type)
            {
            case InterVarType.Bool:
            {
                return(iv.IsBool() ? true : false);
            }

            case InterVarType.Number:
            {
                return(iv.IsNumber() ? true : false);
            }

            case InterVarType.Time:
            {
                return(iv.IsTime() ? true : false);
            }

            case InterVarType.String:
            {
                return(iv.IsString() ? true : false);
            }

            case InterVarType.List:
            {
                return(iv.IsList() ? true : false);
            }
            }
            return(false);
        }
Exemple #5
0
 public void TurnToList()
 {
     type = InterVarType.List;
 }
 public void Add(string name, InterVarType type)
 {
     variables.Add(new InterVar(name, type, true));
 }