Exemplo n.º 1
0
            public override void EnterCat([NotNull] lbnfParser.CatContext context)
            {
                if (context.Identifier() == null)
                {
                    return;
                }
                var id = context.Identifier().GetText();

                if (context.Parent is lbnfParser.DefContext ||
                    context.Parent is lbnfParser.CatContext)
                {
                    var     frontier = TreeEdits.Frontier(context);
                    var     list     = frontier.Select(t => t.Symbol).ToList();
                    ISymbol sym      = new NonterminalSymbol(id, list);
                    _pd.RootScope.define(ref sym);
                    CombinedScopeSymbol s = (CombinedScopeSymbol)sym;
                    _pd.Attributes[context] = new List <CombinedScopeSymbol>()
                    {
                        s
                    };
                    foreach (var tr in frontier)
                    {
                        _pd.Attributes[tr] = new List <CombinedScopeSymbol>()
                        {
                            s
                        }
                    }
                    ;
                }
            }
        }
            public override void EnterSymbol([NotNull] W3CebnfParser.SymbolContext context)
            {
                var token_ref = context.SYMBOL();

                if (token_ref != null)
                {
                    for (var parent = context.Parent; parent != null; parent = parent.Parent)
                    {
                        if (parent is W3CebnfParser.LhsContext)
                        {
                            return;
                        }
                    }
                    string         id   = token_ref.GetText();
                    List <ISymbol> list = _pd.RootScope.LookupType(id).ToList();
                    if (!list.Any())
                    {
                        ISymbol sym = new NonterminalSymbol(id, new List <IToken>()
                        {
                            token_ref.Symbol
                        });
                        _pd.RootScope.define(ref sym);
                        list = _pd.RootScope.LookupType(id).ToList();
                    }
                    List <CombinedScopeSymbol> new_attrs = new List <CombinedScopeSymbol>();
                    CombinedScopeSymbol        s         = new RefSymbol(new List <IToken>()
                    {
                        token_ref.Symbol
                    }, list);
                    new_attrs.Add(s);
                    _pd.Attributes[context]   = new_attrs;
                    _pd.Attributes[token_ref] = new_attrs;
                }
            }
Exemplo n.º 3
0
        public static void ResetGlobalVariables(
            Action <MessageTypeOrDestinationEnum, String> outputMessage,
            Action <MessageTypeOrDestinationEnum, String, Int32> outputMessageAndPosition)
        {
            // Reset all settings
            GlobalSettings.Reset();

            UnifiedString.Reset();

            // Reset all static variables
            NumberOfActions            = 0;
            OutputMessage              = outputMessage;
            OutputMessageAndPosition   = outputMessageAndPosition;
            NumberOfTerminalSymbols    = 0;
            NumberOfNonterminalSymbols = 0;
            Startsymbol = new NonterminalSymbol(new UnifiedString("*Startsymbol"),
                                                position: 0,
                                                symbolNumber: 0,
                                                attributetypeStringList: Array.Empty <UnifiedString>(),
                                                attributenameStringList: Array.Empty <UnifiedString>()
                                                // trivalDefinitionsArray: Array.Empty<Symbol>(), // the startsymbol will not have any trival definitions: default
                                                // nontrivalDefinitionsList: ... // will be set after the startsymbol: default (empty list)
                                                );


            ListOfAllHaltActions.Clear();
            ListOfAllHaltActions.Capacity = InitialCapacityOfListOfAllHaltActions;
            ListOfAllHaltActions.Add(new HaltAction(IdNumber: 0, AttributestackAdjustement: 0));

            TerminalSymbols    = Array.Empty <TerminalSymbol>();
            AllTerminalSymbols = EmptyBitarray;

            ListOfAllStates.Clear();
            ListOfAllStates.Capacity = InitialCapacityOfListOfAllStates;

            ListOfAllErrorhandlingActions.Clear();
            ListOfAllErrorhandlingActions.Capacity = InitialCapacityOfListOfAllStates;

            ListOfAllReductions.Clear();
            ListOfAllReductions.Capacity = InitialCapacityOfListOfAllReductions;

            ListOfAllBranchActions.Clear();
            ListOfAllBranchActions.Capacity = InitialCapacityOfListOfAllBranchActions;

            ListOfAllPushStateActions.Clear();
            ListOfAllPushStateActions.Capacity = InitialCapacityOfListOfAllPushStateActions;

            ListOfAllPrioritySelectActions.Clear();
            ListOfAllPrioritySelectActions.Capacity = InitialCapacityOfListOfAllPrioritySelectActions;

            ListOfAllPriorityBranchActions.Clear();
            ListOfAllPriorityBranchActions.Capacity = InitialCapacityOfListOfAllPriorityBranchActions;
        }
Exemplo n.º 4
0
 static GlobalVariables()
 {
     Startsymbol = new NonterminalSymbol(new UnifiedString("*Startsymbol"),
                                         position: 0,
                                         symbolNumber: 0,
                                         attributetypeStringList: Array.Empty <UnifiedString>(),
                                         attributenameStringList: Array.Empty <UnifiedString>()
                                         );
     TerminalSymbols          = Array.Empty <TerminalSymbol>();
     OutputMessage            = OutputToNirwana;
     OutputMessageAndPosition = OutputToNirwana;
     Startaction = new DeletedParserAction();
 }
