Exemple #1
0
        //Metodi pubblici
        public ResultCode Translate(CodeType type, string Code, string[] PackagesPath, string ExoprtPath)
        {
            PackageCollection pc     = PackageCollection.LoadPackageByFile(PackagesPath, lm);
            CodeImage         code   = CodeImage.CreateCodeImage(Code, pc, type, lm);
            ResultCode        result = new ResultCode(ExoprtPath);

            if (lm.WithOutError)
            {
                for (int i = 0; i < code.Package.Count; i++)
                {
                    result.AddInclude(code.Package[i].Name, lm);
                }

                int general = pc.FirstIndexOf("GENERAL");
                if (general < 0)
                {
                    lm.Add("Cannot find the main package for the program execution");
                }
                else
                {
                    code.Package.Add(pc[general]);
                }

                result.AddBlankLine();

                if (code.Type == CodeType.Program)
                {
                    result.AddLine("namespace Leggermente.Programma{ class Program{", lm);
                }
                else
                {
                    result.AddLine("namespace Leggermente.lib." + code.PackageName + "{ class " + code.PackageName + "{", lm);
                }

                WriteConstant(code, result);
                if (lm.WithOutError)
                {
                    Parsing(code, result);
                }

                result.AddBlankLine();
                result.AddLine("} }", lm);

                WriteCsDocumets(result);
            }
            return(result);
        }
Exemple #2
0
        public void WriteConstant(CodeImage ci, ResultCode res)
        {
            VariableCollection vc = ci.Constant;

            res.AddBlankLine();
            for (int i = 0; i < vc.Count; i++)
            {
                res.AddLine("static const int " + vc[i].Name + " = new Variable(" + vc[i].Name + ", " + vc[i].Value + ");", lm);
            }
            res.AddBlankLine();
        }
Exemple #3
0
        public void AnalyzeFunction(FunctionSection fs)
        {
            vc      = new VariableCollection();
            this.fs = fs;
            bool findReturn = false;

            res.AddLine(GenerateSign(fs.Function), lm);

            AnalyzeCodeLines(fs.FunctionCodes);

            for (int i = 0; i < fs.FunctionCodes.Count && findReturn == false; i++)
            {
                if (Regex.IsMatch(fs.FunctionCodes[i].Code, @"ritorna", RegexOptions.IgnoreCase))
                {
                    findReturn = true;
                }
            }
            if (!findReturn && fs.Function.Name.ToLower() != "programma")
            {
                res.AddLine("\treturn new Variable(\"NULL\",null);", lm);
            }


            res.AddLine("}", lm);
        }