Пример #1
0
 public static LanguageProcessor.ParsedLine ParseLine(string line)
 {
     LanguageProcessor.ParsedLine parsedLine = new LanguageProcessor.ParsedLine();
     string[] strArray = line.Split(new char[1] {
         ','
     }, StringSplitOptions.RemoveEmptyEntries);
     parsedLine.name    = strArray [0].Trim();
     parsedLine.number1 = strArray [1].Trim().GetValue();
     parsedLine.number2 = strArray [2].Trim().GetValue();
     if (strArray.Length > 3)
     {
         List <string> stringList = new List <string> ((IEnumerable <string>)strArray [3].Split(" -".GetArray <string> (), StringSplitOptions.RemoveEmptyEntries));
         for (int index = 0; index < stringList.Count; ++index)
         {
             stringList [index] = stringList [index].Trim();
         }
         parsedLine.flags = stringList.ToArray();
     }
     else
     {
         parsedLine.flags = new string[0];
     }
     return(parsedLine);
 }
Пример #2
0
 public void SetMainLine(string line)
 {
     this.IsParameter = char.IsWhiteSpace(line [0]);
     this.mainLine    = line;
     this.parsedLine  = LanguageProcessor.ParsedLine.ParseLine(line);
 }
Пример #3
0
            public static TemplateParameter ParseParameter(LanguageProcessor.ParsedLine line)
            {
                int      minDimensions   = 1;
                int      maxDimensions   = 1;
                bool     pointer         = false;
                bool     isFixed         = false;
                bool     signed          = false;
                int      valueBase       = 16;
                Priority pointedPriority = Priority.none;

                foreach (string flag in line.flags)
                {
                    if (flag.Length != 0)
                    {
                        int num1 = flag.IndexOf(':');
                        if (flag.StartsWith("pointer"))
                        {
                            pointer = true;
                            if (num1 > 0)
                            {
                                string str = flag.Substring(num1 + 1);
                                if (((IEnumerable <string>)Enum.GetNames(typeof(Priority))).Contains <string> (str))
                                {
                                    pointedPriority = (Priority)Enum.Parse(typeof(Priority), str);
                                }
                            }
                        }
                        else if (flag.StartsWith("coordinates") || flag.StartsWith("coordinate"))
                        {
                            if (num1 < 0)
                            {
                                throw new FormatException("No : in option " + flag);
                            }
                            string s = flag.Substring(num1 + 1);
                            if (s.Contains("-"))
                            {
                                string[] strArray = s.Split('-');
                                minDimensions = int.Parse(strArray [0]);
                                maxDimensions = int.Parse(strArray [1]);
                            }
                            else
                            {
                                int num2 = int.Parse(s);
                                minDimensions = num2;
                                maxDimensions = num2;
                            }
                        }
                        else if (flag.StartsWith("preferredBase"))
                        {
                            if (num1 < 0)
                            {
                                throw new FormatException("No : in option " + flag);
                            }
                            valueBase = flag.Substring(num1 + 1).GetValue();
                        }
                        else if (flag.StartsWith("fixed"))
                        {
                            isFixed = true;
                        }
                        else
                        {
                            if (!flag.StartsWith("signed"))
                            {
                                throw new FormatException("Unknown option " + flag + " in parameter " + line.name);
                            }
                            signed = true;
                        }
                    }
                }
                TemplateParameter templateParameter = new TemplateParameter(line.name, line.number1, line.number2, minDimensions, maxDimensions, pointer, pointedPriority, signed, isFixed);

                templateParameter.SetBase(valueBase);
                return(templateParameter);
            }
Пример #4
0
        private ICodeTemplate ParseCode(IList <LanguageProcessor.LanguageElement> lines, ICollection <string> usedLanguages, out Priority priority)
        {
            LanguageProcessor.ParsedLine parsedLine1 = lines [0].ParsedLine;
            priority = Priority.none;
            bool canBeRepeated    = false;
            bool chechForProblems = true;
            bool end = false;
            bool canBeDisassembled = true;
            bool canBeAssembled    = true;
            int  num1  = 1;
            bool flag1 = false;
            byte num2  = 0;
            int  num3  = 4;

            foreach (string flag2 in parsedLine1.flags)
            {
                if (flag2.StartsWith("language") || flag2.StartsWith("game"))
                {
                    string[] strArray = flag2.Split(new char[1] {
                        ':'
                    }, StringSplitOptions.RemoveEmptyEntries);
                    for (int index = 1; index < strArray.Length; ++index)
                    {
                        usedLanguages.Add(strArray [index].Trim());
                    }
                }
                else if (flag2.StartsWith("priority"))
                {
                    int    num4 = flag2.IndexOf(':');
                    string str  = flag2.Substring(num4 + 1);
                    if (!((IEnumerable <string>)Enum.GetNames(typeof(Priority))).Contains <string> (str))
                    {
                        throw new FormatException("Error in enum priority: " + flag2);
                    }
                    priority = (Priority)Enum.Parse(typeof(Priority), str);
                }
                else if (flag2.StartsWith("repeatable"))
                {
                    canBeRepeated = true;
                }
                else if (flag2.StartsWith("unsafe"))
                {
                    chechForProblems = false;
                }
                else if (flag2.StartsWith("end"))
                {
                    end = true;
                }
                else if (flag2.StartsWith("noDisassembly"))
                {
                    canBeDisassembled = false;
                }
                else if (flag2.StartsWith("noAssembly"))
                {
                    canBeAssembled = false;
                }
                else if (flag2.StartsWith("indexMode"))
                {
                    int num4 = flag2.IndexOf(':');
                    num1 = int.Parse(flag2.Substring(num4 + 1));
                }
                else if (flag2.StartsWith("terminatingList"))
                {
                    int num4 = flag2.IndexOf(':');
                    num2  = (byte)int.Parse(flag2.Substring(num4 + 1));
                    flag1 = true;
                }
                else
                {
                    if (!flag2.StartsWith("offsetMod"))
                    {
                        throw new FormatException("Unknown option " + flag2 + " in parameter " + parsedLine1.name);
                    }
                    int num4 = flag2.IndexOf(':');
                    num3 = (int)(byte)int.Parse(flag2.Substring(num4 + 1));
                }
            }
            parsedLine1.number2 = parsedLine1.number2 * num1;
            List <TemplateParameter> templateParameterList = new List <TemplateParameter> ();

            for (int index = 1; index < lines.Count; ++index)
            {
                LanguageProcessor.ParsedLine parsedLine2 = lines [index].ParsedLine;
                parsedLine2.number1 *= num1;
                parsedLine2.number2 *= num1;
                TemplateParameter parameter = LanguageProcessor.ParsedLine.ParseParameter(parsedLine2);
                templateParameterList.Add(parameter);
            }
            return(!flag1 ? (ICodeTemplate) new CodeTemplate(parsedLine1.name, parsedLine1.number1, parsedLine1.number2, (IEnumerable <TemplateParameter>)templateParameterList, canBeRepeated, chechForProblems, end, num3, canBeAssembled, canBeDisassembled, this.stringComparer) : (ICodeTemplate) new TerminatingStringTemplate(parsedLine1.name, (IEnumerable <TemplateParameter>)templateParameterList, (int)num2, num3, this.stringComparer));
        }