Exemplo n.º 5
0
            public override void EnterCat([NotNull] lbnfParser.CatContext context)
            {
                if (context.Identifier() == null)
                {
                    return;
                }
                var id = context.Identifier().GetText();

                if (!(context.Parent is lbnfParser.ItemContext))
                {
                    return;
                }

                var            frontier = TreeEdits.Frontier(context);
                List <ISymbol> prior    = _pd.RootScope.LookupType(id).ToList();

                if (!prior.Any())
                {
                    var     listp = frontier.Select(t => t.Symbol).ToList();
                    ISymbol symp  = new NonterminalSymbol(id, listp);
                    _pd.RootScope.define(ref symp);
                    prior = _pd.RootScope.LookupType(id).ToList();
                }
                var list = frontier.Select(t => t.Symbol).ToList();
                List <CombinedScopeSymbol> new_attrs = new List <CombinedScopeSymbol>();
                CombinedScopeSymbol        s         = new RefSymbol(list, prior);

                new_attrs.Add(s);
                _pd.Attributes[context] = new_attrs;
                _pd.Attributes[context] = new List <CombinedScopeSymbol>()
                {
                    s
                };
                foreach (var tr in frontier)
                {
                    _pd.Attributes[tr] = new List <CombinedScopeSymbol>()
                    {
                        s
                    }
                }
                ;
            }
        }
Exemplo n.º 6
0
        public override void EnterRuleref([NotNull] ANTLRv4Parser.RulerefContext context)
        {
            TerminalNodeImpl first = context.GetChild(0) as TerminalNodeImpl;
            string           id    = context.GetChild(0).GetText();
            IList <ISymbol>  list  = _pd.RootScope.LookupType(id);

            if (!list.Any())
            {
                ISymbol sym = new NonterminalSymbol(id, first.Symbol);
                _pd.RootScope.define(ref sym);
            }
            List <CombinedScopeSymbol> new_attrs = new List <CombinedScopeSymbol>();

            foreach (ISymbol sym in list)
            {
                CombinedScopeSymbol s = new RefSymbol(first.Symbol, sym);
                new_attrs.Add(s);
            }
            _pd.Attributes[context]             = new_attrs;
            _pd.Attributes[context.GetChild(0)] = new_attrs;
        }
Exemplo n.º 7
0
        public GrammarDefinition(
            bool isCaseInsensitive,
            string lineComment,
            string startBlockComment,
            string endBlockComment,
            IEnumerable <RegexDefinition> regexDefinitions,
            IEnumerable <CharsetDefinition> charsetDefinitions,
            IReadOnlyDictionary <GrammarProduction, string> productionNames,
            IEnumerable <GrammarProduction> productions,
            NonterminalSymbol startingSymbol) : base(productions, startingSymbol)
        {
            IsCaseInsensitive  = isCaseInsensitive;
            LineComment        = lineComment;
            StartBlockComment  = startBlockComment;
            EndBlockComment    = endBlockComment;
            ProductionNames    = productionNames;
            RegexDefinitions   = regexDefinitions.ToList().AsReadOnly();
            CharsetDefinitions = charsetDefinitions.ToList().AsReadOnly();
            ExtractKeywords();
            Validate();
            ComputeTable();

            var charsetByName = new Dictionary <string, CharsetDefinition>();

            this.CharsetByName = charsetByName;
            foreach (var item in CharsetDefinitions)
            {
                charsetByName[item.Name] = item;
            }

            var regexByName = new Dictionary <string, RegexDefinition>();

            this.RegexByName = regexByName;
            foreach (var item in RegexDefinitions)
            {
                regexByName[item.Name] = item;
            }
        }
Exemplo n.º 8
0
        public override void EnterParserRuleSpec([NotNull] ANTLRv4Parser.ParserRuleSpecContext context)
        {
            int i;

            for (i = 0; i < context.ChildCount; ++i)
            {
                if (!(context.GetChild(i) is TerminalNodeImpl))
                {
                    continue;
                }

                TerminalNodeImpl c = context.GetChild(i) as TerminalNodeImpl;
                if (c.Symbol.Type == ANTLRv4Lexer.RULE_REF)
                {
                    break;
                }
            }
            if (i == context.ChildCount)
            {
                return;
            }

            TerminalNodeImpl rule_ref = context.GetChild(i) as TerminalNodeImpl;
            string           id       = rule_ref.GetText();
            ISymbol          sym      = new NonterminalSymbol(id, rule_ref.Symbol);

            _pd.RootScope.define(ref sym);
            CombinedScopeSymbol s = (CombinedScopeSymbol)sym;

            _pd.Attributes[context] = new List <CombinedScopeSymbol>()
            {
                s
            };
            _pd.Attributes[context.GetChild(i)] = new List <CombinedScopeSymbol>()
            {
                s
            };
        }
            public override void EnterSymbol([NotNull] W3CebnfParser.SymbolContext context)
            {
                var token_ref = context.SYMBOL();

                if (token_ref != null && context.Parent is W3CebnfParser.LhsContext)
                {
                    string  id  = token_ref.GetText();
                    ISymbol sym = new NonterminalSymbol(id, new List <IToken>()
                    {
                        token_ref.Symbol
                    });
                    _pd.RootScope.define(ref sym);
                    CombinedScopeSymbol s = (CombinedScopeSymbol)sym;
                    _pd.Attributes[context] = new List <CombinedScopeSymbol>()
                    {
                        s
                    };
                    _pd.Attributes[token_ref] = new List <CombinedScopeSymbol>()
                    {
                        s
                    };
                }
            }