5 ms·
Pretty easy in raku, too[1]. Comes in at 29 lines—a hair under racket :) (Though, granted, the latter does need to separate lexer and parser.) 1. http://ix.i
by moonchild 6y ago
Pretty easy in raku, too[1]. Comes in at 29 lines—a hair under racket :)
(Though, granted, the latter does need to separate lexer and parser.)
1. http://ix.io/2ASA http://ix.io/2ASA
- AQXt 6y agoThis is quite impressive! I don't know any other programming language that implement grammars in such a clean way.
- moonchild 6y agoIt was a logical extension of regexes, which were a very important part of perl (raku was originally perl 6). It also integrates very well with the rest of the language—even more so than does regex with perl. However, though I think raku's reimagination of regexes is probably the best one—and the one that feels the least bound to legacy—there are other developments in that area. For instance, oil's egg expressions - http://www.oilshell.org/preview/doc/eggex.html http://www.oilshell.org/preview/doc/eggex.html
- 9214 6y agoThere's Red with its Parse meta-DSL. https://www.red-lang.org/2013/11/041-introducing-parse.html https://www.red-lang.org/2013/11/041-introducing-parse.html
- ceceron 6y agoProlog implements Definite Clause Grammars[0] which can express context-sensitive grammars. In Prolog there is a simple DSL to express DCGs, but in fact DCG just uses Prolog runtime features. I don't believe there is aanother general purpose language with such complex parsing just built-in the runtime. Here you can see my version of the raku parser, it's arguably shorter (I'm not a Prolog expert): https://swish.swi-prolog.org/p/basic_logic_parser.pl https://swish.swi-prolog.org/p/basic_logic_parser.pl [0] https://en.wikipedia.org/wiki/Definite_clause_grammar https://en.wikipedia.org/wiki/Definite_clause_grammar
- moonchild 6y ago(On the other hand, the raku version also implements operator precedence properly, with infix operators having lower precedence than logical negation.)
- hydroxideOH- 6y agoHi, author here. I'm new to Racket and obviously no expert. I realized this problem, but I wasn't sure about the best way to go about fixing it, do you have any suggestions?
- moonchild 6y agoI would do something similar to the raku version and have an extra bit in the grammar. Don't know racket or brag, but maybe something like http://ix.io/2AXE http://ix.io/2AXE
- moron4hire 6y agoTechnically, the Racket version is using a separate lexer and parser library, it's just that Racket erases the line between what is a library and what is a language when it comes to lexers and parsers. One could either say this is a Racket program that uses the Brag library, or a Brag program (though the latter is preferred in the Racket ecosystem).