Replies: 1 comment
-
New idea for omitting parentheses in callsIn LESv2 the
which means
I copied this rule into LESv3 even though the motivation for it (superexpressions) had disappeared. So now I'm thinking, huh, what if Then you could write What precedence should this operator have? Well, Haskell defines a very similar Note the need for double-
Since this would be a pseudo-operator, not a real operator, Another question is whether it should be possible to call a method of two arguments with this pseudo-operator. Er, probably not. The ambiguity monster stirs... I'm inclined to require that there be no space to the left of |
Beta Was this translation helpful? Give feedback.
-
ASCII doesn't have enough characters.
For LESv3, I designed a special use for single quote (followed by a space or an identifier): it would cause a parsing mode where each tokens is simply converted to a Loyc tree, e.g.
(' x+y, z)
means(`'`(x, `'+`, y, `',`, z))
. Inside this mode, square and curly brackets[] {}
temporarily switch back to normal parsing. This works great for DSLs of unusual syntax, such as parser generators:I've been wondering if it wouldn't have more value to use the single quote differently. For one thing, I was looking at some Ruby code the other day and I was like "this is nice."
Meanwhile, Julia and (I think) MATLAB have a nice syntax for matrixes that is space-sensitive, something like
Could LES understand lines like these?
Maybe, but I don't think
;
would work as a delimiter unless it terminates the special parsing mode, because outside brackets it should mark end-of-statement. And similarly for comma:An ordinary operator character could delimit matrix rows instead:
The change I'm thinking of would have two parts:
The second rule is motivated by examples like
'print (x + 1)*x
because surely this must mean
print((x + 1) * x)
and notprint((x,
'+, 1) * x)
, which is what it might mean if parentheses don't reset the parsing mode.Both of these changes would harm the ability to parse grammars. #1 would mean that
X?
is a syntax error, while #2 would mean thatA (B | C D)
is a syntax error. Another disadvantage is that, by convention,'
means "operator", but I specifically want to use it to call ordinary non-operator functions likesin
orprint
. Finally, I defined this notation as being able to accept multiple arguments, but that's not good for unary operators, as we'd like'sin x + 1
to meansin(x) + 1
and notsin(x,
'+, 1)
.So, while it would be nice to create opportunities to avoid parentheses, the cost seems too high for this idea. Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions