Pragmatically is there any popular interpretive language that first generates the Syntax tree when parsing?

StackOverflow https://stackoverflow.com/questions/6805717

  •  25-10-2019
  •  | 
  •  

Question

It seems all scripting languages like PHP ,Perl doesn't build any syntax tree,but interpret it directly(no separate syntax parsing & code generation):

https://svn.php.net/repository/php/php-src/trunk/Zend/zend_language_parser.y

is there any popular interpretive language that first generates the Syntax tree when parsing at all?

Was it helpful?

Solution

The information you have regarding Perl is incorrect:

At compile time, the interpreter parses Perl code into a syntax tree. At run time, it executes the program by walking the tree.

(Source: perl wikipedia page.)

You'll find information about modules you can use to visualize that syntax tree in the Core modules documentation.

OTHER TIPS

Nearly all of them. Interpreting from a token stream is hard (and interpreting without even a tokenizer is even harder), as you'd need to do much of the parsing work anyway (only this time ad hoc, without the help of parser generators, mixing parser logic with interpreter logic). For starters, getting operator precedence right seem to require potentially infinite lookahead/backtracing if you try it without building intermediate data structures (AST).

One exception might be shell scripting languages due to their dead-simple syntax (mostly just invocations of external programs, variable assignments that operate on strings anyway, and simple loop structures), although I wouldn't bet on it. Edit: Nope, bash has a yacc grammar, and zsh seems to have a fully-blown parser as well.

Many of those languages don't stop at the AST either but go on to compile it to bytecode (even if they don't save it for later runs by default - e.g. PHP) and interpret that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top