public void Compile()
        {
            if (state >= State.Compiled)
            {
                return;
            }
            GenerateCode();
            lock (this)
            {
                if (state >= State.Compiled)
                {
                    return;
                }

                using (var codeProvider = new CSharpCodeProvider())
                {
                    compilerParameters.OutputAssembly = "";
                    Directory.CreateDirectory(TempLocation);
                    compilerParameters.TempFiles = new TempFileCollection(TempLocation, false);
                    prg = codeProvider.CompileAssemblyFromSource(compilerParameters, ProgramText);
                }
                if (prg.Errors.Count > 0)
                {
                    var lines = ProgramText.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
                    throw new InvalidExpressionException(string.Format("{0} in expression \"{1}\"",
                                                                       prg.Errors[0].ErrorText,
                                                                       prg.Errors[0].Line > 0 ? lines[prg.Errors[0].Line - 1] : "<source code not found>"));
                }
                state = State.Compiled;
            }
        }
Esempio n. 2
0
        /*
         *  ---------------- / CONSTRUCTOR ----------------
         */

        /*
         *  ---------------- PUBLIC METHODS ----------------
         */

        public char GetChar() /* Get the frontmost input character from the string if there is one */
        {
            /* Local Variables */
            char retVal;                /* Character to send out                    */

            /* / Local Variables */

            /* Return a null terminator to allow other objects to know there is no more input */
            if (ProgramText.Length == 0)
            {
                return(NULL_TERMINATOR);
            }

            /* Return the first character in the input buffer and remove it from the buffer */
            retVal = ProgramText[0];

            ProgramText = ProgramText.Substring(1, ProgramText.Length - 1);
            ++Position;

            /* Update the line number IF: the current character is a newline*/

            if (retVal == NEWLINE)
            {
                ++LineNumber;
            }

            return(retVal);
        }
        private void ExecuteAddRow(object obj)
        {
            int           count   = ProgramText.Count(ch => ch == '\r');
            StringBuilder builder = new StringBuilder();

            for (int i = 1; i <= count + 1; i++)
            {
                builder.Append(i + Environment.NewLine);
            }
            Rows = builder.ToString();
        }
Esempio n. 4
0
        public void Save()
        {
            string fileName = FileName;

            if (!FileName.EndsWith(".txt"))
            {
                int extensionLocation = fileName.LastIndexOf('.');
                if (extensionLocation != -1)
                {
                    fileName = fileName.Remove(extensionLocation);
                }
                fileName = fileName + ".txt";
            }
            using (StreamWriter sw = new StreamWriter(fileName, false)) {
                sw.Write(ProgramText.Replace("\r", "").Replace("\n", Environment.NewLine));
            }
            Dirty = false;
        }