Most effective way to parse C-like definition strings?

前端 未结 5 1188
滥情空心
滥情空心 2021-01-13 08:24

I\'ve got a set of function definitions written in a C-like language with some additional keywords that can be put before some arguments(the same way as \"unsigned\" or \"re

5条回答
  •  孤城傲影
    2021-01-13 08:54

    That entirely depends on your definition of "effective". If you have all the time of the world, the fastest parser would be a hand-written pull parser. They take a long time to debug and develop but today, no parser generator beats hand-written code in terms of runtime performance.

    If you want something that can parse valid C within a week or so, use a parser generator. The code will be fast enough and most parser generators come with a grammar for C already which you can use as a starting point (avoiding 90% of the common mistakes).

    Note that regexps are not suitable for parsing recursive structures. This approach would both be slower than using a generator and more error prone than a hand-written pull parser.

提交回复
热议问题