9

I have an infix expression that I have tokenised and would like to proceed to create an abstract syntax tree. I understand the shunting-yard algorithm used in these cases. I have only found ways to convert the infix expression to RPN format, not into an AST. I could create the RPN version first and then AST from it, but it seems unnecessary.

My language of choice is JavaScript, though I only need to see an example in any language and/or a description of the algorithm. I have skimmed through the Dragon Book and Terence Parr's book, but neither gave the answer I was looking for.

user27114
  • 99
  • 1
  • 2
  • 3
    [This blog article](http://www.klittlepage.com/2013/12/22/twelve-days-2013-shunting-yard-algorithm/) shows this in Java, and might be useful. – Don Roby Jan 25 '14 at 22:07
  • 2
    I just happened to post a gist https://gist.github.com/gene-ressler/8278298 that makes a DAG rather than an AST. But if you remove the `dict.lookup` calls, it makes an AST. This does not use the shunting yard algorithm, but a recursive descent parser. – Gene Jan 26 '14 at 01:30
  • Possible duplicate of [How to construct an abstract syntax tree](https://stackoverflow.com/questions/1721553/how-to-construct-an-abstract-syntax-tree) – trincot Nov 10 '18 at 14:32

0 Answers0