hoaproject / Compiler

The Hoa\Compiler library.
https://hoa-project.net/
453 stars 47 forks source link

Question: how to access/traverse nodes of grammar #92

Closed flip111 closed 5 years ago

flip111 commented 5 years ago

After the PP is read how can the grammar nodes be access / traversed programmatically? Before reading in any actual input for the parser.

guiled commented 5 years ago

Does that class help you ? https://github.com/guiled/Hoathis-Lua/blob/v2/src/Debugger.php

flip111 commented 5 years ago

Maybe. I'm not sure how it would help. Some methods return a string which can't be traversed obviously. Did you have something in mind on how i should use this class?

guiled commented 5 years ago

The only way it would help is that it can inspire you ;-) The point of this class is to print the pp grammar from the grammar tree.

Hywan commented 5 years ago

The only way is to use getRules (https://github.com/hoaproject/Compiler/blob/master/Llk/Parser.php#L764) to get all the rules, and then use a foreach loop, it's a linear structure.

flip111 commented 5 years ago

This answer is the right answer (closing ticket). We could put some code or documentation for this. What do you think?