Are regular expressions used to build parsers?

后端 未结 8 1790
Happy的楠姐
Happy的楠姐 2020-12-16 15:58

This is just a question out of curiosity since I have been needing to get more and more into parsing and using regex lately.. it seems, for questions I come across in my sea

8条回答
  •  没有蜡笔的小新
    2020-12-16 16:39

    No, parsers are built from grammars.

    But most compilers (interpreters) will use a separate scanner (lexer) to recognize the input-tokens. A scanner can be specified with regular expressions, but afaik they are not built using the usual RegEx library classes.

    A separate scanner is a practical approach. It is possible to define full grammars all the way down to the character level, but that is impractical. Regular expressions handle the endpoint subset of the grammars easier.

    For reference, see Yacc and Lex. They both have modern successors.

提交回复
热议问题