New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expression and type grouping – () and <> #13
Comments
Another possibility would be to have |
No, nonsense, that doesn’t work with |
Excerpt from the official Java 7 grammar:
( |
@gavinking what do you think? Should I adopt the compiler’s |
IIRC the reason for the split b/w The reason we don't have a |
I thought that |
You see lots of stuff like this in the grammar: spreadArgument returns [SpreadArgument positionalArgument]
: PRODUCT_OP
{ $positionalArgument = new SpreadArgument($PRODUCT_OP); }
unionExpression
{ Expression e = new Expression(null); // <--
e.setTerm($unionExpression.term); // <--
$positionalArgument.setExpression(e); } // why not $positionalArgument.setTerm($unionExpression.term); ?
; |
The grammar contains this hierarchy of expression rules:
If we adopted this structure in the AST, we would solve both this issue and #18. I’m thinking something like this: ...
abstract class Expression10 of SumExpression|DifferenceExpression|Expression11
abstract class Expression11 of ScaleExpression|Expression12
...
class SumExpression(Expression10 left, Expression11 right)
class ScaleExpression(Expression12 left, Expression11 right)
... or ...
abstract class AdditiveExpression of SumExpression|DifferenceExpression|ScalingExpression
abstract class ScalingExpression of ScaleExpression|MultiplicativeExpression
...
class SumExpression(AdditiveExpression left, ScalingExpression right)
class ScaleExpression(MultiplicativeExpression left, ScaleExpression right)
... Conceptually, I like this approach, but I’m not sure about the naming of either of the variants above: I don’t like the many numbers of the first, but in the second the |
I guess the numbers in SumExpression {
ProductExpression {
NaturalLiteral(1);
NaturalLiteral(2);
};
NaturalLiteral(3);
} and that would be well-typed. If you swapped |
Of course, |
Yeah, I’ll definitely go with |
I’m going to start with the types first, though, because their hierarchy is simpler (and I need them for expressions anyway). Draft for the names:
|
Oh, and ceylon/ceylon-spec#852. |
Now that both |
I’m done with the type hierarchy! (Not pushed yet because of compiler bugs.) So now I get to start with the actual expressions. One thing to note is that I ended up making the |
I suppose I could add I also don’t know how useful it is that people can override |
(And since |
WRT
|
Wait, no, this would still require every user to either
Also, for the expression hierarchy the aliases would be pretty long (when fully expanded), so the second variant is completely unfeasible. |
I might just be stupid, but I can’t think of any cases where you’d call |
Okay, I think the plan now is:
|
(I’m working on the hierarchy in https://gist.github.com/lucaswerkmeister/64a59e091b70b36469d1) |
So, back to the names of I’m not completely sure if it should be (Edited again because I confused precedence and associativity.) |
No, I think |
and aliases for operator precedence (see #13). ExponentiationOperation includes a really ugly workaround for a bug that may or may not be ceylon/ceylon-compiler#1728; I’ll investigate that some more.
Well, the name pattern I’ll try to see if I can come up with good non-numerical names once more. |
As I wrote these down, I realized that
So let’s try the |
Hm,
|
I really just need to stop pretending that it’s possible to shoehorn all these operations into one naming scheme. Let’s keep the “name based on own expression” scheme, but drop all grammar schemes, and see where that gets us:
(Actually, most names seem fine with |
Or perhaps
In general, that seems a bit better to me. |
One issue I still have with these names is that they no longer convey that these aliases are just auxiliary constructs to represent precedence. Perhaps a different suffix than the generic |
That could be solved with
but those names feel too long to me, even for auxiliary constructs. |
Final draft:
Avoiding the names “anding”, “oring” and “notting” because they’re just too silly. These names are not supposed to appear in user code often, so I think it’s okay to use “conjoining” and “disjoining”. As for “inverting” vs “negating”, the interface is called It’s now been exactly four months since the original idea for representing precedence in the type system first came up… I just need to finally get this done. |
In Ceylon, there are two kinds of syntactical grouping:
(I made up the names, but that doesn’t matter right now.)
In the Ceylon compiler, these are handled differently:
expression
, which is a wrapper around aTerm
with optional parentheses. All the expression classes –InvocationExpression
,BinaryOperatorExpression
, etc. – extendTerm
, notExpression
. AnExpression
is aTerm
. Grammar rules often look like this:groupedType
, but no corresponding class. The<
and>
tokens are discarded – the AST offers no way to discover if a type was grouped or not. (This caused me some headache in lucaswerkmeister/ceylon.formatter#23.)How do we handle these in
ceylon.ast
?The text was updated successfully, but these errors were encountered: