public void PracticalExample_MathematicalFormula() { #region Composite var VALUE = new PrioritizedChoice( new CapturingGroup("VALUE", new OneOrMore(new CharacterClass { ClassExpression = "[0-9]" }) ) , new Sequence( new Literal { MatchText = "(" }, new RecursionCall("ParethesisFunction") ) .Sequence(new Literal { MatchText = ")" }) ); var PRODUCT = new Sequence( VALUE, new Sequence( new CapturingGroup("SYMBOL", new PrioritizedChoice( new Literal { MatchText = "*" }, new Literal { MatchText = "/" } ) ), VALUE ).Star() ); var SUM = new Sequence( PRODUCT, new Sequence( new CapturingGroup("SYMBOL", new PrioritizedChoice( new Literal { MatchText = "+" }, new Literal { MatchText = "-" } ) ), PRODUCT ).Star() ); AExpression EXPRESSION = new RecursionCreate("ParethesisFunction", new CapturingGroup("EXPRESSION", SUM)); #endregion var input = "((((12/3)+5-2*(81/9))+1))"; var bytes = Encoding.UTF8.GetBytes(input); var iterator = new ByteInputIterator(bytes); var visitor = new NpegParserVisitor(iterator); EXPRESSION.Accept(visitor); Assert.IsTrue(visitor.IsMatch); AstNode node = visitor.AST; Assert.IsTrue(node.Token.ValueAsString(iterator) == input); }