Beispiel #1
0
        public static NodeGroup GetGroups(PluginRoot Plugin, CodeString Code, char BracketLeft = '{', char BracketRight = '}')
        {
            var Ret   = new NodeGroup(Code);
            var State = Plugin.State;

            var List = RecognizerHelper.SplitToParameters(State, Code, ',');

            if (List == null)
            {
                return(null);
            }

            for (var i = 0; i < List.Length; i++)
            {
                var Param = List[i];
                if (Param.Length > 1 && Param[0] == BracketLeft && Param[Param.Length] == BracketLeft)
                {
                    Param = Param.Substring(1, Param.Length - 1).Trim();
                    Ret.Children.Add(Expressions.GetGroups(Plugin, Param));
                }
                else
                {
                    var Node = Expressions.Recognize(Param, Plugin);
                    if (Node == null)
                    {
                        return(null);
                    }

                    Ret.Children.Add(Node);
                }
            }

            return(Ret);
        }
Beispiel #2
0
        Macro ProcMacro(CodeString MLine)
        {
            var MacroName = MLine.Word();

            if (!MacroName.IsValidIdentifierName)
            {
                State.Messages.Add(MessageId.NotValidName, MacroName);
                return(null);
            }

            var Params   = new CodeString();
            var Handlers = State.Language.GlobalHandlers;

            if (MLine.Length > 0 && MLine[0] == '(')
            {
                var zp = MLine.GetBracketPos(false, Handlers);
                if (zp > 0)
                {
                    Params = MLine.Substring(1, zp - 1).Trim();
                    MLine  = MLine.Substring(zp + 1).Trim();
                }
            }

            List <string> ParamList = null;

            if (Params.IsValid)
            {
                var PStrList = RecognizerHelper.SplitToParameters(State, Params, ',');
                if (PStrList == null)
                {
                    return(null);
                }

                ParamList = new List <string>();
                for (var i = 0; i < PStrList.Length; i++)
                {
                    var String = PStrList[i].ToString();
                    if (!PStrList[i].IsValidIdentifierName)
                    {
                        State.Messages.Add(MessageId.WrongParamList, PStrList[i]);
                        return(null);
                    }

                    if (ParamList.Contains(String))
                    {
                        State.Messages.Add(MessageId.IdAlreadyDefined, PStrList[i]);
                        return(null);
                    }

                    ParamList.Add(String);
                }
            }

            MLine = MLine.Trim();
            if (MLine.Length > 0)
            {
                var Plugin = new PluginForDefine(Container, ParamList);
                var Node   = Expressions.CreateExpression(MLine, Plugin);

                if (Node != null)
                {
                    return(new Macro(MacroName, Node, ParamList));
                }
                else
                {
                    return(null);
                }
            }

            return(new Macro(MacroName, null, ParamList));
        }
Beispiel #3
0
 public CodeString[] SplitToParameters(CompilerState State, CodeString Self, bool EnableMessages = true)
 {
     return(RecognizerHelper.SplitToParameters(State, Self, ',', EnableMessages));
 }
Beispiel #4
0
        public SimpleRecResult Recognize(IdContainer Container, CodeString Code, GetIdOptions Options, ref Identifier Ret)
        {
            var Position = Code.Length - 1;

            if (Position >= 0 && Code[Position] == ']')
            {
                var State = Container.State;
                var ZPos  = Code.GetBracketPos(State, true, Options.EnableMessages);
                if (ZPos == -1)
                {
                    return(SimpleRecResult.Failed);
                }

                var Left = Code.TrimmedSubstring(State, 0, ZPos, Options.EnableMessages);
                if (!Left.IsValid)
                {
                    return(SimpleRecResult.Failed);
                }

                var TOptions = Options;
                TOptions.Func = x => x.RealId is Type;

                var TypeOfVals = Identifiers.Recognize(Container, Left, TOptions);
                if (TypeOfVals == null)
                {
                    return(SimpleRecResult.Failed);
                }

                var RTypeOfVals = TypeOfVals.RealId as Type;
                if (RTypeOfVals == null || (RTypeOfVals.TypeFlags & TypeFlags.CanBeArrayType) == 0)
                {
                    if (Options.EnableMessages)
                    {
                        State.Messages.Add(MessageId.UnknownId, Code);
                    }

                    return(SimpleRecResult.Failed);
                }

                var StrParams = Code.Substring(ZPos + 1, Position - ZPos - 1).Trim();
                if (StrParams.IsEqual("?"))
                {
                    Ret = new NonrefArrayType(Container, TypeOfVals, null);
                    if (Options.Func == null || Options.Func(Ret))
                    {
                        return(SimpleRecResult.Succeeded);
                    }
                }
                else if (StrParams.IsEqual("*"))
                {
                    if ((RTypeOfVals.TypeFlags & TypeFlags.CanBePointer) == 0)
                    {
                        if (Options.EnableMessages)
                        {
                            State.Messages.Add(MessageId.UnknownId, Code);
                        }

                        return(SimpleRecResult.Failed);
                    }

                    Ret = new PointerAndLength(Container, TypeOfVals);
                    if (Options.Func == null || Options.Func(Ret))
                    {
                        return(SimpleRecResult.Succeeded);
                    }
                }

                var SplParams = RecognizerHelper.SplitToParameters(State, StrParams,
                                                                   ',', Options.EnableMessages, true);

                if (SplParams == null)
                {
                    return(SimpleRecResult.Failed);
                }

                if (SplParams.Length == 0 || SplParams[0].Length == 0)
                {
                    for (var i = 0; i < SplParams.Length; i++)
                    {
                        if (SplParams[i].Length > 0)
                        {
                            State.Messages.Add(MessageId.NotExpected, SplParams[i]);
                            return(SimpleRecResult.Failed);
                        }
                    }

                    var IndexCount = SplParams.Length == 0 ? 1 : SplParams.Length;
                    Ret = new RefArrayType(Container, TypeOfVals, IndexCount);
                    if (Options.Func == null || Options.Func(Ret))
                    {
                        return(SimpleRecResult.Succeeded);
                    }
                }
                else
                {
                    var Plugin = Container.GetPlugin();
                    Plugin.GetPlugin <EvaluatorPlugin>().MustBeConst = true;

                    var Lengths = new int[SplParams.Length];
                    for (var i = 0; i < SplParams.Length; i++)
                    {
                        var Node    = Expressions.CreateExpression(SplParams[i], Plugin);
                        var ConstCh = Node as ConstExpressionNode;
                        if (ConstCh == null)
                        {
                            return(SimpleRecResult.Failed);
                        }

                        if (!(ConstCh.Type is NonFloatType))
                        {
                            if (Options.EnableMessages)
                            {
                                State.Messages.Add(MessageId.MustBeInteger, StrParams);
                            }

                            return(SimpleRecResult.Failed);
                        }

                        if (!VerifyArrayLength(State, ConstCh, StrParams, Options.EnableMessages))
                        {
                            return(SimpleRecResult.Failed);
                        }

                        Lengths[i] = (int)ConstCh.Integer;
                    }

                    Ret = new NonrefArrayType(Container, TypeOfVals, Lengths);
                    if (Options.Func == null || Options.Func(Ret))
                    {
                        return(SimpleRecResult.Succeeded);
                    }
                }
            }

            return(SimpleRecResult.Unknown);
        }