Syntax

Keywords

    return new true false null super this instanceof if while for

Root defintions

A PIL program consists of one or more declarations. A declaration consists of zero or more annotations, followed by the actual declaration.

    Application ::= Declaration*
    Declaration ::= Annotation* Decl
    Annotation  ::= "@" QId
    Annotation  ::= "@" QId "(" {Exp ","}* ")"

Classes

    Decl      ::= "class" QId SuperClassDeclaration?
         "{" ClassBodyDeclaration* "}"  
    Decl      ::= "class" QId "<" {Id ","}* ">" SuperClassDeclaration?
         "{" ClassBodyDeclaration* "}"  
    Decl      ::= "external" "class" ClassName SuperClassDeclaration?
         "{" ExternalClassBodyDeclaration* "}"  
    ClassName ::= QId TypeParams?

    SuperClassDeclaration        ::= "extends" Type
    ClassBodyDeclaration         ::= Annotation* ClassBodyDecl
    ExternalClassBodyDeclaration ::= Annotation* ExternalClassBodyDecl

Method declarations

    ClassBodyDecl         ::= Type MethodId "(" {FormalArg ","}* ")" Block

new and as<...> are special types of methods. new defines the constructor and as methods define casts/conversions between types.

    ClassBodyDecl         ::= "new" "(" {FormalArg ","}* ")" SuperInv? Block
    ClassBodyDecl         ::= "as" "<" Type ">" Block

    ExternalClassBodyDecl ::= "new" "(" {FormalArg ","}* ")" ";"
    ExternalClassBodyDecl ::= Type MethodId "(" {FormalArg ","}* ")" ";"
    ExternalClassBodyDecl ::= "as" "<" Type ">" ";"

    SuperInv              ::= "extends" "super" "(" {Exp ","}* ")"

Statements

    Block     ::= "{" Statement* "}"
    Statement ::= Stat ";"
    VarDecl   ::= Type Id "=" Exp
    Stat      ::= VarDecl
    Stat      ::= Exp
    Stat      ::= LHS "=" Exp
    Stat      ::= "return" Exp
    Stat      ::= "return"
    Stat      ::= "throw" Exp

    LHS       ::= QId
    LHS       ::= Exp "." Id

    Statement ::= Block
    Statement ::= "if" "(" Exp ")" Statement "else" Statement
    Statement ::= "if" "(" Exp ")" Statement
    Statement ::= "for" "(" Type Id ":" Exp ")" Block
    Statement ::= "for" "(" VarDecl ";" Exp ";" Exp ")" Block
    Statement ::= "while" "(" Exp ")" Block
    Statement ::= "try" Block Catch* Finally?
    Statement ::= "catch" "(" FormalArg ")" Block
    Statement ::= "finally" Block

And syntactic sugar for type inference:

    Stat ::= "var" Id "=" Exp

And indexers:

    LHS  ::= Exp "[" Exp "]"

Expressions

All basic literals are expression:

    Exp ::= QId
    Exp ::= Int
    Exp ::= Float
    Exp ::= String
    Exp ::= Char
    Exp ::= String
    Exp ::= "true"
    Exp ::= "false"
    Exp ::= "null"
    Exp ::= "this"
    Exp ::= "super"

In PIL, the use of operators are basically syntactic sugar for method calls. The expression 2 + 2, for instance, is in fact the same as 2.+(2). Which operators can be used between expressions is defined below:

    Exp ::= "(" Exp ")"
    Exp ::= Exp "." Id
    Exp ::= Exp BoolMethodId Exp
    Exp ::= Exp CompareMethodId Exp
    Exp ::= Exp TermOperatorMethodId Exp
    Exp ::= Exp OperatorMethodId Exp
    Exp ::= Exp PostFixId
    Exp ::= Exp "instanceof" Type
    Exp ::= Exp "isa" Type
    Exp ::= "!" Exp
    Exp ::= Exp "." MethodId "(" {Exp ","}* ")"
    Exp ::= Exp "." "as" "<" Type ">"
    Exp ::= QId "<" {Type ","}* ">" "(" {Exp ","}* ")"
    Exp ::= QId "(" {Exp ","}* ")"
    Exp ::= "new" Type "(" {Exp ","}* ")"

    BoolMethodId         ::= "||" | "&&"                     
    CompareMethodId      ::= "==" | "!=" | "<" | "<=" | ">" | ">="
    TermOperatorMethodId ::= "*" | "/" | "<<" | ">>" | "&" | "|" | "%"
    OperatorMethodId     ::= "+" | "-"
    PostFixId            ::= "++" | "--"
    MethodId             ::= Id | BoolMethodId | CompareMethodId |
                             TermOperatorMethodId | OperatorMethodId | PostFixId

And sugar (indexers, expression blocks):

    Exp ::= Exp "[" Exp "]"
    Exp ::= "{|" Statement* "|" Exp "|}"
    Exp ::= "typeof" Type

Functions and global variables

As an addition to its Java roots, PIL adds global variables and global functions:

    Decl      ::= Type QId "(" {FormalArg ","}* ")" Block
    Decl      ::= "external" TypeParams? Type QId "(" {FormalArg ","}* ")" ";"
    FormalArg ::= Type Id
    FormalArg ::= Type "*" Id

    Decl      ::= Type QId "=" Exp ";"
    Decl      ::= "external" Type QId ";"