public override bool CreateNonTerminal(Lexer lex, ProductionStorage ps) { // Don't have fraction yet //get the leading PA string p; if (ps.MatchProduction(Selmaho.PA, out p)) PAs.Add(p); else return false; while (true) { if (ps.MatchProduction(Selmaho.PA, out p)) PAs.Add(p); else break; //if we didn't match a PA, then stop trying. } //eat the BOI that might be there ps.MatchProduction(Selmaho.BOI); ConstructNumber(); return true; }
public override bool CreateNonTerminal(Lexer lex, ProductionStorage ps) { Mex1 m1; if (ps.MatchProduction<Mex1>(out m1)) { result = m1; //( operator mex-1 | operand * operator KUhE? ) * while (true) { Operator op; Mex1 m12; List<NonTerminal> o = new List<NonTerminal>(); //( operator mex1 ) int save = lex.Position; if (ps.MatchProduction<Operator>(out op) && ps.MatchProduction<Mex1>(out m12)) { //if we're done this, then we have the whole bracket. //turn it into an infix result = new Infix(result, op, m12); } //(operand * operator KUhE?) else { //undo any damage from the first bit lex.Seek(save); //put the leading mex1 into the operand list o.Add(m1); //operand * while (true) { Operand oper; if(ps.MatchProduction<Operand>(out oper)) o.Add(oper); else break; } //operator if (ps.MatchProduction<Operator>(out op)) { result = new RP(o, op); } else { lex.Seek(save); break; // havent matched an infix or an rp } ps.MatchProduction(Selmaho.KUhE); } } return true; } else return false; //you have to match a Mex1 first }
protected override void BeginProduction() { base.BeginProduction(); for (int i = 0; i < ProductionRequirements.Count; ++i) { ProductionStorage.Remove(ProductionStorage.Find(x => x == ProductionRequirements[i])); } }
public Parser(Lexer l) { lex = l; ProductionStorage ps = new ProductionStorage(l); if (!ps.MatchProduction<Mex>(out Result)) throw new ParseError("Parse failed.", l.Current); if (l.Current.Type != Selmaho.EndOfStream) throw new ParseError("Parse ended before end of input.", l.Current); }
public override bool CreateNonTerminal(Lexer lex, ProductionStorage ts) { if (lex.Current.Type == Selmaho.Operator) { _Operator = lex.Advance(); return true; } return false; }
public override bool CreateNonTerminal(Lexer lex, ProductionStorage ps) { string by; // get the leading ( BY | A BU ) if (ps.MatchProduction(Selmaho.BY, out by)) { if (by.Length == 2) by = by[0].ToString(); _String += by; } else if (lex.Peek.Type == Selmaho.BU) { string l = lex.Advance(); if (l.Length > 1) l = "(" + l + ")"; _String += l; lex.Advance();//eat the bu } else { return false; } while(true) { if (ps.MatchProduction(Selmaho.BY, out by)) { if (by.Length == 2) by = by[0].ToString(); _String += by; } else if (lex.Peek.Type == Selmaho.BU) { string l = lex.Advance(); if (l.Length > 1) l = "(" + l + ")"; _String += l; lex.Advance();//eat the bu } else break; } //eat the BOI that might be there ps.MatchProduction(Selmaho.BOI); return true; }
protected override void BeginProduction() { base.BeginProduction(); for (int i = 0; i < ProductionRequirements.Count; ++i) { if (ProductionRequirements[i] != Products.Food) { ProductionStorage.Remove(ProductionStorage.Find(x => x == ProductionRequirements[i])); } else { RemoveFoodFromStorage(); } } }
private void RemoveFoodFromStorage() { if (!ProductionStorage.Remove(Products.Fish)) { if (!ProductionStorage.Remove(Products.Fruit)) { if (!ProductionStorage.Remove(Products.Water)) { if (!ProductionStorage.Remove(Products.Meat)) { if (!ProductionStorage.Remove(Products.Wine)) { ProductionStorage.Remove(Products.Bread); } } } } } }
public override bool CreateNonTerminal(Lexer lex, ProductionStorage ps) { int save = lex.Position; //try to match an option PEhO ps.MatchProduction(Selmaho.PEhO); if (ps.MatchProduction<Operator>(out _operator)) { //try to get as many op as we can do { Operand _o; if (ps.MatchProduction<Operand>(out _o)) { _args.Add(_o); } else break; } while (true); // Polish expressions have to have at least one argument if (_args.Count == 0) { lex.Seek(save); return false; } //try to grab an optional KUhE ps.MatchProduction(Selmaho.KUhE); return true; } //we failed. return false; }
/// <summary> /// This isn't a parsing class. It is semantic. /// </summary> /// <param name="lex"></param> /// <param name="ps"></param> /// <returns></returns> public override bool CreateNonTerminal(Lexer lex, ProductionStorage ps) { return false; }
/// <summary> /// A method to fill out this object by eating through the token stream. It returns true if it matched it's construction, advanced all the tokens it used. /// Else it returns false, with the Lexer at the position is started at. /// </summary> /// <param name="lex"></param> /// <param name="ts"></param> /// <returns></returns> public abstract bool CreateNonTerminal(Lexer lex, ProductionStorage ps);