Parser and abstract syntax tree

Recently I've decided to try to implement a very tiny language just to see what I can do. Over the past few hours I managed to write a lexical analyzer for my language that works quite nicely. So after reading theory and stuff I understand the next step is to write a parser. The job of the parser is still a little bit unclear to me, (I'm writing a tiny interpreted language for a start so things will be done directly in code) does it go through tokens, understand meaning, then do what the code says/generate code (for compiler)? OR I've read about abstract syntax tree's, is this something I'm supposed to construct with the parser? I'm not quite sure what an AST is even for really... So I suppose my question is, what's my next step after a lexer? What's the job of the parser? And last but not least what's the job of an abstract syntax tree?

Thanks for any help!


I'm not sure how you wrote you lexer, but a standard way to approach this is by writing the lexer with flex (previously lex ) and to write the parser with yacc . The combination of the two makes it very easy to implement a wide variety of languages.

链接地址: http://www.djcxy.com/p/68206.html

上一篇: 试图理解词法分析器,解析树和语法树

下一篇: 解析器和抽象语法树