Generate an AST in C++

前端 未结 4 752
谎友^
谎友^ 2021-02-04 22:06

I\'m making an interpreter in C++, so far I\'ve got my lexer to generate tokens. The problem is I\'m not sure how to generate an \"walk\" a parse tree.

I was thinking of

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-04 22:54

    People build ASTs as heap-allocated trees. (Yes, you can do it an array but it just isn't as convenient). I suggest you READ the bison documentation; it will explain to you how to build trees and you can follow that style.

    Guessing at your experience level based on your question, if I were you I'd build a flex/bison based parser/AST builder at least once to get a good experience, before you came back to building everything yourself.

提交回复
热议问题