Parsing, where can I learn about it

前端 未结 12 668
鱼传尺愫
鱼传尺愫 2020-12-13 14:56

I\'ve been given a job of \'translating\' one language into another. The source is too flexible (complex) for a simple line by line approach with regex. Where can I go to le

相关标签:
12条回答
  • 2020-12-13 15:31

    Niklaus Wirth's book "Compiler Construction" (available as a free PDF) http://www.google.com/search?q=wirth+compiler+construction

    0 讨论(0)
  • 2020-12-13 15:33

    Try ANLTR:

    ANTLR, ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, interpreters, compilers, and translators from grammatical descriptions containing actions in a variety of target languages.

    There's a book for it also.

    alt text

    0 讨论(0)
  • 2020-12-13 15:34

    If you prefer Java based tools, the Java Compiler Compiler, JavaCC, is a nice parser/scanner. It's config file driven, and will generate java code that you can include in your program. I haven't used it a couple years though, so I'm not sure how the current version is. You can find out more here: https://javacc.dev.java.net/

    0 讨论(0)
  • 2020-12-13 15:36

    flex and bison are the new lex and yacc though. The syntax for BNF is often derided for being a bit obtuse. Some have moved to ANTLR and Ragel for this reason.

    If you're not doing much translation, you may one to pull a one-off using multiline regexes with Perl or Ruby. Writing a compatible BNF grammar for an existing language is not a task to be taken lightly.

    On the other hand, it is entirely possible to leverage any given language's .l and .y files if they are available as open source. Then, you could construct new code from an existing parse tree.

    0 讨论(0)
  • 2020-12-13 15:40

    Lexing/Parsing + typecheck + code generation is a great CS exercise I would recommend it to anyone wanting a solid basis, so I'm all for the Dragon Book

    0 讨论(0)
  • 2020-12-13 15:45

    I've recently been working with PLY which is an implementation of lex and yacc in Python. It's quite easy to get started with it and there are some simple examples in the documentation.

    Parsing can quickly become a very technical topic and you'll find that you probably won't need to know all the details of the parsing algorithm if you're using a parser builder like PLY.

    0 讨论(0)
提交回复
热议问题