J syntax

 

J program

With J syntax, UML profiles, class attributes and methods have to be declared in the right order.

 

Program::=

         {attribute_declaration}

         {method_definition}

 

 

Class attributes

J class attributes can be declared with an initial value.

 

attribute_declaration::=

         class ':' [profile] attribute_name ':'

              class [assignment]';'

 

 

Method declaration

Method declaration is made up of the class which owns the method, its UML profile and its name, followed by its parameters and its possible return value.

 

method_definition::=

   class ':' [profile] method_specification

method_specification::=

   method_name parameter_designation_list

   [return class]

parameter_designation_list::=

         '(' [ <parameter_designation>

         {',' <parameter_designation>}])'

parameter_designation::=

   passing_mode class parameter_name

passing_mode::= 'in'|'inout'

 

 

Designating UML profiles

The designation of the UML profile is useful, either to declare a method, or to define explicitly the UML profile during the message sending.  The designation of the UML profile is in absolute mode (starting from "default" or "#"), or relative mode (starting from the current UML profile and possibly using the moving up "-").

 

UML profile::=

         [header_profile] [{profile_item}]
         profile_name profile_mode

header_profile::= <default |'#'>;

profile item::= profile_name '#';

profile_name::= <name | '-'>;

profile_mode::= <'#' | '##' >;

 

 

Designating a class

Classes are predefined, and will be either basic classes (integer, …), or metamodel classes.  The "[]" prefix is used to designate sets.

 

Class::= class | class'[]'

 

 

Defining blocks of instructions

Blocks of instructions appear either to define the content of the methods, or to define anonymous methods, linked to the sets resulting from a "select" or "while" command.  At the head of each block, local variables can be defined.

 

Block::=

   '{'

            {variable_declaration}

            {statement}

   '}'

 

 

Declaring local variables

Local variables are declared at the head of each block.  They can have an initial value.

 

variable_declaration::=

   class variable_name [assignment]

 

 

Instructions

Instructions can be:

·         a condition (if, else, etc.)

·         an assignment (=, ?=)

·         the sending of a message (object, method (parameter))

·         a message diffusion (object.<method (parameter))

·         the calling of an anonymous method

 

Statement::=

   if_statement

   | anonymous_statement

   | message_call ';'

   | [assign_statement] ';'

 

 

The "if" Instruction

The "if" instruction owns the "else" or " else if" operators, which allow you to easily combine several possible cases ("case" not being present).

 

if_statement::=

   'if' '('expression')'

                                            statement | compound_if_statement

   ['else' statement|compound_if_statement

compound_if_statement::=

   '{'

         {statement}

   '}'

 

 

Assignment

assign_statement::= assignable assignment-operator expression

assignable::= variable_name|parameter_name|attribute_name

assignment operator::= '='|'?='

 

 

Message sending/Message diffusion

The sending of a message consists of accessing an object, then designating a method name and its parameters.  Dynamic evaluation will launch the concerned method for the given object.

 

message_call::=

           instance_access call_operator

        [UML profile] method_name argument_list

instance_access::=[message_call | instance | iterator ]

                       {call_operator [message_call | instance |

                                    iterator ]}

instance::= attribute_name | variable_name |

             MetaModelInstance |

             'this' | 'super' | 'StdOut' | 'StdErr'

iterator::= 'select' '(expression)' | 'while' '('expression')'

call_operator::= '.' | '.<'

argument_list::=

         '('[<argument> {','argument}]')'

argument::= instance_access | integer_value | String_value

   | boolean_value | method_statement | set_access | 'this'

 

 

Anonymous methods

An anonymous method always comes after an expression.

 

anonymous_statement::= message_call

 

 

Expressions

expression::= argument | boolean_expression | arithmetic_expression

   | '('expression')'

boolean_expression::= expression '||' expression

                  | expression '&&' expression

                  | expression '==' expression

                  | expression '!=' expression

                  | expression relational_operator expression

                  | '!' expression

relational_operator::= '<' | '<=' | '>' | '>='

arithmetic_expression::= expression arith_op expression

arith_op::= '+' | '-' | '/' | '*' | '%'

 

 

J classes

J classes are basic classes, "stream" utility classes and metamodel classes.

 

basic_class::=

   MetaModelClass | 'Object' | 'String' | 'boolean' | 'int'
   | 'float' | 'inStream' | 'outStream' | 'stream'

 

 

Basic values

boolean value::= 'true' | 'false'

String_value::= Any symbol between " and "

int_value::= Any integer value