Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIGSEGV when creating grammar. #58

Closed
JeromSar opened this issue Aug 3, 2016 · 3 comments
Closed

SIGSEGV when creating grammar. #58

JeromSar opened this issue Aug 3, 2016 · 3 comments

Comments

@JeromSar
Copy link

JeromSar commented Aug 3, 2016

Hi,

I've been expanding lispy (from your book, which is awesome, btw), to include support for doubles. However, when I finished my implementation, I suddenly get SIGSEGV errors when creating the grammar. Is there something I'm doing wrong?

I'm using the latest (master) version on the repo.

Grammar:

#define GRAMMAR "                                          \
                                                           \
      long     : /-?[0-9]+/ ;                              \
      double   : /-?[0-9]+\\.?[0-9]+/;                     \
      symbol   : /[a-zA-Z0-9_+\\-*\\/\\\\=<>!&\\|\\:]+/ ;  \
      string   : /\"(\\\\.|[^\"])*\"/ ;                    \
      comment  : /;[^\\r\\n]*/ ;                           \
      sexpr    : '(' <expr>* ')' ;                         \
      qexpr    : '{' <expr>* '}' ;                         \
      expr     : <number>  | <symbol> | <string>           \
               | <comment> | <sexpr>  | <qexpr> ;          \
      lispy    : /^/ <expr>* /$/ ;                         \
                                                           \
   "

static mpc_parser_t* number_l;
static mpc_parser_t* number_d;
static mpc_parser_t* symbol;
static mpc_parser_t* string;
static mpc_parser_t* comment;
static mpc_parser_t* sexpr;
static mpc_parser_t* qexpr;
static mpc_parser_t* expr;
static mpc_parser_t* lispy;

mpc_parser_t* grammar_create() {
  number_l = mpc_new("long");
  number_d = mpc_new("double");
  symbol = mpc_new("symbol");
  string = mpc_new("string");
  comment = mpc_new("comment");
  sexpr = mpc_new("sexpr");
  qexpr = mpc_new("qexpr");
  expr = mpc_new("expr");
  lispy = mpc_new("lispy");

  mpca_lang(MPCA_LANG_DEFAULT, GRAMMAR,  
    number_l, number_d, symbol, string, comment,
    sexpr, qexpr, expr, lispy);

  return lispy;
}

GDB backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x74538eb4 in strcmp () from C:\WINDOWS\SysWOW64\msvcrt.dll
(gdb) backtrace
#0  0x74538eb4 in strcmp () from C:\WINDOWS\SysWOW64\msvcrt.dll
#1  0x0040de42 in mpca_grammar_find_parser ()
#2  0x0040de74 in mpcaf_grammar_id ()
#3  0x004081f5 in mpc_parse_apply_to ()
#4  0x00408607 in mpc_parse_run ()
#5  0x00408d22 in mpc_parse_run ()
#6  0x00408e6d in mpc_parse_run ()
#7  0x00408a66 in mpc_parse_run ()
#8  0x00408e6d in mpc_parse_run ()
#9  0x00408e6d in mpc_parse_run ()
#10 0x0040891a in mpc_parse_run ()
#11 0x004086d8 in mpc_parse_run ()
#12 0x00408e6d in mpc_parse_run ()
#13 0x00408e6d in mpc_parse_run ()
#14 0x004085db in mpc_parse_run ()
#15 0x00408feb in mpc_parse_input ()
#16 0x0040e8df in mpca_lang_st ()
#17 0x0040ea59 in mpca_lang ()
#18 0x00403e5c in grammar_create ()
#19 0x00401451 in main ()
(gdb)
@JeromSar
Copy link
Author

JeromSar commented Aug 3, 2016

Nevermind, I got it working. Thanks anyway :)

@JeromSar JeromSar closed this as completed Aug 3, 2016
@yrizk
Copy link

yrizk commented Sep 15, 2018

mind telling us what the issue was? I'm running to the same error on linux.

@yrizk
Copy link

yrizk commented Sep 15, 2018

actually, i figured out my issue. it was that the grammar and the variables were not the same. see issue#8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants