Beispiel #1
0
        public static ICASMDirective ParseDirective(Scope _currentScope, string statement)
        {
            statement = statement.Trim();
            LiteralGrammarElement lge = new LiteralGrammarElement("import", "reflect", "ewfc", "+var", "-var", "+pool", "-pool",
                                                                  "+fields", "+field", "-field", "-fields", "+typespace", "-typespace", "+type", "-type", "-all",
                                                                  "+function", "-function", "call", "assign", "jump", "return", "clear", "if", "elseif", "else",
                                                                  "while", "repeat", "end+");
            TestResult <bool> directiveKeywordResult = lge.Validate(ref statement, true);
            string            directiveKeyword       = (string)directiveKeywordResult["Symbol"];

            statement = statement.Trim();
            ICASMDirectiveType type = ICASMDirective.GetTypeFromString(directiveKeyword);
            ICASMTagType       tag  = ICASMTagType.None;

            if (statement.StartsWith("-"))
            {
                LiteralGrammarElement tagChecker       = new LiteralGrammarElement("-help", "-path", "-none", "-suppress", "-temporary", "-random", "-report", "-variable", "-pool", "-type", "-typespace");
                TestResult <bool>     tagKeywordResult = tagChecker.Validate(ref statement, true);
                if (tagKeywordResult.Result)
                {
                    string tagKeyword = (string)tagKeywordResult["Symbol"];
                    tag = ICASMDirective.GetTagTypeFromString(tagKeyword);
                }
            }
            string innerstatement = null;

            statement = statement.Trim();
            if (type == ICASMDirectiveType.AssignDirective && statement.StartsWith("("))
            {
                innerstatement = statement.Trim().Substring(1, statement.LastIndexOf(')') - 1).Trim();
                statement      = statement.Substring(statement.LastIndexOf(')') + 1).Trim();
                ICASMDirective       innerdirective = ICASMInterpreter.ParseDirective(_currentScope, innerstatement);
                ICASMExecutionResult innerresult    = ICASMInterpreter.Execute(_currentScope, innerdirective);
                if (innerresult.Data.ContainsKey("CallDirective"))
                {
                    statement = ((Address)innerresult.Data["CallDirective"]).FullPath + " " + statement;
                }
            }
            string[] paramstrs = statement.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            ICASMDirectiveParameters parameters = new ICASMDirectiveParameters();
            string str        = "";
            bool   stringopen = false;

            foreach (string param in paramstrs)
            {
                ICASMValue value = null;
                if (!stringopen && param.StartsWith("\"") && !param.EndsWith("\""))
                {
                    stringopen = true;
                    str        = param + " ";
                }
                else if (stringopen || (param.StartsWith("\"") && param.EndsWith("\"")))
                {
                    str = str + param + " ";
                    if (param.EndsWith("\""))
                    {
                        stringopen = false;
                        value      = ICASMValue.ParseValue(str.Trim());
                        str        = "";
                    }
                }
                else
                {
                    value = ICASMValue.ParseValue(param);
                }
                if (value != null)
                {
                    parameters.Add(value);
                }
            }
            return(new ICASMDirective(type, tag, parameters));
        }