Beispiel #1
0
        private int DoWhile(CodeLineCollection cc)
        {
            res.AddLine(Tabul(cc[0].IndentLevel) + "do{", lm);
            CodeLineCollection sup = cc.ExtractSubIndentation(cc[0].LineNumber);

            cc = cc.Extractor(sup.Count + 1);

            AnalyzeCodeLines(sup);

            if (Regex.IsMatch(cc[0].Code, @"quando [\w\W]+", RegexOptions.IgnoreCase))
            {
                if (cc.Count == 1)
                {
                    cc[0].Code = cc[0].Code.Trim();
                    int indx = cc[0].Code.IndexOf(' ');

                    res.AddLine(Tabul(cc[0].IndentLevel) + "}while(" + AnalyzeCode(cc[0].Code.Substring(indx, cc[0].Code.Length - indx).Trim(), cc[0].LineNumber) + ");", lm);
                }
                else
                {
                    lm.Add("Something gone wrong at this line", cc[0].LineNumber);
                }
            }
            else
            {
                lm.Add("The programm cannot find the 'quando' condition", cc[0].LineNumber);
            }
            return(0);
        }
Beispiel #2
0
        private void CaseAction(CodeLineCollection cc, string varName)
        {
            if (cc != null && cc.Count > 0)
            {
                cc[0].Code = cc[0].Code.Trim();
                if (Regex.IsMatch(cc[0].Code, @"se [\W\w]+", RegexOptions.IgnoreCase))
                {
                    int indx = cc[0].Code.IndexOf(' ') + 1;

                    res.AddLine(Tabul(cc[0].IndentLevel) + "if(" + AnalyzeCode(varName + " " + cc[0].Code.Substring(indx, cc[0].Code.Length - indx).Trim(), cc[0].LineNumber) + "){", lm);

                    CodeLineCollection sup = cc.ExtractSubIndentation(cc[0].LineNumber);
                    AnalyzeCodeLines(sup);

                    res.AddLine(Tabul(cc[0].IndentLevel) + "}else ", lm);

                    sup = cc.Extractor(sup.Count + 1);
                    if (sup == null || sup.Count <= 0)
                    {
                        lm.Add("The translator cannot find the 'Altrimenti' tag");
                    }
                    CaseAction(sup, varName);
                }
                else if (Regex.IsMatch(cc[0].Code, @"altrimenti", RegexOptions.IgnoreCase))
                {
                    int indx = cc[0].Code.IndexOf(' ') + 1;

                    res.AddLine(Tabul(cc[0].IndentLevel) + "{", lm);

                    CodeLineCollection sup = cc.ExtractSubIndentation(cc[0].LineNumber);
                    AnalyzeCodeLines(sup);

                    res.AddLine(Tabul(cc[0].IndentLevel) + "}", lm);
                    if (cc.Extractor(sup.Count + 1).Count > 0)
                    {
                        lm.Add("The 'altrimenti' must be the last tag in the switch");
                    }
                }
                else
                {
                    lm.Add("Cannot translate the line in the switch", cc[0].LineNumber);
                }
            }
        }
Beispiel #3
0
        private int SwitchAction(CodeLineCollection cc)
        {
            cc[0].Code = cc[0].Code.Trim();
            int    indx = cc[0].Code.IndexOf(' ') + 1;
            string name = cc[0].Code.Substring(indx, cc[0].Code.Length - indx);

            CaseAction(cc.Extractor(1), name);

            return(cc.Count);
        }
Beispiel #4
0
        private int IfAction(CodeLineCollection cc)
        {
            cc[0].Code = cc[0].Code.Trim();
            int indx = cc[0].Code.IndexOf(' ') + 1;

            res.AddLine(Tabul(cc[0].IndentLevel) + "if(" + AnalyzeCode(cc[0].Code.Substring(indx, cc[0].Code.Length - indx).Trim(), cc[0].LineNumber) + "){", lm);

            AnalyzeCodeLines(cc.Extractor(1));

            res.AddLine(Tabul(cc[0].IndentLevel) + "}", lm);
            return(cc.Count);
        }
Beispiel #5
0
        private int WhileAction(CodeLineCollection cc)
        {
            cc[0].Code = cc[0].Code.Trim();
            int indx = Regex.Match(cc[0].Code, "ripeti quando ", RegexOptions.IgnoreCase).Length;

            res.AddLine(Tabul(cc[0].IndentLevel) + "while(" + AnalyzeCode(cc[0].Code.Substring(indx, cc[0].Code.Length - indx).Trim(), cc[0].LineNumber) + "){", lm);

            AnalyzeCodeLines(cc.Extractor(1));

            res.AddLine(Tabul(cc[0].IndentLevel) + "}", lm);

            return(cc.Count);
        }
