String recognition problem
Closed this issue · 2 comments
peacefulpixel commented
So, my program looks like:
#include "../mpc.h"
int main(int argc, char **argv) {
mpc_parser_t *Expr = mpc_new("expr");
mpca_lang(MPCA_LANG_PREDICTIVE,
" expr : /^/ \"i1\" | \"i2\" /$/ ; ",
Expr, NULL);
mpc_result_t r;
if (mpc_parse_contents(argv[1], Expr, &r)) {
mpc_ast_print(r.output);
mpc_ast_delete(r.output);
} else {
mpc_err_print(r.error);
mpc_err_delete(r.error);
}
mpc_cleanup(1, Expr);
return 0;
}
Then if i try to parse input like this:
i1
I got output:
>
regex
string:1:1 'i1'
But if i try to parse
i2
I got an error message:
test11:1:2: error: expected "i1" or "i2" at '2'
So i can't catch what's wrong with my program
orangeduck commented
Your grammar isn't predictive so if you remove the MPCA_LANG_PREDICTIVE
flag it should work.
peacefulpixel commented
I set flag MPCA_LANG_DEFAULT
and now it's work. Thanks!