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

Function term

code_snippets/Chapter07/chapter.7.2.cpp:115–139  ·  view source on GitHub ↗

deal with *, /, and %

Source from the content-addressed store, hash-verified

113
114// deal with *, /, and %
115double term()
116{
117 double left = primary();
118 Token t = ts.get(); // get the next token from token stream
119
120 while(true) {
121 switch (t.kind) {
122 case '*':
123 left *= primary();
124 t = ts.get();
125 break;
126 case '/':
127 {
128 double d = primary();
129 if (d == 0) error("divide by zero");
130 left /= d;
131 t = ts.get();
132 break;
133 }
134 default:
135 ts.putback(t); // put t back into the token stream
136 return left;
137 }
138 }
139}
140
141//------------------------------------------------------------------------------
142

Callers 1

expressionFunction · 0.70

Calls 4

primaryFunction · 0.70
errorFunction · 0.70
getMethod · 0.45
putbackMethod · 0.45

Tested by

no test coverage detected