3 ms·
Types are moving to the right because having them on the left makes the grammar undecidable. Languages like C or C++ can only be parsed when semantic informatio
by majewsky 8y ago
Types are moving to the right because having them on the left makes the grammar undecidable. Languages like C or C++ can only be parsed when semantic information is passed back into the parser.
For example, consider the following C++ statement:
a b(c);
This is a declaration of `b`. If `c` is a variable, this declares `b` of type `a` and calls its constructor with the argument `c`. If `c` is a type, it declares `b` to be a function that takes a `c` and returns an `a`.
- mehrdadn 8y ago> Types are moving to the right because having them on the left makes the grammar undecidable. This is just an artifact of how they designed the syntax in some languages like C++ or C#. You can easily put types on the left in a way that makes this false.
- SamReidHughes 8y agoThat's only if you have weird function type syntax like C does.
- colmvp 8y agoIs this an example of the 'Most Vexing Parse' problem?
- WalterBright 8y ago`a b(c);` is always a declaration of function `b` in D. To construct `b` of type `a`, it is written instead: a b = a(c); // one way auto b = a(c); // preferred way
- UIZealot 8y agoIf you're designing a new programming language anyway, why not go with: var int a function int f() Clear and easy to parse.