Пример #1
0
        /// <summary>
        ///     Generate the code from the AST we have.
        /// </summary>
        /// <param name="script">The LSL source as a string.</param>
        /// <returns>String containing the generated C# code.</returns>
        public string Convert(string script)
        {
            //Unless we are using the same LSL_Converter instance for all scripts, we don't need to reset this
            //ResetCounters();

            LSL2CSCodeTransformer codeTransformer;
            try
            {
                //               lock (p)
                {
                    codeTransformer = new LSL2CSCodeTransformer(p.Parse(script));
                    //                    p.m_lexer.Reset();
                }
            }
            catch (CSToolsException e)
            {
                string message;

                // LL start numbering lines at 0 - geeks!
                // Also need to subtract one line we prepend!
                //
                string emessage = e.Message;
                string slinfo = e.slInfo.ToString();

                // Remove wrong line number info
                //
                if (emessage.StartsWith(slinfo + ": "))
                    emessage = emessage.Substring(slinfo.Length + 2);

                if (e.slInfo.lineNumber - 1 <= 0)
                    e.slInfo.lineNumber = 2;
                if (e.slInfo.charPosition - 1 <= 0)
                    e.slInfo.charPosition = 2;

                message = String.Format("({0},{1}) {2}",
                                        e.slInfo.lineNumber - 1,
                                        e.slInfo.charPosition - 1, emessage);

                m_compiler.AddError(message);
                //                p.m_lexer.Reset();
                ResetCounters();
                return "Error parsing the script. " + message;
            }

            SYMBOL root = codeTransformer.Transform(LocalMethods, LocalMethodArguements);
            DuplicatedGlobalVariables = codeTransformer.DuplicatedGlobalVars;
            DuplicatedLocalVariables = codeTransformer.DuplicatedLocalVars;
            OriginalScript = script;
            StringBuilder retVal = new StringBuilder();

            // line number
            //m_CSharpLine += 3;

            // here's the payload
            retVal.Append(GenerateLine());
            foreach (SYMBOL s in root.kids)
                retVal.Append(GenerateNode(s));

            retVal.Append(GenerateFireEventMethod());

            // Removes all carriage return characters which may be generated in Windows platform. 
            //Is there a cleaner way of doing this?
            string returnstring = retVal.ToString().Replace("\r", "");

            try
            {
                CheckEventCasts(returnstring);
            }
            catch (InvalidOperationException ex)
            {
                m_compiler.AddError(ex.Message);
                return ex.Message;
            }
            return CreateCompilerScript(m_compiler, MethodsToAdd, returnstring);
        }
Пример #2
0
        /// <summary>
        /// Generate the code from the AST we have.
        /// </summary>
        /// <param name="script">The LSL source as a string.</param>
        /// <returns>String containing the generated C# code.</returns>
        public string Convert(string script)
        {
            ResetCounters();

            LSL2CSCodeTransformer codeTransformer;
            try
            {
 //               lock (p)
                {
                    codeTransformer = new LSL2CSCodeTransformer(p.Parse(script));
//                    p.m_lexer.Reset();
                }
            }
            catch (CSToolsException e)
            {
                string message;

                // LL start numbering lines at 0 - geeks!
                // Also need to subtract one line we prepend!
                //
                string emessage = e.Message;
                string slinfo = e.slInfo.ToString();

                // Remove wrong line number info
                //
                if (emessage.StartsWith(slinfo + ": "))
                    emessage = emessage.Substring(slinfo.Length + 2);

                if (e.slInfo.lineNumber - 1 <= 0)
                    e.slInfo.lineNumber = 2;
                if (e.slInfo.charPosition - 1 <= 0)
                    e.slInfo.charPosition = 2;

                message = String.Format("({0},{1}) {2}",
                        e.slInfo.lineNumber - 1,
                        e.slInfo.charPosition - 1, emessage);

                m_compiler.AddError(message);
//                p.m_lexer.Reset();
                ResetCounters();
                return "Error parsing the script. " + message;
            }

            m_astRoot = codeTransformer.Transform(LocalMethods, LocalMethodArguements);
            OriginalScript = script;
            string returnstring = "";

            // line number
            //m_CSharpLine += 3;

            // here's the payload
            returnstring += GenerateLine();
            foreach (SYMBOL s in m_astRoot.kids)
                returnstring += GenerateNode(s);

            // Removes all carriage return characters which may be generated in Windows platform. 
            //Is there a cleaner way of doing this?
            returnstring = returnstring.Replace("\r", "");

            CheckEventCasts(returnstring);
            return CreateCompilerScript(returnstring);
        }
