1
$\begingroup$

We learn how to write compiler. I know that we can use grammar to construct a parser for compiler or otherwise use a syntax graph to represent grammar and generate code when move on it's node. our teacher use second approach. a simple graph for only expression (limited) is:
enter image description here

You can see that when we see a sub graph, we go inside that to complete it. in this example, "T", "E" and "F" are sub graphs. after getting to final node of sub graph, if there is no token that can be matched, we comeback to upper graph and move on that edge. if there is code generation on a graph, we generate it too like "genSum" and etc.
If you examine it, you will see that it works perfect. however I don't know how to implement "power" syntax with this syntax graph because of it's associativity. Is it impossible? out teacher doesn't answer that and ask us to think about it.
Thanks and sorry for bad English.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.