开发者

Using adaptive grammars [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 3 years ago.

Improve this question

I'm tryin开发者_StackOverflowg to implement a language (or family of languages) whose grammar can be changed dynamically. I have found no examples that serve as study cases.

Can you give me some reference to any that are actually used in the real world (even from the academic world)?

Does it make sense to implement a Domain-Specific Languages with a dynamic grammar?


The most famous current language that has a dynamic syntax is Perl6. The most famous example in general is probably Smalltalk-72.

You might also want to look into OMeta and the rest of the STEPS project from Alan Kay's Viewpoints Research Institute, as well as Val Schorre's original META II.

Also interesting: the π programming language.

XL (Extensible Language) also allows for powerful manipulation of the syntax itself.


The Katahdin programming language offers syntax and semantic changes at runtime. It's an unsupported thesis language so don't expect to use it in production. Still, Chris Seaton's thesis may be a good resource for implementing similar ideas in your own language.

Seaton is cited in this paper describing a macro system for the Fortress programming language. The authors' goal is to make syntactic extension indistinguishable from core syntax.


I really like the syntax of Agda, which is extremely flexible. It allows for arbitrary distfix operators which essentially allows for, what looks like new language features.

Although I haven't looked closely into her work I know Annika Aasa has done some work on letting programmers specify new syntax. You'll find her work on Google Scholar.

Fwiw, I think developing domain-specific languages as a library in a language with a very flexible syntax makes a lot of sense. It's sometimes referred to as an embedded domain-specific language, in case you didn't know.


I'm working on the same thing.

I should have a couple extendable parser libraries that people can use soon. I've got the lexer done and I'm busy throwing together the parser.

The first library is being written in Ruby and I intend to translate it to Java when it's done. I tried a Java version first, but I got bogged down in stupid details so I switched to Ruby so the language won't get in my way while I'm still thinking.

I'm happy with my approach which allows switching between multiple lexers and multiple expression types with distfix operators. The lexers are just ordered series of regex expressions.

The parsing is simple operator precedence outside of the distfix parts of the productions and LL(1) inside. We'll see if I find I want anything stronger.


Katahdin is an obvious choice. There is also PFront, and good old parsing macros in Common Lisp as well.


I have found relatively few implementations of adaptive grammars, though there is an adaptive parser generator called Dypgen. I also wrote an adaptive parser in Prolog that can "learn" new grammars from its input.

There is also a "self-modifying grammar interpreter" called OpenZZ, though it hasn't been updated in a few years.

It's also possible to write "self-modifying" parsers using Nearley, though this feature isn't documented yet.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