开发者

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

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开发者_StackOverflow中文版.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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