3 ms·
The serious question I would have about non-s-expressions language is - while they might be homoiconic by whatever definition, what makes them easy to parse? T
by joe_the_user 13y ago
The serious question I would have about non-s-expressions language is - while they might be homoiconic by whatever definition, what makes them easy to parse?
The thing that's appealing about s-expression languages is that code-as-data is easy to do because parse, creating and modifying code is dead-easy. Is there some still-very-easy algorithm for parsing things like infix operators or does code-as-data depend on using the facilities of the language.
Edit: I can see Julia does this by reflection and macros. But I'm still curious about the general issues and algorithms involved here.
- krichman 13y ago> still-very-easy algorithm for parsing things like infix operators You would be interested in the shunting-yard algorithm[1], to start with. [1] https://en.wikipedia.org/wiki/Shunting_yard_algorithm https://en.wikipedia.org/wiki/Shunting_yard_algorithm
- draegtun 13y ago>The serious question I would have about non-s-expressions language is - while they might be homoiconic by whatever definition, what makes them easy to parse? Rebol is very easy to parse. Here is a Rebol parser in 10 lines of Rebol: parse text blk-rule: [ some [ str: newline | #";" [thru newline | to end] new: (probe copy/part str new) | [#"[" | #"("] blk-rule | [#"]" | #")"] break | skip (set [value new] load/next str probe :value) :new ] ] ref: http://www.rebol.net/cookbook/recipes/0042.html http://www.rebol.net/cookbook/recipes/0042.html
- joe_the_user 13y agoThat is interesting and I'm getting back late on this. But after mentally parsing that, it seems all this is doing separating blocks. What one would want to also do is to also scan operators, if one was evaluating code or transforming it into an abstract syntax tree.
- draegtun 13y agoI've been on holiday since I left my last reply so also getting back late on this :) Everything in Rebol is just blocks of words, where (in general) expressions are evaluated from left to right; however, within each expression evaluation occurs from right to left [1]. So (infix) operators are also just words and have no precedence order so they just evaluate left to right (like Smalltalk) when parsed [2]... >> 1 + 2 * 3 == 9 To enforce any precedence you use paren! blocks [3], which are blocks that get evaluated immediately. >> 1 + (2 * 3) == 7 refs: [1] http://www.rebol.com/r3/docs/guide/code-eval.html http://www.rebol.com/r3/docs/guide/code-eval.html [2] http://www.rebol.com/r3/docs/concepts/math-precedence.html http://www.rebol.com/r3/docs/concepts/math-precedence.html [3] http://www.rebol.com/r3/docs/datatypes/paren.html http://www.rebol.com/r3/docs/datatypes/paren.html