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

endless loop in mpc_parse #5

Closed
igalic opened this issue Apr 15, 2014 · 3 comments
Closed

endless loop in mpc_parse #5

igalic opened this issue Apr 15, 2014 · 3 comments

Comments

@igalic
Copy link

igalic commented Apr 15, 2014

In my attempt to extend Lispy for a double type, I created the following grammar (full source code):

        mpc_parser_t* Integer  = mpc_new("integer");
        mpc_parser_t* Double   = mpc_new("double");
        mpc_parser_t* Symbol   = mpc_new("symbol");
        mpc_parser_t* Sexpr    = mpc_new("sexpr");
        mpc_parser_t* Expr     = mpc_new("expr");
        mpc_parser_t* Lispy    = mpc_new("lispy");

  const char *grammar = 
    "                                                                                         \n\
      double   : /-?[0-9]+.[0-9]+/ | ;                                                        \n\
      integer  : /-?[0-9]+/ | ;                                                               \n\
      symbol   : '+' | '-' | '*' | '/' | '%' | '^' | \"min\" | \"max\" | \"inc\" | \"dec\" ;  \n\
      sexpr    : '(' <expr>* ')' ;                                                            \n\
      expr     : <double> | <integer> | <symbol> | <sexpr> ;                                  \n\
      lispy    : /^/ <expr>* /$/ ;                                                            \n\
    \n";

  printf("Grammar: %s\n", grammar);

  mpca_lang(MPC_LANG_DEFAULT, grammar,
      Double, Integer, Symbol, Sexpr, Expr, Lispy);

Unfortunately, this gets my program stuck in mpc_parse(); (despite running on Linux;).

@orangeduck
Copy link
Owner

Hey,

I'm not sure exactly what might be happening but I can see a few problems with your grammar.

The double and integer expressions end with a trailing or sign |. I should probably disallow this in the grammar syntax, so that is definitely a bug in mpc to allow it, but that might be breaking it.

In your double definition regex you need to escape the . symbol, which means "any character" by itself. Again this might be causing issues but I'm not sure.

Hope that fixes it. I'll look into that issue with the grammar syntax.

Thanks,

Dan

@igalic
Copy link
Author

igalic commented Apr 15, 2014

ACK, Thank you very much!

@orangeduck
Copy link
Owner

This should be fixed in the newest version of mpc, but ultimately I think its due to a badly formed grammar so I'm going to close this issue. I hope that is okay 👍

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