public ail.net.parser.GrammarSymbol AddSymbol(int xi_symbol_id, ail.net.parser.GrammarSymbol.EType xi_type, string xi_name) { ail.net.parser.GrammarSymbol result = (ail.net.parser.GrammarSymbol)PoolAttr[xi_symbol_id]; if (result == (object)null) { result = new ail.net.parser.GrammarSymbol(); result.Id = xi_symbol_id; result.Type = xi_type; result.Name = xi_name; PoolAttr[xi_symbol_id] = result; if (result.IsNonTerminal()) { NonTerminalCountAttr++; } else if (result.IsTerminal()) { TerminalCountAttr++; } } ail.net.framework.Assert.NonNullReference(result, "result"); result.AddRef(); return(result); }
public ail.net.parser.GrammarSymbol AddRhsSymbol(int xi_symbol_id, ail.net.parser.GrammarSymbol.EType xi_type, string xi_name) { ail.net.parser.GrammarSymbol result = GrammarPool.Instance.AddSymbol(xi_symbol_id, xi_type, xi_name); RhsAttr.Add(result); if (result.IsNonTerminal()) { RhsNonTerminalCountAttr++; } else if (result.IsTerminal()) { RhsTerminalCountAttr++; } return(result); }
public void RemoveSymbol(int xi_symbol_id) { ail.net.parser.GrammarSymbol symbol = (ail.net.parser.GrammarSymbol)PoolAttr[xi_symbol_id]; if (symbol != (object)null && symbol.Release() == 0) { if (symbol.IsNonTerminal()) { NonTerminalCountAttr--; } else if (symbol.IsTerminal()) { TerminalCountAttr--; } PoolAttr.Remove(symbol.Id); } }
private void BuildAstLevel(ail.net.parser.EarleyParser.Item xi_item, ail.net.parser.AstNode xi_root_node) { ail.net.framework.Assert.NonNullReference(xi_item, "xi_item"); ail.net.framework.Assert.NonNullReference(xi_root_node, "xi_root_node"); // populate a rhs stack with items of the current level Stack rhs_stack = new Stack(); PopulateRhsStack(rhs_stack, xi_item); // processing all nodes(items) of the level while (rhs_stack.Count > 0) { ail.net.parser.EarleyParser.Item curr_item = (ail.net.parser.EarleyParser.Item)rhs_stack.Pop(); ail.net.parser.GrammarSymbol symbol = (ail.net.parser.GrammarSymbol)curr_item.CoreItem.Rule.Rhs[curr_item.CoreItem.Dot - 1]; // 'dot-1', because we pushed items with 'dot' > 0 if (symbol.IsTerminal()) { // handle terminal Semantics.HandleTerminal(xi_root_node, curr_item.MasterChart.Token); } else if (symbol.IsNonTerminal()) { // handle non-terminal if (curr_item.Rptrs.Count <= 1) { // r-ptr has exactly one element ail.net.framework.Assert.Condition(curr_item.Rptrs.Count == 1, "ail.net.parser.EarleyParser.BuildAstLevel: curr_item.Rptrs.Count == 1"); ail.net.parser.EarleyParser.Item r_ptr_item = (ail.net.parser.EarleyParser.Item)curr_item.Rptrs[0]; ail.net.parser.AstNode new_node = Semantics.HandleNonTerminalBefore(xi_root_node, r_ptr_item); if (new_node != (object)null) { r_ptr_item.Flags |= (uint)ail.net.parser.EarleyParser.EFlags.eMarked; BuildAstLevel(r_ptr_item, new_node); r_ptr_item.Flags &= ~(uint)ail.net.parser.EarleyParser.EFlags.eMarked; } Semantics.HandleNonTerminalAfter(xi_root_node, r_ptr_item); } else { // r-ptr has more than one elements, ambiguity foreach (ail.net.parser.EarleyParser.Item r_ptr_item in curr_item.Rptrs.Values) { if ((r_ptr_item.Flags & (uint)ail.net.parser.EarleyParser.EFlags.eMarked) == 0) { ail.net.parser.AstNode new_node = Semantics.HandleNonTerminalBefore(xi_root_node, r_ptr_item); if (new_node != (object)null) { r_ptr_item.Flags |= (uint)ail.net.parser.EarleyParser.EFlags.eMarked; BuildAstLevel(r_ptr_item, new_node); r_ptr_item.Flags &= ~(uint)ail.net.parser.EarleyParser.EFlags.eMarked; Semantics.HandleNonTerminalAfter(xi_root_node, r_ptr_item); break; } } } } } } }