Beispiel #6
0
        private int ForAction(CodeLineCollection cc)
        {
            cc[0].Code = cc[0].Code.Trim();
            int    indx  = Regex.Match(cc[0].Code, @"ripeti ", RegexOptions.IgnoreCase).Length;
            int    lnght = Regex.Match(cc[0].Code, @" volte ", RegexOptions.IgnoreCase).Index;
            string name  = "indice";

            if (Regex.IsMatch(cc[0].Code, @"ripeti [\w\W]+ volte [a-zA-Z][\w]*", RegexOptions.IgnoreCase))
            {
                int indx2 = Regex.Match(cc[0].Code, @"ripeti [\w\W]+ volte ", RegexOptions.IgnoreCase).Length;
                name = cc[0].Code.Substring(indx2, cc[0].Code.Length - indx2);
            }

            res.AddLine(Tabul(cc[0].IndentLevel) + "for( Variable " + name + " = new (\"" + name + "\", 0) ; " + name + " < " + AnalyzeCode(cc[0].Code.Substring(indx, lnght - indx).Trim(), cc[0].LineNumber) + " ; " + name + " += (new Variable(\"_\",1)) ){", lm);
            vc.Add(new Variable(name, ""));

            AnalyzeCodeLines(cc.Extractor(1));

            vc.Remove(new Variable(name, ""));
            res.AddLine(Tabul(cc[0].IndentLevel) + "{", lm);

            return(cc.Count);
        }
Beispiel #7
0
        private void AnalyzeCodeLines(CodeLineCollection cc)
        {
            if (cc != null && cc.Count > 0)
            {
                if (Regex.IsMatch(cc[0].Code, @"crea (vettore )?[a-z][\w]*(\s?\{[\w\W]+\})* [\w\W]+", RegexOptions.IgnoreCase))
                {
                    CreateVariable(cc[0]);
                    AnalyzeCodeLines(cc.Extractor(1));
                }
                else if (Regex.IsMatch(cc[0].Code, @"cambia [a-z][\w]*(\s?\{[\w\W]+\})* [\w\W]+", RegexOptions.IgnoreCase))
                {
                    ChangeVariable(cc[0]);
                    AnalyzeCodeLines(cc.Extractor(1));
                }
                else if (Regex.IsMatch(cc[0].Code, @"se [\W\w]+", RegexOptions.IgnoreCase))
                {
                    cc = cc.Extractor(IfAction(cc.ExtractSubIndentation(cc[0].LineNumber, true)));
                    if (Regex.IsMatch(cc[0].Code, @"altrimenti", RegexOptions.IgnoreCase))
                    {
                        AnalyzeCodeLines(cc.Extractor(ElseAction(cc.ExtractSubIndentation(cc[0].LineNumber), cc[0].IndentLevel)));
                    }
                }
                else if (Regex.IsMatch(cc[0].Code, @"controlla [\W\w]+", RegexOptions.IgnoreCase))
                {
                    AnalyzeCodeLines(cc.Extractor(SwitchAction(cc.ExtractSubIndentation(cc[0].LineNumber, true))));
                }
                else if (Regex.IsMatch(cc[0].Code, @"ripeti quando [\w\W]+", RegexOptions.IgnoreCase))
                {
                    AnalyzeCodeLines(cc.Extractor(WhileAction(cc.ExtractSubIndentation(cc[0].LineNumber, true))));
                }
                else if (Regex.IsMatch(cc[0].Code, @"ripeti [\w\W]+ volte", RegexOptions.IgnoreCase))
                {
                    AnalyzeCodeLines(cc.Extractor(ForAction(cc.ExtractSubIndentation(cc[0].LineNumber, true))));
                }
                else if (Regex.IsMatch(cc[0].Code, @"ripeti", RegexOptions.IgnoreCase))
                {
                    CodeLineCollection sup = cc.ExtractSubIndentation(cc[0].LineNumber, true);
                    sup.Add(cc.Extractor(sup.Count)[0]);

                    AnalyzeCodeLines(cc.Extractor(DoWhile(sup)));
                }
                else if (Regex.IsMatch(cc[0].Code, @"ritorna [\w\W]+", RegexOptions.IgnoreCase))
                {
                    ReturnAction(cc[0]);
                    AnalyzeCodeLines(cc.Extractor(1));
                }
                else if (Regex.IsMatch(cc[0].Code, @"[\w\W]+", RegexOptions.IgnoreCase))
                {
                    FunctionAction(cc[0]);
                    AnalyzeCodeLines(cc.Extractor(1));
                }
                else
                {
                    lm.Add("Nothing is possible to translate at this line", cc[0].LineNumber);
                }
            }
        }