开发者

Parsing techniques for runtime language alteration

Looking at Rakudo Perl6 I wonder if there are techniques for 开发者_C百科parsing and lexical analyses that allow to alter/extend the syntax of the language and that are efficient and not to hard to implement.


Take a look at PEGs. There are languages that are based on PEGs ( http://en.wikipedia.org/wiki/Parsing_expression_grammar ), which are extendable, for example:

http://www.chrisseaton.com/katahdin/

http://www.meta-alternative.net/mbase.html

Perl5 and Perl6 grammars could be easily defined in PEG form (and I might be wrong, but the current Perl6 is most likely implemented this way).


"No". [edit: as of the time of the question] If the question is about lexing/parsing Perl, its pretty hard. We (see my bio for "we") have a Perl5 lexer. We have really good lexer-generator tools (Unicode, multi-state, regexps complete with "not regexp" built-in). The Perl lexer was a royal headache to build; we ended up with something like 50 lexical modes (each with its own set of token definitions) to handle the lexing part.

We're staring at the parsing part and today we are lucky and don't have a direct need to do it, so we've avoided this so far. Apparantly the language is ambiguous depending on the dynamic definitions of various identifiers, so how you interpret (parse) a phrase at one moment isn't statically decidable. We think we can do it using a GLR parser that handles ambiguities and just simply hold on to the ambiguities as possible runtime alternatives. I'll let you know in several months.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