开发者

What use is an incremental SLR parser generator?

开发者 https://www.devze.com 2023-01-24 13:11 出处:网络
I once implemented an SLR parser generator that generates incremental parsers.The parser can parse a piece of text from beginning to end, but when you delete or insert text it does the minimal amount

I once implemented an SLR parser generator that generates incremental parsers. The parser can parse a piece of text from beginning to end, but when you delete or insert text it does the minimal amount of work and minimal amount of changes in the token stream and syntax tree, instead of just reparsing everything from the beginning. The problem is I havn't been able to find any use of this? The parser does slightly more work than a normal parser. Is there any use of such a thing? PS. If you want to know how, google 'basics of compiler design diku', it's a free book, then all I had to do was to modify the algorithm a little bit so开发者_高级运维 it stores the state of the parser everywhere, which is the extra work I mentioned above.


The obvious answer is support for a structured editor, in which what the editor holds is the AST rather then the text. This allows the editor to suggest how to continue editing when only a partial input is provided (e.g., after "while" keyword, the editor knows that "(" is necessary and can suggest it; it can put in a full "if" statement after just the keyword is provided, it can complain that entered syntax is wrong as you type, etc.)

There have been lots of such editors built, most of them not successful; people seem to love/hate editors that do this.

THe most advanced current project I know that does this is the Harmonia project at Berkeley. They use the big-brother version of your incremental parser: an incremental GLR parser.

0

精彩评论

暂无评论...
验证码 换一张
取 消