An abstract syntax tree can help your code make sense of what a user provides.
Have you ever had somebody give you instructions that were all jumbled up and barely made any sense? Maybe they would forget things and go back to an earlier point to clarify. Or maybe they would give you instructions that were unnecessary.
A good way to make sure you understand is to try to make sense of what the other person is saying and then repeat the instructions. You can make things more organized and your friend will be amazed at how simple and straightforward the instructions have become.
In a way, what you’re doing is creating an abstract syntax tree. Usually we think of something abstract as being hard to visualize and understand. Something that has no form and is more of an idea than anything else.
Well, I’m not sure of the origin of the term abstract syntax tree, but the way I understand it is that you’re building a very specific tree that abstracts your code away from the confusing world of information provided. So instead of thinking of them as abstract, syntax trees, I think of them as abstract syntax, trees. Notice where I put the mental pause. To me, it’s the syntax that’s abstract and then the tree comes along and makes things better.
Listen to the full episode as I describe how to build an abstract syntax tree starting with a simple idea and then how that idea needs to change.