English 中文(简体)
What is the processes to parse an interpreted programming language?
原标题:

I would like to know how is the best way to create the syntax tree.

最佳回答

The standard Stack Overflow resource for learning to write compilers and interpreters is Learning to write a compiler

问题回答

Here is some explanation about abstract syntax trees (AST) from the LLVM project.

Teaser:

The AST for a program captures its behavior in such a way that it is easy for later stages of the compiler (e.g. code generation) to interpret. We basically want one object for each construct in the language, and the AST should closely model the language.

No different from any other language, really. The difference between interpreted and compiled languages is primarily in the backend, not the frontend. Specific languages may have specific parsing requirements, but you can t make a meaningful comparison in parsing technologies between the two classes of languages.

You don t list a language requirement for your parser, so if C or C++ is a possibility, you should start by looking at yacc: http://en.wikipedia.org/wiki/Yacc

Yacc generates a C parser for your specific syntax. Getting started with that might be a little extra work, but once you get the thing up and rolling, it should be easier to maintain.

Disclaimer: I have only used yacc in one project and it was 10+ years ago, so your milage may vary.





相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

How to get instance from string in C#?

Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

Locating specific string and capturing data following it

I built a site a long time ago and now I want to place the data into a database without copying and pasting the 400+ pages that it has grown to so that I can make the site database driven. My site ...

热门标签