4 ms·
Why is it so often stated, that Scheme doesn't need a parser? I mean the AST is simpler then in other languages, but at the end of the day, you have to parse SE
by protomikron 10y ago
Why is it so often stated, that Scheme doesn't need a parser? I mean the AST is simpler then in other languages, but at the end of the day, you have to parse SEXPs, don't you?
I mean let's say you evaluate
> (+ 2 3)
You have to parse the string "(+ 2 3)" and will then evaluate it to 5?
- DonaldFisk 10y agoThe read function the parser.
- richard_todd 10y ago... reading sexp's is technically parsing but it is so far removed from something like a C parser that it's really not the same animal. I mean, you can write a function to build a list from a sexp in a few minutes, while even a basic hand-written C parser will take days/weeks/months depending on your familiarity. So, that's a reason why it is said. (edit: also, if the course implements scheme IN scheme, then you don't need a parser because the host scheme can do it for you.)
- protomikron 10y ago> ... reading sexp's is technically parsing but it is so far removed from something like a C parser that it's really not the same animal. Yeah it is obviously a lot easier to parse than traditional, imperative languages like C. I just do not like the phrase, as it gives this "magic" vibe to Scheme. I mean its syntax is beautiful and simple, but there is definitely no magic there.
- nickpsecurity 10y agoMcCarthy's basic evaluator for LISP in a page or two in a high-level language (esp LISP). That's not magic but good design gets plenty close. ;)
- acchow 10y agowe mean it doesn't need a parser in the traditional sense of a LR or LL grammar (or more complicated) with generated table or even a hand-rolled parser with lookahead. Sure, it needs a "parser" in the sense of a FSA + a stack.
- mncharity 10y ago"It's easy to parse scheme" is one of those pretty stories that is often repeated but untrue. A similar one is "it's easy to implement scheme in scheme". It is true for toy compilers of language subsets, and those are often done. And few people ever explore real scheme compiler internals. The readers in real scheme compilers are generally a large pile of ugly code. A decade or so ago, I recall Bigloo's was the cleanest I'd found, with a regular expression based parser framework. I can't quickly find the files to link. But after wading through many other implementations, it was a breath of fresh air. But not simple, and not small. Here's a quick quote from a Chicken changelog: "2.7 Fix several bugs (expt, integer?, rational?, <=, >=, eqv?, -) found by importing the number tests from Gauche and writing an extensive test for number syntax edge cases. Complete rewrite of number parser (it should fully conform to the R7RS superset of R5RS number syntax now)."