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

Function expression

code_snippets/Chapter07/chapter.7.2.cpp:144–164  ·  view source on GitHub ↗

deal with + and -

Source from the content-addressed store, hash-verified

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

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