/// <summary>
        /// Scans the given source code and converts it into parallel code.
        /// </summary>
        /// <param name="outputFile">The file that contains the converted code.</param>
        public bool ScanAndConvert(string outputFile)
        {
            noSyncOn = false;
            string[] codeLines = ReadContent(SourceFile);
            int currentIndex = 0;
            int lineCounter = codeLines.Length;

            if (codeLines[codeLines.Length - 1].StartsWith(
                "// -embedded line, required for future conversions, do not alter- "))
            {
                if (Int32.TryParse(codeLines[codeLines.Length - 1].Substring(
                    "// -embedded line, required for future conversions, do not alter- ".Length), out whileLoopIndex))
                {
                }
                else
                {
                    whileLoopIndex = 0;
                }
            }

            while (currentIndex < lineCounter)
            {
                int currentLine = currentIndex + 1;
                string line = codeLines[currentIndex];
                ErrorTypes errorType = CheckForPragmas(line);

                switch (errorType)
                {
                    case ErrorTypes.Invalid:
                        break;
                    case ErrorTypes.Valid:
                        ErrorTypes returnType = FindScope(codeLines, currentIndex + 1, "while", true);
                        switch (returnType)
                        {
                            case ErrorTypes.Invalid:
                                break;
                            case ErrorTypes.Valid:
                                pragmaLine = currentLine;
                                ScopeScanner scanner = new ScopeScanner();
                                scanner.ParseString(scope);
                                InspectScope(scanner.ProgramInternalForm, currentLine + 1);
                                ConvertWhile(codeLines, outputFile);
                                ScanAndConvert(outputFile);
                                return true;
                            case ErrorTypes.Missing:
                                break;
                        }
                        break;
                }

                currentIndex++;
            }

            if (pragmaLine == 0)
            {
                return false;
            }
            return true;
        }
        /// <summary>
        /// Scans the given file and returns the errors that have occured.
        /// </summary>
        /// <returns>The list of errors that have occured during scanning.</returns>
        public override Error[] ScanFile()
        {
            List<Error> errorList = new List<Error>();
            List<string> temp = new List<string>();
            int lineCounter = 0;

            TextReader reader = null;

            try
            {
                reader = new StreamReader(SourceFile);

                string line = reader.ReadLine();
                while (line != null)
                {
                    lineCounter++;
                    temp.Add(line);
                    line = reader.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Logging.Log(ex.ToString());
                throw new Exception(ex.ToString());
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            string[] codeLines = temp.ToArray<string>();
            int currentIndex = 0;

            while (currentIndex < lineCounter)
            {
                int currentLine = currentIndex + 1;
                string line = codeLines[currentIndex];
                ErrorTypes errorType = CheckForPragmas(currentIndex, codeLines);

                switch (errorType)
                {
                    case ErrorTypes.Invalid:
                        errorList.Add(new Error(currentLine,
                            "Invalid parallel tasks pragma detected.\nUsage: //@ parallel tasks [pooled] [nosync] and it must end with //@ end tasks", 
                            WarningLevels.Fatal));
                        break;
                    case ErrorTypes.Valid:
                        validParallelTasks.Clear();
                        errorList.AddRange(ValidateTasks(currentIndex, codeLines));
                        Main.Application.PragmaLines.Add(currentLine - 1);
                        if (validParallelTasks.Count > 0)
                        {
                            foreach (int validTaskLine in validParallelTasks)
                            {
                                ErrorTypes returnType = FindScope(codeLines, validTaskLine + 1, "{", false);
                                switch (returnType)
                                {
                                    case ErrorTypes.Invalid:
                                        errorList.Add(new Error(validTaskLine + 2,
                                            "Invalid parallel task detected.\nMust be a scope enclosed in curly braces.",
                                            WarningLevels.Fatal));
                                        break;
                                    case ErrorTypes.Valid:
                                        ScopeScanner scanner = new ScopeScanner();
                                        scanner.ParseString(scope);
                                        errorList.AddRange(InspectScope(scanner.ProgramInternalForm, validTaskLine + 1));
                                        break;
                                    case ErrorTypes.Missing:
                                        errorList.Add(new Error(validTaskLine + 2,
                                            "Parallel task missing.",
                                            WarningLevels.Fatal));
                                        break;
                                }
                            }
                        }
                        break;
                }

                currentIndex++;
            }

            return errorList.ToArray<Error>();
        }
        /// Scans the given source code and converts it into parallel code.
        /// </summary>
        /// <param name="outputFile">The file that contains the converted code.</param>
        public bool ScanAndConvert(string outputFile)
        {
        scan:
            string[] codeLines = ReadContent(SourceFile);
            int lineCounter = codeLines.Length;
            int currentIndex = 0;

            if (codeLines[codeLines.Length - 1].StartsWith(
                "// -embedded line, required for future conversions, do not alter- "))
            {
                if (Int32.TryParse(codeLines[codeLines.Length - 1].Substring(
                    "// -embedded line, required for future conversions, do not alter- ".Length), out tasksIndex))
                {
                }
                else
                {
                    tasksIndex = 0;
                }
            }

            while (currentIndex < lineCounter)
            {
                int currentLine = currentIndex + 1;
                string line = codeLines[currentIndex];
                ErrorTypes errorType = CheckForPragmas(currentIndex, codeLines);

                switch (errorType)
                {
                    case ErrorTypes.Invalid:
                        break;
                    case ErrorTypes.Valid:
                        validParallelTasks.Clear();
                        pragmaLine = currentLine;
                        ValidateTasks(currentIndex, codeLines);

                        if (validParallelTasks.Count > 0)
                        {
                            int validTaskLine = validParallelTasks.First();
                            ErrorTypes returnType = FindScope(codeLines, validTaskLine + 1, "{", false);
                            switch (returnType)
                            {
                                case ErrorTypes.Invalid:
                                    break;
                                case ErrorTypes.Valid:
                                    pragmaLine = validTaskLine;
                                    ScopeScanner scanner = new ScopeScanner();
                                    scanner.ParseString(scope);
                                    InspectScope(scanner.ProgramInternalForm, validTaskLine + 1);
                                    ConvertTask(codeLines, outputFile);
                                    SourceFile = outputFile;
                                    goto scan;
                                case ErrorTypes.Missing:
                                    break;
                            }
                        }
                        else
                        {
                            ConvertTasks(codeLines, outputFile);
                            currentTask = 0;
                            SourceFile = outputFile;
                            isPooled = false;
                            noSyncOn = false;
                            goto scan;
                        }
                        break;
                }

                currentIndex++;
            }

            if (pragmaLine == 0)
            {
                return false;
            }
            return true;
        }
        /// <summary>
        /// Scans the given file and returns the errors that have occured.
        /// </summary>
        /// <returns>The list of errors that have occured during scanning.</returns>
        public override Error[] ScanFile()
        {
            List<Error> errorList = new List<Error>();
            List<string> temp = new List<string>();
            int lineCounter = 0;

            TextReader reader = null;

            try
            {
                reader = new StreamReader(SourceFile);

                string line = reader.ReadLine();
                while (line != null)
                {
                    lineCounter++;
                    temp.Add(line);
                    line = reader.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Logging.Log(ex.ToString());
                throw new Exception(ex.ToString());
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            string[] codeLines = temp.ToArray<string>();
            int currentIndex = 0;

            while (currentIndex < lineCounter)
            {
                int currentLine = currentIndex + 1;
                string line = codeLines[currentIndex];
                ErrorTypes errorType = CheckForPragmas(line);

                switch (errorType)
                {
                    case ErrorTypes.Invalid:
                        errorList.Add(new Error(currentLine,
                            "Invalid parallel for pragma detected.\nUsage: //@ parallel for static/dynamic [iterationCount] [nosync]" + 
                            "\r\nwhere iterationCount >= 0.", WarningLevels.Fatal));
                        break;
                    case ErrorTypes.Valid:
                        ErrorTypes returnType = FindScope(codeLines, currentIndex + 1, "for", true);
                        switch (returnType)
                        {
                            case ErrorTypes.Invalid:
                                errorList.Add(new Error(currentLine + 1,
                                    "Invalid for statement detected.\nMust be of the form: "
                                    + "for (type value = startValue; value < endValue; value++), the for body must be "
                                    + "enclosed in curly braces and the type must be int or long.",
                                    WarningLevels.Fatal));
                                break;
                            case ErrorTypes.Valid:
                                ScopeScanner scanner = new ScopeScanner();
                                scanner.ParseString(scope);
                                ErrorTypes newReturnType = ValidateFor(scanner.ProgramInternalForm);
                                switch (newReturnType)
                                {
                                    case ErrorTypes.Invalid:
                                        errorList.Add(new Error(currentLine + 1,
                                            "Invalid for statement detected.\nMust be of the form: "
                                            + "for (type value = startValue; value < endValue; value++), the for body must be "
                                            + "enclosed in curly braces and the type must be int or long.",
                                            WarningLevels.Fatal));
                                        break;
                                    case ErrorTypes.Valid:
                                        Main.Application.PragmaLines.Add(currentLine - 1);
                                        errorList.AddRange(InspectScope(scanner.ProgramInternalForm, currentLine + 1));
                                        break;
                                }
                                break;
                            case ErrorTypes.Missing:
                                errorList.Add(new Error(currentLine + 1,
                                    "For statement missing.",
                                    WarningLevels.Fatal));
                                break;
                        }
                        break;
                }

                currentIndex++;
            }

            return errorList.ToArray<Error>();
        }
        /// <summary>
        /// Scans the given file and returns the errors that have occured.
        /// </summary>
        /// <returns>The list of errors that have occured during scanning.</returns>
        public override Error[] ScanFile()
        {
            List<Error> errorList = new List<Error>();
            List<string> temp = new List<string>();
            int lineCounter = 0;
            TextReader reader = null;

            try
            {
                reader = new StreamReader(SourceFile);

                string line = reader.ReadLine();
                while (line != null)
                {
                    lineCounter++;
                    temp.Add(line);
                    line = reader.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Logging.Log(ex.ToString());
                throw new Exception(ex.ToString());
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            string[] codeLines = temp.ToArray<string>();
            int currentIndex = 0;

            while (currentIndex < lineCounter)
            {
                int currentLine = currentIndex + 1;
                string line = codeLines[currentIndex];
                ErrorTypes errorType = CheckForPragmas(line);

                switch (errorType)
                {
                    case ErrorTypes.Invalid:
                        errorList.Add(new Error(currentLine,
                            "Invalid parallel atomic pragma detected.\nUsage: //@ parallel atomic",
                            WarningLevels.Fatal));
                        break;
                    case ErrorTypes.Valid:
                        ErrorTypes returnType = FindAtomic(codeLines, currentIndex + 1);
                        switch (returnType)
                        {
                            case ErrorTypes.Invalid:
                                break;
                            case ErrorTypes.Valid:
                                ScopeScanner scanner = new ScopeScanner();
                                scanner.ParseString(scope);
                                ErrorTypes newReturnType = ValidateAtomic(scanner.ProgramInternalForm);
                                switch (newReturnType)
                                {
                                    case ErrorTypes.Invalid:
                                        errorList.Add(new Error(currentLine + 1,
                                            "Invalid atomic operation detected.\nMust be a single instruction and either " +
                                            "increment, decrement, addition or subtraction.",
                                            WarningLevels.Fatal));
                                        break;
                                    case ErrorTypes.Valid:
                                        Main.Application.PragmaLines.Add(currentLine - 1);
                                        break;
                                }
                                break;
                            case ErrorTypes.Missing:
                                errorList.Add(new Error(currentLine + 1,
                                    "Atomic instruction missing.",
                                    WarningLevels.Fatal));
                                break;
                        }
                        break;
                }

                currentIndex++;
            }

            return errorList.ToArray<Error>();
        }
        /// <summary>
        /// Scans the given file and returns the errors that have occured.
        /// </summary>
        /// <returns>The list of errors that have occured during scanning.</returns>
        public override Error[] ScanFile()
        {
            List<Error> errorList = new List<Error>();
            List<string> temp = new List<string>();
            int lineCounter = 0;

            TextReader reader = null;

            try
            {
                reader = new StreamReader(SourceFile);

                string line = reader.ReadLine();
                while (line != null)
                {
                    lineCounter++;
                    temp.Add(line);
                    line = reader.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Logging.Log(ex.ToString());
                throw new Exception(ex.ToString());
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            string[] codeLines = temp.ToArray<string>();
            int currentIndex = 0;

            while (currentIndex < lineCounter)
            {
                int currentLine = currentIndex + 1;
                string line = codeLines[currentIndex];
                ErrorTypes errorType = CheckForPragmas(line);

                switch (errorType)
                {
                    case ErrorTypes.Invalid:
                        errorList.Add(new Error(currentLine,
                            "Invalid parallel while pragma detected.\nUsage: //@ parallel while [nosync]"
                            , WarningLevels.Fatal));
                        break;
                    case ErrorTypes.Valid:
                        ErrorTypes returnType = FindScope(codeLines, currentIndex + 1, "while", true);
                        switch (returnType)
                        {
                            case ErrorTypes.Invalid:
                                errorList.Add(new Error(currentLine + 1,
                                    "Invalid while statement detected.\nMust be of the form: "
                                    + "while(condition) and the while body must be enclosed in curly braces.",
                                    WarningLevels.Fatal));
                                break;
                            case ErrorTypes.Valid:
                                ScopeScanner scanner = new ScopeScanner();
                                scanner.ParseString(scope);
                                errorList.AddRange(InspectScope(scanner.ProgramInternalForm, currentLine + 1));
                                Main.Application.PragmaLines.Add(currentLine - 1);
                                break;
                            case ErrorTypes.Missing:
                                errorList.Add(new Error(currentLine + 1,
                                    "While statement missing.",
                                    WarningLevels.Fatal));
                                break;
                        }
                        break;
                }

                currentIndex++;
            }

            return errorList.ToArray<Error>();
        }