DEV Community

Discussion on: Abstract Syntax Trees: They're Actually Used Everywhere -- But What Are They?

Collapse
 
edgarbonet profile image
Edgar Bonet

If there is a syntax error (missing brace, or bracket...) wouldn't you be unable to build the AST in the first place?

Collapse
 
aruna profile image
aruna-x • Edited

Hi Edgar, I was curious about that too when I first started playing with esprima. Wonderfully, esprima (which comes pre-baked with the rules of writing code we expect - it's fun to crawl through the esprima code and see how they've done this) throws helpful errors indicating the line and column numbers of syntactic issues. As long as you catch and handle them well (for example, by indicating the issue to the user so they can fix it, as with VS Code), you should be good :)

Collapse
 
edgarbonet profile image
Edgar Bonet

Oh, I see. So it's the process of attempting to build the AST that uncovers syntax errors. It's not the AST itself, which cannot be built if there is such an error. Makes sense.

Thread Thread
 
aruna profile image
aruna-x

Ah, I see what you meant to say! It seems I played fast and loose with my phrasing in this post. Thanks for highlighting this! I’ll edit the post so it’s more accurate :)