private void Quant(ref IPhrase aPhr) { // look for quantifier here if (lex != null && (lex.Text == "{" || lex.Text == "*" || lex.Text == "+" || lex.Text == "?")) { ExprInt lMin = null, lMax = null; //{1..5} if (lex.Text == "{") { lex = lex.Next(); lMin = ParseIntValue(); if (lex.Text == ".") { lex = lex.Next(); ExpectSign("."); if (lex.Text == "*") { lMax = new ExprInt(Int32.MaxValue); } else { lMax = ParseIntValue(); } } else { lMax = lMin; } ExpectSign("}"); } else if (lex.Text == "*") { lMin = new ExprInt(0); lMax = new ExprInt(int.MaxValue); lex = lex.Next(); } else if (lex.Text == "+") { lMin = new ExprInt(1); lMax = new ExprInt(int.MaxValue); lex = lex.Next(); } else if (lex.Text == "?") { lMin = new ExprInt(0); lMax = new ExprInt(1); lex = lex.Next(); } else { throw new GrammarSyntaxException("Недолжно быть. Неподдерживаемый знак после нетерминала " + lex.Text); } QuantifiedPhrase lQuant = new QuantifiedPhrase(mGrammar, aPhr, lMin, lMax); aPhr = lQuant; } }
//Seq := T | NT | "(",Phrase,")" private IPhrase Seq() { if (lex == null) { throw new GrammarSyntaxException("unexpected end of rule"); } IPhrase lPhr; if (lex.Type == LexemType.LeftBr) { lex = lex.Next(); lPhr = ParsePhrase(); Expect(LexemType.RightBr, ")"); Quant(ref lPhr); } else if (lex.Type == LexemType.Sign && lex.Text == "[") { lex = lex.Next(); lPhr = new QuantifiedPhrase(mGrammar, ParsePhrase(), 0, 1); ExpectSign("]"); } else if (lex.Type == LexemType.Sign && lex.Text == "{") { lex = lex.Next(); lPhr = new QuantifiedPhrase(mGrammar, ParsePhrase()); ExpectSign("}"); } else if (lex.Type == LexemType.Sign && lex.Text == "<") { lex = lex.Next(); if (lex.Type != LexemType.NotTerminal) { throw new GrammarSyntaxException("Name expected"); } string lName = lex.Text; lex = lex.Next(); ExpectSign(">"); lPhr = PlaceHolderAssign(lName); Quant(ref lPhr); } else if (lex.Text == "#") { lex = lex.Next(); lPhr = Expr(); } else { //терминальный или не терминальный if (lex.Type == LexemType.Terminal) { lPhr = new Terminal(mGrammar, lex.Text); lex = lex.Next(); } else if (lex.Type == LexemType.NotTerminal) { lPhr = TransCall(); } else { throw new GrammarSyntaxException("Terminal or Non-Terminal symbol expected"); } Quant(ref lPhr); } return(lPhr); }