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

Function expression

code_snippets/Chapter07/chapter.7.4.cpp:148–168  ·  view source on GitHub ↗

deal with + and -

Source from the content-addressed store, hash-verified

146
147// deal with + and -
148double expression()
149{
150 double left = term(); // read and evaluate a Term
151 Token t = ts.get(); // get the next token from token stream
152
153 while(true) {
154 switch(t.kind) {
155 case '+':
156 left += term(); // evaluate Term and add
157 t = ts.get();
158 break;
159 case '-':
160 left -= term(); // evaluate Term and subtract
161 t = ts.get();
162 break;
163 default:
164 ts.putback(t); // put t back into the token stream
165 return left; // finally: no more + or -: return the answer
166 }
167 }
168}
169
170//------------------------------------------------------------------------------
171

Callers 2

primaryFunction · 0.70
mainFunction · 0.70

Calls 3

termFunction · 0.70
getMethod · 0.45
putbackMethod · 0.45

Tested by

no test coverage detected