theorycontext-free-grammarprefix-operator

CFG for reverse polish notation


I need to create a CFG for reverse polish notation with operators +-*/ and then write out the right derivation and create an abstract syntax tree.

I understand how to create the derivation and the syntax tree but I don't really understand how to create a CFG given a set of rules. I've done a lot of research online and I am only able to find out how to use a CFG but not how to create one with a given set of rules.

If someone could point me in the right direction or explain a different example of this that would be awesome. Thanks!


Solution

  • Not sure what you are referring to with a given set of rules...? Isn't the grammar just

    X -> X X o
    X -> n
    

    Where o is an operator and n a number?