Class, Interface
Grammar
Class ::= "class" ID ("extends" QName)? ("implements" QName ("," QName)*)? "{" (Attribute | Method)* "}". Interface ::= "interface" ID ("extends" QName ("," QName)*)? "{" (MethodDeclaration)* "}". Attribute ::= VariableDeclaration (VariableInit)? ";". VariableDeclaration ::= Type ID. Type ::= (PrimitiveType | QName) ("[" "]")*. PrimitiveType ::= "boolean" | "byte" | "char" | "short" | "int" | "float" | "long" | "double". Method ::= ("override")? MethodDeclaration StatementBlock. MethodDeclaration ::= ID (MethodParameters)? (":" Type)?. MethodParameters ::= "(" (VariableDeclaration ("," VariableDeclaration)*)? ")".
Example Class
class Point implements IPoint{ int x; int y; Point(int x, int y) { this.x = x; this.y = y; } override getX() : int{ return this.x; } override getY() : int{ return this.y; } }
Example Interface
interface IPoint { getX() : int; getY() : int; }
Statements
Grammar
Statement ::= ( StatementBlock | IfStatement | SwitchStatement | WhileStatement | DoWhileStatement | ForStatement | ForEachStatement | VariableStatement | ConstructorStatement | ExpressionStatement | BreakStatement | ContinueStatement | ReturnStatement ). StatementBlock ::= "{" (Statement)* "}". IfStatement ::= "if" "(" Expression ")" Statement ("else" Statement)?. SwitchStatement ::= "switch" "(" Expression ")" "{" ("case" Expression ":" (Statement)*)* ("default" ":" (Statement)*)? "}" WhileStatement ::= "while" "(" Expression ")" Statement. DoWhileStatement ::= "do" Statement "while" "(" Expression ")" ";". ForStatement ::= "for" "(" VariableDeclaration ";" Expression ";" Expression ")" Statement. ForEachStatement ::= "for" "(" VariableDeclaration ":" Expression ")" Statement. VariableStatement ::= VariableDeclaration VariableInit ";". ConstructorStatement ::= ("super" | "this") "(" (ArgsList)? ")" ";". ExpressionStatement ::= Expression ";". BreakStatement ::= "break" ";". ContinueStatement ::= "continue" ";". ReturnStatement ::= "return" (Expression)? ";".
Example if-Statement
int i = 2; if (i>2) { }
Example switch-Statement
int i = 2; switch(i) { case 2 : return true; case 4 : return true; default : return false; }
Example while-Statement
int i = 2; while (i>2) { } do { } while (i>2);
Example for-Statement
for (int j = 0; j<10; j++) { } List list = [1,2,3]; for (Object element : list) { }
Example Variables
// Constructor Call Point p1 = new Point(2, 5); Point p2(2,5); // Assigning attribute values Point p3 = new Point{x = 2, y = 5}; Point p4{x = 2, y = 5};
Expressions
Grammar
Expression ::= ( AssignmentExpression | LogicalExpression | EqualityExpression | ArithmeticExpression | UnaryExpression | CastExpression | PrefixExpression | PostfixExpression | InstanceOfExpression | CreateExpression | AttributeExpression | MethodExpression | ArrayExpression | "this" | "super" | ID | LiteralExpression | ("(" Expression ")"). AssignmentExpression ::= Expression ("=" | "+=" | "-=" | "*=" | "/=" | "%=") Expression. LogicalExpression ::= Expression ("&&" | "||") Expression. EqualityExpression ::= Expression ("==" | "!=" | ">" | ">=" | "<" | "<=") Expression. ArithmeticExpression ::= Expression ("+" | "-" | "*" | "/"| "%") Expression. UnaryExpression ::= ("+" | "-" | "!") Expression. CastExpression ::= "(" Type ")" Expression. PrefixExpression ::= ("++" | "--") Expression. PostfixExpression ::= Expression ("++" | "--"). InstanceOfExpression ::= Expression "instanceof" Type. NewExpression ::= "new" QName (("[" "]") | (("(" (ArgsList)? ")")? ("{" ArgsMap "}")?)). MemberCallExpression ::= (Expression ".")? ID ("(" (ArgsList)? ")")?. ArrayExpression ::= Expression ("[" ArgsList "]")+. LiteralExpression ::= Integer | Double | Boolean | Char | String | Range | List | Map | Null VariableInit ::= ((("(" (ArgsList)? ")")? ("{" ArgsMap "}")?) | ("=" Expression)). ArgsList ::= Expression ("," Expression)*. ArgsMap ::= ArgsMapKeyValue ("," ArgsMapKeyValue)*. ArgsMapKeyValue ::= ID "=" Expression
Metadata
Grammar
Metadata ::= ID "=" MetadataValue. MetadataValue ::= MetadataValueSingle | MetadataValueList | MetadataValueMap. MetadataValueSingle ::= INTEGER | Double | CHAR | STRING | BOOLEAN | QName. MetadataValueList ::= "[" (MetadataValue ("," MetadataValue)*)? "]". MetadataValueMap ::= "[" (MetadataValueMapEntry ("," MetadataValueMapEntry)*)? "]". MetadataValueMapEntry ::= MetadataValue ":" MetadataValue.
See operators in ODL or queries in QDL for examples.
Literals
Grammar
Integer ::= (0..9)+. Double ::= (0..9)* "." (0..9)+. Boolean ::= ("true" | "false"). Char ::= "'" Unicode-Character "'". String ::= '"' (Unicode-Character)* '"'. Range ::= (0..9)+ ".." (0..9)+. List ::= "[" (Expression ("," Expression)*)? "]". Map ::= "[" (MapKeyValue ("," MapKeyValue)*)? "]". MapKeyValue ::= Expression ":" Expression. Null ::= "null".
Example
Range r = 1..10; List l = [1, 2, 3]; Map m = ["key1":1, "key2":2];
Identifier, Qualified Name, Namespace
Grammar
ID ::= ("a".."z"|"A".."Z"|"_")("a".."z"|"A".."Z"|"_"|"0".."9")*. QName ::= ID ("::" ID)* Namespace ::= "use" QualifiedNameWithWildcard ";". QualifiedNameWildcard ::= QualifiedName ("::*")?
Example
use java::util::*; use de::uniol::inf::is::odysseus::core::ISubscription; use com::google::common::collect::ImmutableMap;
Java-Code
Grammar
GPLCode ::= "$*" GPL Code "*$"
Example
$* public static void main(String[] args) { } *$
Comments
Grammar
Comment ::= SingeLineComment | MultiLineComment. SingeLineComment ::= "//" Text (("\r")? "\n")?. MultiLineComment ::= "/*" Text "*/".
Example
// This is a single line comment /* * This is a multi line comment */