Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b33e7cac6d
Fetching contributors…

Cannot retrieve contributors at this time

file 34 lines (31 sloc) 0.7 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "lex.h"

int next(token *t, FILE *f) {
  char c, t_buf[255];
  int num_read, in_value;
  num_read = in_value = 0;

  while((c = fgetc(f)) != EOF) {
    if(isspace(c)) {
      if(num_read > 0) {
        t_buf[num_read] = '\0';
        t->type = (in_value ? T_VALUE : T_SYMBOL);
        if(t->type == T_VALUE) {
          t->value = atof(t_buf);
        } else {
          memset(t->symbol, '\0', 255);
          strncpy(t->symbol, t_buf, num_read);
        }
        return 1;
      } else {
        return 0;
      }
    } else {
      in_value = isdigit(c);
      t_buf[num_read++] = c;
    }
  }

  return 0;
}
Something went wrong with that request. Please try again.