Function type -postfix

Rémi Forax forax at univ-mlv.fr
Mon Feb 8 17:14:57 PST 2010


I wonder if postfix syntax id not better than the prefix one.

Let's try some examples:

a function that takes an int and returns an int:
int->int

a function that takes two ints and returns an int:
int,int->int
I think this syntax will not generate conflicts despite the fact
that ',' can be used in expressions if int->int.class and
implementing a function type are not allowed.

Here parenthesis are mandatory, the rule is if you want to have
a function type in a function type, parens are required:
int, (int->int)->int

this means that int -> int -> int is illegal and
should be written:
int -> (int -> int) or (int -> int) -> int

The syntax for array of function type, again parenthesis
are mandatory:
(int->int)[]

The syntax with an exception: throws is before the arrow:
int,int throws Exception->int

Here is the syntax of a function that takes an int and
a function that takes an int and return an int. The
former function throws an Exception and returns an int.
int, (int -> int) throws Exception->int

Here the syntax is can be confused with
int, (int throws Exception -> int) -> int
but the rule is simple throws is before the arrow.

Here is the proposed grammars:

BasicType = ClassType
          |  PrimitiveType
          |  ArrayType
          ;

Type = BasicType
          |  FunctionType
          ;

ArrayType = BasicType  '[' ']'
                   |   '(' FunctionType ')'  '[' ']'
                   ;

FunctionType = ElementTypes ThrowsOpt '->' ReturnElementType
                         ;

ElementTypes = ElementType
                          |  ElementTypes ',' ElementType
                          ;

ElementType = BasicType
                        |   '(' FunctionType ')'
                        ;

ReturnElementType = ElementType
                                    | void
                                    ;


'#' can be added at the starts of the function type,
but I think it is not a requirement.

Rémi


More information about the lambda-dev mailing list