5 ms·
Regexps alone are a really poor fit for dealing with recursive structures, such as finding matching pairs of braces. You can use them for a lexing step, but you
by silentbicycle 18y ago
Regexps alone are a really poor fit for dealing with recursive structures, such as finding matching pairs of braces. You can use them for a lexing step, but you're probably better off using something like yacc or LPEG for the parsing.
Forth, Factor, and other stack-based languages also have this same property of "syntax agnostic representation". While on the surface they're kind of a backwards Lisp (due to postfix notation, with intermediate results pushed on a stack), both are dealing with nested lists of symbols, and very adept at dealing with things expressed the same way.
- deleted 18y ago[deleted]
- yters 18y agoThat's true about the nested structures. I was wondering if it is worthwhile to make lexing and parsing first class and changeable at runtime, and whether regexps would be a good way of doing this. The problem with relying on an external program is that making syntax conversion first class gets much more convoluted. But, it isn't clear to me whether it is a good idea to make everything about LOP first class. I do like that feature of Lisp though.
- mst 18y agoOr, possibly, perl6 rules. One of the things I keep meaning to have a go at is taking Larry's gimme5 stuff (a slow but working implementation of much of the rules system in perl5 he's using to bootstrap the grammar) and bolting it back into perl5 so we can experiment with it more easily.
- kragen 18y agoForth is not adept at dealing with nested lists of anything. It doesn't have linked lists, garbage collection, or traditionally even heap allocation. It does have recursion, but it doesn't traditionally have local variables, and mutual recursion (really handy when you're doing anything related to ASTs) requires using DEFER or something. Do you have a lot of experience writing Forth?
- silentbicycle 18y agoForth words are nested lists of other words (before compilation). It's not as good at dealing with nested data structures as Lisps, agreed, but the poster above is asking about syntax and DSLs.
- yters 18y agoAs you pointed out, though, programs tend to have nested structures.
- kragen 18y agoBefore compilation, Forth words don't exist. During compilation, they are flat lists of other words, not nested lists of other words. After compilation, they can be just about anything. Forth is great for embedded DSLs but it's not because of its great ability to deal with nested lists of words.