/// <summary> /// initialization of living storage /// </summary> void InitLivingStorage() { foreach (var abs in Productions.GetTools("living")) { m_livingStorages.Add(abs.m_toolLink as Items); } }
/* Using statistics... * * U, T * * Var * Univ * Type: * Quantifier * Shift * Construct * Destruct: U, T, K * */ private static IEnumerable <Bits> EncodeTerm(Productions production) { switch (production) { case Productions.Variable: return(new Bits[] { Bits.Zero, Bits.Zero }); case Productions.Destructor: return(new Bits[] { Bits.Zero, Bits.One }); case Productions.Constructor: return(new Bits[] { Bits.One, Bits.Zero }); case Productions.Type: return(new Bits[] { Bits.One, Bits.One, Bits.Zero }); case Productions.Universe: return(new Bits[] { Bits.One, Bits.One, Bits.One }); default: throw new InvalidProgramException("Should never happen."); } }
private void addClosures(SingleState <SYMBOL_ENUM, TREE_NODE> sourceState, Productions <SYMBOL_ENUM, TREE_NODE> productions, int lookaheadWidth) { if (!sourceState.HasIncomingSymbol) { return; } // find productions for that symbol foreach (Production <SYMBOL_ENUM, TREE_NODE> prod in productions.FilterByLhs(sourceState.IncomingSymbol)) { SingleState <SYMBOL_ENUM, TREE_NODE> existing; // getting "impostor" object just for sake of FAST comparison (no memory allocations) if (items.TryGetValue(SingleState <SYMBOL_ENUM, TREE_NODE> .CreateClosureComparisonStateFrom(prod), out existing)) // [@STATE_EQ] { // switching closure links to existing state existing.AddClosureParent(sourceState); } else { // creating real state object var state = SingleState <SYMBOL_ENUM, TREE_NODE> .CreateClosureStateFrom(InternalId, items.Count, sourceState, prod); items.Add(state); addClosures(state, productions, lookaheadWidth); // recursive call } } }
public IList <EbnfMessage> DeclareImplicitTerminals() { var result = new List <EbnfMessage>(); var terms = new HashSet <EbnfExpression>(); var done = new HashSet <EbnfExpression>(); foreach (var prod in Productions) { _VisitFetchTerminals(prod.Value.Expression, terms); if (prod.Value.Expression.IsTerminal) { done.Add(prod.Value.Expression); } } foreach (var term in terms) { if (!done.Contains(term)) { var prod = new EbnfProduction(); prod.Expression = ((ICloneable)term).Clone() as EbnfExpression; var newId = _GetImplicitTermId(); Productions.Add(newId, prod); result.Add(new EbnfMessage(EbnfErrorLevel.Message, -1, "Terminal was implicitly declared.", term.Line, term.Column, term.Position)); } } return(result); }
public void TestGrammarComments() { Productions commentLaden = Productions.Parse(@" /* comment /* comment */rule/*comm:nent */:a? ( /*coomnet*/b | c/*comm)ent*/);"); Productions simple = Productions.Parse("rule : a? ( b | c );"); Assert.AreEqual(commentLaden[0].ToString(), simple[0].ToString()); }
public ActionResult DeleteConfirmed(int id) { Productions productions = db.Productions.Find(id); db.Productions.Remove(productions); db.SaveChanges(); return(RedirectToAction("Index")); }
private static IEnumerable <Bits> EncodeTerm(IUniverse universe, Productions production) { if (universe.Rank == 0) { return(EncodeTerm(production)); } return(EncodeType(production)); }
public void Add(string tokenId, object prodObj) { Productions.Add(new KeyValuePair <string, object>(tokenId, prodObj)); if (!ProductionsByTokenId.TryGetValue(tokenId, out List <object> prodObjs)) { ProductionsByTokenId.Add(tokenId, prodObjs = new List <object>()); } prodObjs.Add(prodObj); }
public void SelectParentItem(object obj) { int id = (int)obj; Productions del = ProductionsList.First(d => d.ProductionId == id); int index = ProductionsList.IndexOf(del); SelectedProductionId = index; }
private void PREDICTOR(State state, int k, HashSet <State> Sk) { //Ne sjecam se u kom slucaju je trebalo provjeriti da budu razlicite produkcije, ali to je ocito visak foreach (Production by in Productions.Where(prod => prod.Name.Equals(state.NextElement().Name)))// && prod != state.Production)) { State adding = new State(by, 0, k); Sk.Add(adding); } }
internal void Clear() { Symbols.Clear(); CharacterSets.Clear(); Productions.Clear(); FAStates.Clear(); LRActionLists.Clear(); Groups.Clear(); }
public override int GetHashCode() { unchecked { int hashCode = StartElement.GetHashCode(); hashCode = (hashCode * 397) ^ EndOfInputElement.GetHashCode(); hashCode = (hashCode * 397) ^ Productions.GetHashCode(); return(hashCode); } }
internal void AddClosuresAndLookaheads(Productions <SYMBOL_ENUM, TREE_NODE> productions, Dictionary <Production <SYMBOL_ENUM, TREE_NODE>, Dictionary <int, SymbolChunkSet <SYMBOL_ENUM> > > precomputedRhsFirsts, int lookaheadWidth) { foreach (SingleState <SYMBOL_ENUM, TREE_NODE> seed in items.ToList()) { addClosures(seed, productions, lookaheadWidth); } addClosuresLookaheads(precomputedRhsFirsts, lookaheadWidth); }
public override string ToString() { var str = string.Empty; str += $"Start: {Start}" + Environment.NewLine; str += $"Epsilon: {Epsilon}" + Environment.NewLine; str += string.Join(Environment.NewLine, Productions.OrderByDescending(x => x.Order)); return(str); }
public ActionResult Edit([Bind(Include = "ID,Name,depId,is_delete,create_time,create_user")] Productions productions) { productions.create_time = DateTime.Now; if (ModelState.IsValid) { db.Entry(productions).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(productions)); }
public void RemoveProduction(int index) { try { Productions.RemoveAt(index); } catch (Exception) { throw new ArgumentException("Неверный индекс"); } }
public void BindReturn <TResultNode, TBaseNode>(Grammar <TToken, TBaseNode> .ParserRule <TResultNode> rule) where TResultNode : TBaseNode where TBaseNode : class { var transition = new ParserProduction(new ParserEntry[] { rule }) { Name = typeof(TResultNode).Name, Binding = ConstructorParserProductionBinding.Bind <TResultNode>(), Unwrap = true }; Productions.Add(transition); }
// GET: Projects public ActionResult Index() { var pjts = db.Projects.ToList(); foreach (var pjt in pjts) { Productions productions = db.Productions.Find(pjt.prd_id); pjt.prd_Name = productions.Name; } return(View(pjts)); }
public void Build(string[] Input) { try { Start = Input[0][0]; foreach (string s in Input) { if (s == string.Empty) { continue; } string[] tp = s.Split(new String[] { "→" }, StringSplitOptions.None); if (tp.Length != 2) { throw new Exception("产生式应该有且仅有一个→"); } if (tp[0].Length != 1 || !isVn(tp[0][0])) { throw new Exception("产生式左边应该是一个非终结符"); } char left = tp[0][0]; char empty = System.Configuration.ConfigurationManager.AppSettings["Empty"][0]; Vn.Add(left); string[] right = tp[1].Split('|'); for (int i = 0; i < right.Count(); ++i) { string part = right[i]; foreach (char c in part) { if (isVn(c)) { Vn.Add(c); } else { Vt.Add(c); } } Production p = new Production(left, part); if (!ProductionsMap.ContainsKey(p)) { Productions.Add(p); ProductionsMap.Add(p, ProductionsMap.Count() + 1); _ProductionsMap.Add(_ProductionsMap.Count() + 1, p); } } } } catch (Exception) { throw new Exception("输入不合法\n"); } }
string _GetImplicitTermId() { var result = "implicit"; var i = 2; while (Productions.ContainsKey(result)) { result = string.Concat("implicit", i.ToString()); ++i; } return(result); }
/// <summary> /// Open item after research. /// Here: getting tools for production /// Could be changed by children /// </summary> public override void OpenItem() { List <ItemsEffect> tools = new List <ItemsEffect>(); foreach (string prod in m_productionType) { foreach (ItemsEffect effect in Productions.GetTools(prod.Trim())) { tools.Add(effect); } } foreach (var tool in tools) { if (tool.m_toolLink.m_isItOpen > 0) { bool hasItThesame = false; foreach (var eff in m_tools) { hasItThesame |= eff.m_toolLink.m_name == tool.m_toolLink.m_name; } if (hasItThesame) { continue; } else { try { ItemsEffect neff = new ItemsEffect(tool); m_tools.Add(neff); ArrowScript asc = ArrowScript.NewArrowScript(neff.m_toolLink.m_thisObject, m_thisObject); asc.m_isItTool = true; m_thisObject.m_toolsTo.Add(asc); neff.m_toolLink.m_thisObject.m_toolsFrom.Add(asc); } catch (Exception ex) { Debug.LogError(ex.Message); } } } } for (int i = 0; i < 10; i++) { m_productQueue.Enqueue(0); } base.OpenItem(); }
private void ValidateNoUndeclaredNonterminal() { foreach (var item in Productions) { foreach (var nt in item.Body.Where(x => x is NonterminalSymbol).Cast <NonterminalSymbol>()) { if (!Productions.Any(x => x.Head == nt)) { throw new GrammarException(new Location(), $"símbolo {nt} não declarado"); } } } }
CreateDfa <SYMBOL_ENUM, TREE_NODE>(Productions <SYMBOL_ENUM, TREE_NODE> productions, int lookaheadWidth, Dictionary <Production <SYMBOL_ENUM, TREE_NODE>, Dictionary <int, SymbolChunkSet <SYMBOL_ENUM> > > precomputedRhsFirsts, HorizonSets <SYMBOL_ENUM> horizonSets) where SYMBOL_ENUM : struct where TREE_NODE : class { SingleState <SYMBOL_ENUM, TREE_NODE> .SyntaxErrorSymbol = productions.SyntaxErrorSymbol; var worker = new Worker <SYMBOL_ENUM, TREE_NODE>(productions, lookaheadWidth, precomputedRhsFirsts, horizonSets); return(worker.Dfa); }
/// <summary> /// parsing excel data into current format /// </summary> /// <param name="itm">target</param> /// <param name="repItm">source</param> /// <returns> parsed item </returns> public static new AbstractObject Parse(AbstractObject itm, ExcelLoading.AbstractObject repItm) { Localization loc = Localization.GetLocalization(); ExcelLoading.ScienceItem rep = (ExcelLoading.ScienceItem)repItm; Science scs = (Science)itm; scs.m_repItem = rep; scs.m_tooltipCount = loc.m_ui.m_scienceCount; scs.m_tooltipProductivity = loc.m_ui.m_scienceProductivity; Productions.AddProduction(scs, "science"); return(GameAbstractItem.Parse(itm, repItm)); }
// GET: Productions/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Productions productions = db.Productions.Find(id); if (productions == null) { return(HttpNotFound()); } return(View(productions)); }
public ActionResult Create([Bind(Include = "ID,Name,depId,is_delete,create_time,create_user")] Productions productions) { productions.create_time = DateTime.Now; productions.is_delete = 0; if (ModelState.IsValid) { db.Productions.Add(productions); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(productions)); }
private void FixupProdRefNodes() { foreach (var node in _astNodeFactory.AllNodes.Where(p => p.AstNodeType == AstNodeType.ProdRef)) { var prodRefNode = (IProdRefNode)node; var prodInfo = Productions.FirstOrDefault(p => p.Name == prodRefNode.ProdName); if (prodInfo == null) { throw new SemanticErrorException($"Definition for production {prodRefNode.ProdName} not found."); } prodRefNode.Expression = prodInfo.Statement.Expression; } }
public BuilderHorizonSets(Productions <SYMBOL_ENUM, TREE_NODE> productions, int lookaheadWidth, FirstSets <SYMBOL_ENUM> firstSets, CoverSets <SYMBOL_ENUM> coverSets, FollowSets <SYMBOL_ENUM> followSets) : base(productions, lookaheadWidth) { this.firstSets = firstSets; this.followSets = followSets; this.coverSets = coverSets; if (!coverSets.HasNonTerminals || lookaheadWidth != coverSets.LookaheadWidth) { throw new ArgumentException("Internal error."); } }
private void SetupView(Productions productions) { if (_isSetupDone) { return; } foreach (var config in productions.Config) { var buildingInfo = GetBuildingInfo(); buildingInfo.SetupView(config); buildingInfo.OnBuildingSelected += OnBuildingSelected; } _isSetupDone = true; }
// GET: Productions/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Productions productions = db.Productions.Find(id); Departments departments = db.departments.Find(productions.depId); productions.DepName = departments.Name; if (productions == null) { return(HttpNotFound()); } return(View(productions)); }