/// Author: Max Hamulyak
        /// Date:	17-06-2015
        /// <summary>
        /// Reads the value of a token, and gives the correct comparison operator back.
        /// This method is in CodeParser because math operator (==, !=, &lt;, &gt;, &lt;= and &gt;=) should be the same
        /// in all programming languages. If desired it can be overuled in a ConcreteParser.
        /// </summary>
        /// <returns>The comparison operator from token.</returns>
        /// <param name="token">Token.</param>
        protected virtual EComparisonOperator ParseComparisonOperatorFromToken(Token token)
        {
            EComparisonOperator comparisionOperator = EComparisonOperator.None;

            switch (token.Value) {
            case "<=":
                comparisionOperator = EComparisonOperator.ValueLessThanOrEqualTo;
                break;
            case ">=":
                comparisionOperator = EComparisonOperator.ValueGreaterThanOrEqualTo;
                break;
            case "<":
                comparisionOperator = EComparisonOperator.ValueLessThan;
                break;
            case ">":
                comparisionOperator = EComparisonOperator.ValueGreaterThan;
                break;
            case "==":
                comparisionOperator = EComparisonOperator.ValueEqualTo;
                break;
            case "!=":
                comparisionOperator = EComparisonOperator.ValueNotEqualTo;
                break;
            default:
                break;
            }

            return comparisionOperator;
        }
        /// Author: Max Hamulyak
        /// Date:	24-06-2015
        /// <summary>
        /// Given a token, this method builds a <see cref="ConcreteInstruction"/>
        /// </summary>
        /// <returns>The logic instruction from token.</returns>
        /// <param name="token">Token.</param>
        private ICondition ParseLogicInstructionFromToken(Token token)
        {
            ICondition condition;
            if (token.Value.StartsWith ("at('")) {
                int quoteIndex = token.Value.IndexOf ("'");
                String desiredObject = token.Value.Substring (quoteIndex + 1);
                desiredObject = desiredObject.TrimEnd ("')".ToCharArray ());
                condition = new ConcreteInstruction (ECanInstructions.At, desiredObject);
            } else {

                switch (token.Value) {

                case "left":
                    condition = new ConcreteInstruction (ECanInstructions.Left);
                    break;
                case "right":
                    condition = new ConcreteInstruction (ECanInstructions.Right);
                    break;
                case "forward":
                    condition = new ConcreteInstruction (ECanInstructions.Forward);
                    break;
                case "backward":
                    condition = new ConcreteInstruction (ECanInstructions.Backward);
                    break;
                default:
                    condition = null;
                    break;
                }
            }
            return condition;
        }
 protected virtual void EndOfBlockTokenCorrect(Token endToken, string expectedEnd, ETokenType blockType)
 {
     //DO NOTHING ONLY ON OVERRIDE CLASS, CURRENTLY ONLY PASCAL NEEDS THIS METHOD
 }
 /// Author: Max Hamulyak
 /// Date:	29-06-2015
 /// <summary>
 /// Should be used to indicate that there are incorrect values before the semcicolon
 /// </summary>
 /// <returns>The before semicolon.</returns>
 /// <param name="lineNumber">Line number.</param>
 /// <param name="tokenToParse">Token to parse.</param>
 /// <param name="errorToken">Error token.</param>
 protected CodeParseException ValueBeforeSemicolon(int lineNumber, Token tokenToParse, Token errorToken)
 {
     return new CodeParseException (String.Format (errorAtLine + invalidSyntax + "Expected ';' after '{1}' but found '{2}'", lineNumber, tokenToParse.Value, errorToken.Value));
 }
        /// Author: Max Hamulyak
        /// Date:	17-06-2015
        /// <summary>
        /// Reads the value of a token, and gives the correct math operator back.
        /// This method is in CodeParser because math operator ( + - / *) should be the same
        /// in all programming languages. If desired it can be overuled in a ConcreteParser.
        /// </summary>
        /// <returns>The math operator from token.</returns>
        /// <param name="token">Token.</param>
        protected virtual EMathOperator ParseMathOperatorFromToken(Token token)
        {
            EMathOperator mathOperator = EMathOperator.None;

            switch (token.Value) {

            case "*":
                mathOperator = EMathOperator.Multiply;
                break;
            case "/":
                mathOperator = EMathOperator.Divide;
                break;
            case "+":
                mathOperator = EMathOperator.Add;
                break;
            case "-":
                mathOperator = EMathOperator.Subtract;
                break;
            default:
                break;
            }

            return mathOperator;
        }
 /// Author: Max Hamulyak
 /// Date:	19-06-2015 
 /// <summary>
 /// Can parse a logic operator from a token, should be able to match
 /// syntax from most programming languages, can be overriden in child class
 /// if logic is different, or more cases needed to be added.
 /// The following values ar supported:
 /// <list type="bullet">
 /// <item>
 /// <term>LOGICAL OPERATOR AND</term>
 /// <description> Support values are (and or &&)</description>
 /// </item>
 /// <item>
 /// <term>LOGICAL OPERATOR OR</term>
 /// <description> Support values are (or or ||)</description>
 /// </item>
 /// <item>
 /// <term>LOGICAL OPERATOR NOT</term>
 /// <description> Support values are (not or !) </description>
 /// </item>
 /// </list>
 /// </summary>
 /// <returns>The logic operator from token.</returns>
 /// <param name="token">Token.</param>
 protected virtual ELogicOperators ParseLogicOperatorFromToken(Token token)
 {
     ELogicOperators logicOperator = ELogicOperators.None;
     switch (token.Value) {
     case "and":
     case "&&":
         logicOperator = ELogicOperators.And;
         break;
     case "or":
     case "||":
         logicOperator = ELogicOperators.Or;
         break;
     case "not":
     case "!":
         logicOperator = ELogicOperators.Not;
         break;
     default:
         break;
     }
     return logicOperator;
 }
 /// Author: Max Hamulyak
 /// Date:	26-06-2015
 /// <summary>
 /// Reads an token marked as invalid and gives an exception.
 /// </summary>
 /// <param name="tokenToParse">Token to parse.</param>
 private void InvalidCommandFromToken(Token tokenToParse)
 {
     if (tokenToParse.Value == "rotateLeft()") {
         throw InvalidCommand (tokenToParse.Position.Line, tokenToParse.Value, "rotateRight()");
     } else if (tokenToParse.Value == "moveBackward()") {
         throw InvalidCommand (tokenToParse.Position.Line, tokenToParse.Value, "moveForward()");
     }
 }
 protected override void EndOfBlockTokenCorrect(Token endToken, string expectedEnd, ETokenType blockType)
 {
     if (endToken.Type == ETokenType.endBlock) {
         if (endToken.Value != expectedEnd) {
             throw IncorrectEndingOfBlock (endToken.Position.Line, expectedEnd, endToken.Value, blockType.ToString());
         }
     }
 }