Exemplo n.º 1
0
Expr* factor(const char* string, Expr* expr) {
    if(string[VAL_STRING] == '(') {
        expr->op = eat_char(string, '(');
        expr->data.expr[0] = parse(string);
        eat_char(string, ')');
    } else if(isdigit(string[VAL_STRING])) {
        expr->op = 'd';
        expr->data.terminal = eat_int(string);
    }
    return expr;
}
Exemplo n.º 2
0
int main(int argc, char ** argv){
  tokenizer_t t = mk_tokenizer(argv[1]);
  while(cur_tok(t).kind != tok_eof){
    if(cur_tok(t).kind == tok_nl){
      t->num = 0;
      next_tok(t);
    }
    else{
      int x = eat_int(t);
      while(cur_tok(t).kind != tok_nl){
        eat_plus(t);
        int y = eat_int(t);
        x = x + y;
      }
      t->num = 0;
      next_tok(t);
      printf("sum = %d\n", x);
    }
  }
  return 0;
}