tj / luna

luna programming language - a small, elegant VM implemented in C
2.45k stars 147 forks source link

Application crash when debug parser #97

Open ntwo1980 opened 7 years ago

ntwo1980 commented 7 years ago

The debug macro in parse.c is:

#ifdef EBUG_PARSER
#define debug(name) \
  fprintf(stderr, "\n\e[90m%s\e[0m\n", name); \
  luna_token_inspect(&self->lex->tok);
#else
#define debug(name)
#endif

But following debug statement will crash because the self->lex->tok hasn't been assigned a valid token.

static luna_block_node_t *
program(luna_parser_t *self) {
  debug("program");
  ...
}

Can the debug macro be changed to:

#ifdef EBUG_PARSER
#define debug(name) \
  fprintf(stderr, "\n\e[90m%s\e[0m\n", name); \
  if(self->lex->offset) \
    luna_token_inspect(&self->lex->tok);
#else
#define debug(name)
#endif