Esempio n. 1
0
int main(int argc, char ** argv){
  FILE * fp = stdout;
  if (argc < 2 || argc > 3){
    printf("Usage: %s input_file [output_file]\n", argv[0]);
    exit(1);
  }
  tokenizer_t t = mk_tokenizer(argv[1]);
  program_t p = parse_program(t);
  if (argc == 3) fp = safe_fopen(argv[2], "w");
  cogen_program(fp, p);
  return 0;
}
Esempio 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;
}