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

Mix parsers and AST #145

Open
Eren121 opened this issue Jun 22, 2022 · 3 comments
Open

Mix parsers and AST #145

Eren121 opened this issue Jun 22, 2022 · 3 comments

Comments

@Eren121
Copy link

Eren121 commented Jun 22, 2022

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 ?

@orangeduck
Copy link
Owner

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.

@Eren121
Copy link
Author

Eren121 commented Jun 22, 2022

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

@orangeduck
Copy link
Owner

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.

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