Arithmetic evaluation/C: Difference between revisions

m
Added some comments in
(Copy from main task page)
 
m (Added some comments in)
Line 40:
}
 
/* Will consume a character from the input,
* (such as +, -, *, etc.) and return it.
*/
char consume_char(const char* string, char c) {
if(string[G_STRING_ITERATOR] != c) {
Line 48 ⟶ 51:
}
 
/* Same as consume_char, except for integers.
*/
int consume_int(const char* string) {
int i;
Line 55 ⟶ 60:
}
 
/* I don't have to pass in the start of the string
* into atoi, but only where I want it to start
* scanning for an integer.
*/
i = atoi(string + G_STRING_ITERATOR);
while(isdigit(string[G_STRING_ITERATOR])) {
Line 156 ⟶ 165:
}
 
/* Runs through the AST, evaluating and freeing
* the tree as it goes.
*/
int evaluate(Expr* expr) {
int ret;