//Pipe/Alternative internal static BnfExpression Op_Pipe(BnfTerm term1, BnfTerm term2) { //Check term1 and see if we can use it as result, simply adding term2 as operand BnfExpression expr1 = term1 as BnfExpression; if (expr1 == null) //either not expression at all, or Pipe-type expression (count > 1) { expr1 = new BnfExpression(term1); } //Check term2; if it is an expression and is simple sequence (Data.Count == 1) then add this sequence directly to expr1 BnfExpression expr2 = term2 as BnfExpression; //1. term2 is a simple expression if (expr2 != null && expr2.Data.Count == 1) // if it is simple sequence (plus operation), add it directly { expr1.Data.Add(expr2.Data[0]); return(expr1); } //2. term2 is not a simple expression expr1.Data.Add(new BnfTermList()); //add a list for a new OR element (new "plus" sequence) expr1.Data[expr1.Data.Count - 1].Add(term2); // and put term2 there if it is not Empty pseudo-element return(expr1); }
public NonTerminal(string name, BnfExpression expression) : this(name) { Rule = expression; }