Esempio n. 1
0
        static public VariableCollection ExtractConstant(ref string RawCode, LogManager lm)
        {
            VariableCollection ret = new VariableCollection();
            Match m;
            int   indexr = 0;

            do
            {
                m = Regex.Match(RawCode, @"@#(?:[^#]+|##)*#|#(?:[^#\\]+|\\.)*#".Replace('#', '\"'), RegexOptions.Singleline);
                if (m.Success && m.Length > 0)
                {
                    ret.Add(new Variable("_text" + indexr.ToString(), m.Value));
                    RawCode = RawCode.Remove(m.Index, m.Length);
                    RawCode = RawCode.Insert(m.Index, "_text" + indexr.ToString());
                    indexr++;
                }
            } while (m.Success && m.Length > 0);

            indexr = 0;

            do
            {
                m = Regex.Match(RawCode, @"[ ,\+\*\/\-\{]\d+([.]?\d+)?(\^?\d+)?", RegexOptions.Singleline);
                if (m.Success && m.Length > 0)
                {
                    ret.Add(new Variable("_num" + indexr.ToString(), m.Value.TrimStart(' ', ',', '+', '-', '/', '*', '{')));
                    RawCode = RawCode.Remove(m.Index + 1, m.Length - 1);
                    RawCode = RawCode.Insert(m.Index + 1, "_num" + indexr.ToString());
                    indexr++;
                }
            } while (m.Success && m.Length > 0);

            return(ret);
        }
Esempio n. 2
0
        private void CreateVariable(CodeLine cl)
        {
            cl.Code = cl.Code.Trim();
            string[] ret  = cl.Code.Split(' ');
            string   code = cl.Code;

            if (Regex.IsMatch(cl.Code, @"crea vettore [a-z][\w]*(\s?\{[\w\W]+\})* [\w\W]+", RegexOptions.IgnoreCase))
            {
                vc.Add(new Variable(ret[2], 0));

                code = code.Remove(0, ret[0].Length + ret[1].Length + ret[2].Length + 2).Trim();
                res.AddLine(Tabul(cl.IndentLevel) + "Variable " + ret[2] + " = new Variable(\"" + ret[2] + "\"," + AnalyzeCode(code, cl.LineNumber) + ");", lm);
            }
            else if (Regex.IsMatch(cl.Code, @"crea [a-z][\w]*(\s?\{[\w\W]+\})* [\w\W]+", RegexOptions.IgnoreCase))
            {
                vc.Add(new Variable(ret[1]));

                code = code.Remove(0, ret[0].Length + ret[1].Length + 1).Trim();
                res.AddLine(Tabul(cl.IndentLevel) + "Variable " + ret[1] + " = new Variable(\"" + ret[1] + "\"," + AnalyzeCode(code, cl.LineNumber) + ");", lm);
            }
            else
            {
                lm.Add("The creation of the variable at the line gone wrong", cl.LineNumber);
            }
        }