3 ms·
> I used an S-expression syntax, instead of designing my own syntax and writing a parser for it. > This meant I was able to experiment with the semantics and v
by matheusmoreira 3y ago
> I used an S-expression syntax, instead of designing my own syntax and writing a parser for it.
> This meant I was able to experiment with the semantics and virtual machine of the language, instead of worrying over what keyword to use for function definitions.
Yeah. I see a lot of people asking why people are so fascinated by lisp and why there are so many lisps out there. I think this is a huge reason. It certainly was for me.
I just wanted to get some ideas working as soon as possible. Lisp is the easiest language to parse that I've ever seen, managed to write a parser by hand. And yet it's a fully featured programming language. It just gives you huge power for very low effort. It took a single bit to add metaprogramming to my lisp:
if (function.flags.evaluate_arguments) {
arguments = evaluate_all(interpreter, environment, arguments);
}
I see it as a little frontend for my data structures. I get to work on them endlessly and everything I do improves something.
- kaba0 3y agoI found that a naive frontend for a language is not that big of a deal with something like ANTLR. The benefit is that you have a formal grammar syntax description, and you can iterate on that endlessly without too many code changes down the line.
- ReleaseCandidat 3y agoIt isn't with a handwritten lexer/parser either, the real work starts after the parsing is complete. Of course, there are two possibilities: often changing them can either result in a cleaner, more readable result or a _real_ mess ;) But you have to rewrite it by hand anyways if you want to get better (or usable) error messages and incremental parsing for a LSP.
- danybittel 3y agoI see lisp as sort of "no syntax". It's basically the AST. Which is a good thing, you can concentrate on the compiler and add syntax later. If you are working on a compiler for a non lisp PL, it makes sense to log the AST after parsing, as a lisp, as a readable AST.
- lolinder 3y ago> Lisp is the easiest language to parse that I've ever seen, managed to write a parser by hand. I've written a dozen or so parsers for different languages by hand: the parser is easy regardless of the syntax you choose. The complicated bit is always compilation/interpretation. The biggest value I see to using S-expressions isn't the time saved in writing a parser, it's reducing the amount of bikeshedding you'll be tempted to do fiddling with syntax.
- matheusmoreira 3y agoAren't languages like C notoriously difficult to parse? I've read that they're actually context sensitive. IIRC much of Go's syntax was designed to avoid parsing complexity.
- shaftoe444 3y agoSee the clockwise/spiral rule!
- jstimpfle 3y agoType syntax started pretty easy to parse, basically just parse a C expression. It became more complex and inconsistent later (when for example types for function parameters were added), but IIRC the clockwise/spiral rule is nothing like the idea behind the syntax. I think it is too complicated / not getting the gist of it.
- kazinator 3y agoI suspect that the interpretation of C cannot be specified in a brief page of C code. For one thing, the language doesn't supply the data structures for representing any aspec of itself; the code will have to invent those: declarations, definitions, statements, types. Then handle a ton of cases. It will not be obvious that what the C code is doing is C interpretation, because all those data structures don't resemble the C syntax. The Lisp meta-circular interpreter side-steps that; the issue is settled elsewhere. It exists against a backdrop where the easy correspondence between the printed syntax and the data structure being handled by the interpreter is taken for granted. The C would need the same kind of backdrop; and that would be a lot of documentation.