4 ms·
I'm not an expert, but as far as I know, the first step is always to get an abstract syntax tree, which is needed to check for syntax errors and have the progra
by Sebb767 6y ago
I'm not an expert, but as far as I know, the first step is always to get an abstract syntax tree, which is needed to check for syntax errors and have the program in an usable representation. This means that your first pass always reads all the code and allows handling this case, possibly without getting into the hard work of optimizing, creating the variables etc.
That, or the early JS interpreters simply couldn't handle that case - I've never heard of this, though.
- cardiffspaceman 6y agoI don't think creation of a syntax tree is always explicit; I have read C compiler source codes that use one pass with back-patching and the usable representation is bytecode or machine code. One could reckon that the AST is implicit during code generation as functions call each other to generate the code. A valid JS interpreter could just do what the statements say using dictionaries for each scope, linked together to allow levels of scope with the right semantics.
- jcranmer 6y agoIt's worth noting that the scoping of names in C language is designed to be solvable in one pass: you can't use a function before it's declared. Most newer languages instead require a full pass to discover all the available names, to allow functions to not require a separate declaration before all uses.
- deleted 6y ago[deleted]
- chrisseaton 6y ago> I'm not an expert, but as far as I know, the first step is always to get an abstract syntax tree But you don't need to reify it.