4 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?
by 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