Using adaptive grammars [closed]

荒凉一梦 提交于 2019-12-18 12:30:17

问题


I'm trying 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?


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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.




回答5:


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




回答6:


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.



来源:https://stackoverflow.com/questions/3782362/using-adaptive-grammars

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!