Пример #3
0
        /// <summary>
        /// Generate the code from the AST we have.
        /// </summary>
        /// <param name="script">The LSL source as a string.</param>
        /// <returns>String containing the generated C# code.</returns>
        public string Convert(string script)
        {
            ResetCounters();

            try
            {
                if (m_SLCompatabilityMode && false) // :/ its terribly slow! plus it really should be a job for the parser too...
                {
                    script = CheckForInlineVectors(script);

                    script = CheckFloatExponent(script);
                }
            }
            catch (Exception ex)
            {
                string message = "Syntax error before conversion - " + ex.Message;

                throw new Exception(message);
            }

            LSL2CSCodeTransformer codeTransformer;
            try
            {
                codeTransformer = new LSL2CSCodeTransformer(p.Parse(script));
            }
            catch (CSToolsException e)
            {
                string message;

                // LL start numbering lines at 0 - geeks!
                // Also need to subtract one line we prepend!
                //
                string emessage = e.Message;
                string slinfo = e.slInfo.ToString();

                // Remove wrong line number info
                //
                if (emessage.StartsWith(slinfo + ": "))
                    emessage = emessage.Substring(slinfo.Length + 2);

                if (e.slInfo.lineNumber - 1 <= 0)
                    e.slInfo.lineNumber = 2;
                if (e.slInfo.charPosition - 1 <= 0)
                    e.slInfo.charPosition = 2;

                message = String.Format("({0},{1}) {2}, line: {3}",
                        e.slInfo.lineNumber - 1,
                        e.slInfo.charPosition - 1, emessage, e.slInfo.sourceLine);

                throw new Exception(message);
            }

            m_astRoot = codeTransformer.Transform(LocalMethods);
            OriginalScript = script;
            string returnstring = "";

            // line number
            m_CSharpLine += 3;

            // here's the payload
            returnstring += GenerateLine();
            foreach (SYMBOL s in m_astRoot.kids)
                returnstring += GenerateNode(s);

            // Removes all carriage return characters which may be generated in Windows platform. 
            //Is there a cleaner way of doing this?
            returnstring = returnstring.Replace("\r", "");

            CheckEventCasts(returnstring);
            return CreateCompilerScript(returnstring);
        }
Пример #4
0
        /// <summary>
        /// Generate the code from the AST we have.
        /// </summary>
        /// <param name="script">The LSL source as a string.</param>
        /// <returns>String containing the generated C# code.</returns>
        public string Convert(string script)
        {
            ResetCounters();
            
            LSL2CSCodeTransformer codeTransformer;
            try
            {
                codeTransformer = new LSL2CSCodeTransformer(p.Parse(script));
            }
            catch (CSToolsException e)
            {
                string message;

                // LL start numbering lines at 0 - geeks!
                // Also need to subtract one line we prepend!
                //
                string emessage = e.Message;
                string slinfo = e.slInfo.ToString();

                // Remove wrong line number info
                //
                if (emessage.StartsWith(slinfo+": "))
                    emessage = emessage.Substring(slinfo.Length + 2);

                if (e.slInfo.lineNumber - 1 <= 0)
                    e.slInfo.lineNumber = 2;
                if (e.slInfo.charPosition - 1 <= 0)
                    e.slInfo.charPosition = 2;

                message = String.Format("({0},{1}) {2}, line: {3}",
                        e.slInfo.lineNumber - 1,
                        e.slInfo.charPosition - 1, emessage, e.slInfo.sourceLine);

                throw new Exception(message);
            }

            m_astRoot = codeTransformer.Transform();
            OriginalScript = script;
            StringBuilder returnstring = new StringBuilder();

            // line number
            m_CSharpLine += 3;

            // here's the payload
            returnstring.Append(GenerateLine());
            foreach (SYMBOL s in m_astRoot.kids)
                returnstring.Append(GenerateNode(s));

            // Removes all carriage return characters which may be generated in Windows platform. 
            //Is there a cleaner way of doing this?
            returnstring = returnstring.Replace("\r", "");

            CheckEventCasts(returnstring.ToString());
            return CreateCompilerScript(returnstring);
        }