mpc icon indicating copy to clipboard operation
mpc copied to clipboard

Mix parsers and AST

Open Eren121 opened this issue 2 years ago • 3 comments

I don't want to redefine a grammer for float, so how can I use mpc_float() and friends with mpca_lang and permit to reference it without defining it in the grammar ?

Eren121 avatar Jun 22 '22 16:06 Eren121

You can define it ahead of time with mpc_define , pass it in along with the other arguments to mpca_lang, and reference it using the name it was given by mpc_new.

orangeduck avatar Jun 22 '22 20:06 orangeduck

But it doesn't work with mpc_float because it returns a float*. Will it work only if the function returns a char*?

Eren121 avatar Jun 22 '22 21:06 Eren121

Ah yeah, that's true - I think you can use mpc_apply(mpcf_str_ast, mpc_real()) instead since parsers used in mpca_grammar need to return a mpc_ast_t*. You can also tag that ast node with mpca_tag.

orangeduck avatar Jun 22 '22 23:06 orangeduck