示例#1
0
        private void ProcessPrimitive(Symbol Token, string Statement, int LineNumber, int Scope)
        {
            var    RegexMatch         = Token.Pattern.Match(Statement);
            string OperatorsPattern   = symbols.GetSymbolSet(TokenType.arithmetic);
            string ParenthesisPattern = symbols.GetSymbolSet(TokenType.OpenGrouper) + symbols.GetSymbolSet(TokenType.CloseGrouper);
            string AssigmentPattern   = symbols.GetSymbolSet(TokenType.assigment);

            var ArithmeticRegex = new Regex($"[{OperatorsPattern}{ParenthesisPattern}]");
            var AssigmentRegex  = new Regex($"[{AssigmentPattern}]");

            if (!RegexMatch.Success)
            {
                //Determina si es una expresion libre de contexto
                Match assigmentMatch = ArithmeticRegex.Match(Statement);

                if (assigmentMatch.Success)
                {
                    return;
                }


                symbols.AddError(new Error
                {
                    Analizer = AnalizerType.lexical,
                    Line     = LineNumber,
                    Message  = $"Invalid sintax for {Token.Id}",
                    Type     = "Sintax"
                });

                return;
            }

            var Identifier = RegexMatch.Groups[TokenType.identifier.ToString()];
            var Value      = RegexMatch.Groups[TokenType.value.ToString()];

            if (Identifier != null)
            {
                Symbol ScopeExistingToken = symbols.GetTokenInPreviousScope(Identifier.Value, Scope);
                if (ScopeExistingToken == null)
                {
                    semanticValidation(Identifier.Value, Value.Value, Token, LineNumber);

                    symbols.SetToken(new Symbol
                    {
                        Id       = $"{Identifier.Value}-scope-{Scope}",
                        IsCustom = true,
                        name     = Identifier.Value,
                        DataType = Token,
                        type     = TokenType.identifier,
                        Scope    = Scope
                    });


                    if (Value != null)
                    {
                        symbols.SetToken(new Symbol
                        {
                            Id       = $"{Identifier.Value}-scope-{Scope}_const",
                            Value    = Value.Value,
                            IsCustom = true,
                            type     = TokenType.value
                        });
                    }
                }
                else
                {
                    symbols.AddError(new Error
                    {
                        Analizer = AnalizerType.lexical,
                        Line     = LineNumber,
                        Message  = $"The  identifier {Identifier.Value} was already defined before.",
                        Type     = "Sintax"
                    });
                }
            }
        }