I would like to know how is the best way to create the syntax tree.
-
When you googled "parsing" what did you find? Most interpreted language parses are open source. You can simply download them. What do you need to know? What languages are you talking about? – S.Lott Dec 17 '09 at 13:08
4 Answers
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.

- 181,842
- 47
- 306
- 310
The standard Stack Overflow resource for learning to write compilers and interpreters is Learning to write a compiler

- 1
- 1
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.

- 173,980
- 10
- 155
- 350
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.

- 1,264
- 1
- 11
- 15
-
1O'Reilly just released a book on flex and bison, the GNU equivalents for lex and yacc (ISBN 978-0596155971). Flex and bison are a lot easier to deal with than lex and yacc. – Mike D. Dec 17 '09 at 13:32