5 ms·
Judging from the article, if you parsed "if 3", you'd get back out (prefix if 3) instead of an error, since `if` is just a regular prefix operator. So, pr
by justinpombrio 12y ago
Judging from the article, if you parsed "if 3", you'd get back out
(prefix if 3)
instead of an error, since `if` is just a regular prefix operator. So, presumably there's some sort of well-formedness checking that goes on after parsing? Does anyone know more? The website says very little.
- breuleux 12y agoYeah that puzzles me a bit too. Multifix operators are not more complicated than prefix/postfix/infix (well, only marginally). For instance, you can give each operator a left priority and a right priority and merge them when they meet with the same priority. Then `if x then y else z` would become (if/then/else x y z) or something like that. I think that's saner and easier to handle than what he does.
- justinpombrio 12y agoYeah, that's what I was expecting too. And then XL could claim to have only five node types: integer, real, text, name, and multifix :-)
- c3d 12y agoIn XL, a multifix is a combination of infix, prefix or postfix. Note that the various nodes exist only for the programmer's convenience, i.e. they represent a user-visible syntax. Internally, I could do with only a node with two children. Something like [A,B,C,D] writes as: Block with [] containing Infix , containing Symbol A Infix , containing Symbol B Infix , containing Symbol C Symbol D So this allows me to represent multifix along with their expected syntax. I could also represent for example: [A, B; C, D] if A then B else C unless D for A in B..C loop D The last one is actually one of the for loop forms in XL
- breuleux 12y agoMultifix is more general than a combination of infix, prefix and postfix, though. For instance, a [] block is a multifix operator, but you can't implement it as a combination. The advantage of supporting multifix directly is that you get a more convenient and less confusing representation. For instance, given "if A then B else C" why should I expect (else (then (if A) B) C) and not (if (then A (else B C))? It's not obvious, and both are unwieldy compared to a ternary operator like (if/then/else A B C).
- c3d 12y agoMultifix is not more general than combinations of the 8 node types in XL, only more powerful than a combination of some subset. It's not simpler. XL started with a multifix representation, see http://mozart-dev.sourceforge.net/notes.html http://mozart-dev.sourceforge.net/notes.html. Switching to the current representation was a MAJOR simplification. The current representation captures the way humans parse the code. Infix captures "A+B" or "A and B". Prefix captures "+3" or "sin x". Postfix captures "3!" or "3km". Block captures "[A]", "(A)", "{A}" or indentation. Since humans perceive a difference, you need to record that difference somewhere. XL records that structure in the parse tree itself, not on side data structures such as grammar tables. This approach also enables multiple tree shapes that overlap. Consider the following XL program (I replaced asterisks with slashes because the asterisk means "italics" for HN): A/B+C -> multiply_and_add A, B, C A+B/C -> multiply_and_add B, C, A A+B -> add A, B A*B -> mul A, B In that case, I can match a multifix operator like multiply_and_add without needing a representation that would exclude matching A+B or A/B in other scenarios. This is especially important if you have type constraints on the arguments, e.g.: A:matrix/B:matrix+C:matrix -> ... A:matrix/B:real+C:real -> ... Those would be checked against X/Y+Z in the code, but if X, Y and Z are real numbers, they would not match. If you want to try it by yourself, you can download Tao from http://www.taodyne.com/shop/dev/en/content/10-compare-versions http://www.taodyne.com/shop/dev/en/content/10-compare-versio.... Tao uses XL as the basis of its dynamic document description. There's a tutorial here: http://www.taodyne.com/presentation/tutorial-2.0.html http://www.taodyne.com/presentation/tutorial-2.0.html. Please note that the XL implementation used in Tao has several limitations, notably with local functions and closures.
- 12y ago
- c3d 12y agoTrue, 'if 3' will stay there if there is no rewrite for it. You can also use treat a lack of possible rewrite as an error, this is what the Tao 3D document description language does. You'd get an error like "No form matches 'if 3'". Underneath, there is a rewrite operator, ->, that means to transform the shape on the left into the shape on the right. The precise semantics are a tiny bit more complicated than that, but it iterates until there is no more transformation that applies. Some specific rewrites will be transformed into "opcodes" of the underlying machine model. So A+B with integers on each side will execute an addition (the inner representation of the transform is something like A+B -> opcode Add). For more details, you can read http://xlr.sourceforge.net/sites/default/files/XLRef.pdf http://xlr.sourceforge.net/sites/default/files/XLRef.pdf. I badly need to update it, it's out of date, I have a more recent version, but I need to learn the new way to connect to SourceForge.