MCPcopy Create free account
hub / github.com/bewuethr/stroustrup-ppp / expression

Function expression

code_snippets/Chapter07/chapter.7.7-problematic.cpp:218–238  ·  view source on GitHub ↗

deal with + and -

Source from the content-addressed store, hash-verified

216
217// deal with + and -
218double expression()
219{
220 double left = term(); // read and evaluate a Term
221 Token t = ts.get(); // get the next token from token stream
222
223 while(true) {
224 switch(t.kind) {
225 case '+':
226 left += term(); // evaluate Term and add
227 t = ts.get();
228 break;
229 case '-':
230 left -= term(); // evaluate Term and subtract
231 t = ts.get();
232 break;
233 default:
234 ts.putback(t); // put t back into the token stream
235 return left; // finally: no more + or -: return the answer
236 }
237 }
238}
239
240//------------------------------------------------------------------------------
241

Callers 2

primaryFunction · 0.70
calculateFunction · 0.70

Calls 3

termFunction · 0.70
getMethod · 0.45
putbackMethod · 0.45

Tested by

no test coverage detected