// // Term ::= Factor { ("*" |"/") Factor }. private TERM parseTerm() { TERM term = new TERM(); term.factor = parseFactor(); while ( true ) { Token token = lexer.get(); switch ( token.code ) { case TokenCode.STAR : case TokenCode.SLASH: lexer.forget(); term.ops.Add(token.code); term.factors.Add(parseFactor()); break; default: // Don't forget() return term; } } }
/// <summary> /// Term ::= Factor { ("*" |"/") Factor }. /// </summary> private void generateTerm( ILGenerator il, TERM term ) { generateFactor(il,term.factor); for ( int i=0; i<term.factors.Count; i++ ) { generateFactor(il,term.factors[i]); switch ( term.ops[i] ) { case TokenCode.STAR : il.Emit(OpCodes.Mul); break; case TokenCode.SLASH : il.Emit(OpCodes.Div_Un); break; } } }