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

Simple expression example and AST #73

Closed
iglesias opened this issue Oct 27, 2023 · 3 comments
Closed

Simple expression example and AST #73

iglesias opened this issue Oct 27, 2023 · 3 comments

Comments

@iglesias
Copy link

Hi, I started with the examples/simple-expr-parser.cpp and I am wondering if it would be possible to retrieve from the parser p a type, or some other data, to inspect (or derive from it, if needed) the AST associated to an expression.

For example, when either running the program ./simple-expr-parser '3*(1-5)' or writing code p.parse(cstring_buffer("3*(1-5)") is there somewhere, even if internal, something like o_mul<<number<3>, o_minus<number<1>, number<5>>>?

Thank you very much in advance for any help!

@peter-winter
Copy link
Owner

Sure. Take a look at a json parser example. I creates standard containers (like std::map, std::vector, std::string), however I'm sure you can create whatever else you like.
If you want AST to be constexpr, it is a bit more difficult, I do this in ctjs example (creates constexpr json representation)

@iglesias
Copy link
Author

Thanks for the pointers, I will check them.

@iglesias
Copy link
Author

I understood it for the json parser example with the standard containers and started taking a look at the ctjs example. Thanks again.

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