Thursday, April 8, 2010

ParaSail BNF

Here is the beginnings of a BNF for ParaSail. It is incomplete, particularly in the lower level productions for compound statements.  Also there is no attempt to convey precedence of operators.  The intent is that "normal" precedence would be used for the familiar arithmetic operators, and for less familiar operators, parenthesization would be required to disambiguate if there might be any confusion possible.  Future postings will elaborate on these productions with examples, etc.  We may also edit this posting to add some of the missing lower-level productions.

----------------------------------

module ::= interface_declaration | class_definition

interface_declaration ::=
   [abstract] [concurrent] interface module_defining_name
     [ extends interface_name_list ]
     '<' module_formal_list '>' is
      interface_element_list
   end interface module_defining_name;
  
  
module_defining_name ::= identifier { '::' identifier }


module_formal_list ::=
  [ annotated_module_formal { ';' annotated_module_formal } ]

annotated_module_formal ::=
  [ annotation ] module_formal [ annotation ]


module_formal ::= type_formal | value_formal

type_formal ::= [identifier is] module_instantiation

value_formal ::= identifier ':' type_name



type_name ::= qualified_name

qualified_name ::= identifier { '::' identifier }


module_instantiation ::=
  module_name '<' module_actual_list '>'


module_name ::= qualified_name

module_actual_list ::= [ module_actual { ',' module_actual } ]

module_actual ::=
    [ selector '=>' ] type_specifier
  | [ selector '=>' ] expression

selector ::= identifier

type_specifier ::=
  type_name [ annotation ] | module_instantiation

interface_element_list ::= { interface_element ';' }

interface_element ::=
   operation_declaration | object_declaration
 | interface_declaration | type_declaration


class_definition ::=
   [concurrent] class module_defining_name
      [ extends interface_name ]
      '<' module_formal_list '>' is
      { local_class_element ';' }
   exports
      { exported_class_element ';' }
   end class module_defining_name;
  

local_class_element ::=
  interface_element | exported_class_element
 
exported_class_element ::=
  operation_definition | object_definition | class_definition
 
  
annotation ::= '{' annotation_element_list '}'

annotation_element_list ::=
  annotation_element { ';' annotation_element }

annotation_element ::= boolean_expression

boolean_expression ::= expression


operation_declaration ::=
  function_declaration | procedure_declaration | operator_declaration

function_declaration ::=
  function identifier [ operation_input_list ] '->' operation_output_list
 
procedure declaration ::=
  procedure identifier operation_input_list
 
operator_declaration ::=
  operator operator_designator operation_input_list
     [ '->' operation_output_list ]
 
operator_designator ::= string_literal
 
operation_input_list ::=
    annotated_operation_input
  | '(' annotated_operation_input { ';' annotated_operation_input } ')'
      [ annotation ]

annotated_operation_input ::=
  [ annotation ] operation_input [ annotation ]

operation_input ::=
    [ identifier ':' ] [ input_modifier ] operand_type_specifier
 
operand_type_specifier ::= type_name | type_formal

input_modifier ::= output_modifier
  | queued [ output_modifier ]
  | locked [ output_modifier ]


operation_output_list ::=
   annotated_operation_output
 | '(' annotated_operation_output { ';' annotated_operation_output } ')'
      [ annotation ]

annotated_operation_output ::=
  [ annotation ] operation_output [ annotation ]

operation_output ::=
  [ identifier ':' ] [ output_modifier ] operand_type_specifier

output_modifier ::=  ref | ref var | ref const


object_delaration ::=
   var_or_const identifier ':' type_specifier [ ':=' expression ]
  
var_or_const ::= var | const

object_definition ::=
    const identifier [ ':' type_specifier ] ':=' expression
  | var identifier ':' [ optional ] type_specifier [ ':=' expression ]
  | var identifier ':=' expression
 
type_declaration ::= type identifier is [ new ] type_specifier


operation_definition ::=
  function_definition | procedure_definition | operator_definition

function_definition ::=
  function_declaration is statement_list ';' end function identifier

procedure_definition ::=
  procedure_declaration is statement_list ';' end procedure identifier

operator_definition ::=
  operator_declaration is statement_list ';' end operator identifier


statement_list ::=
    annotated_statement
  | statement_list ';;' statement_list
  | statement_list ';' statement_list
  | statement_list '||' statement_list
  | '(' statement_list ')'
 
annotated_statement ::= [ annotation ] statement [ annotation ]

statement ::= local_declaration | local_definition
  | simple_statement | compound_statement

simple_statement ::=
    variable ':=' expression
  | variable ':=:' variable
  | operation_name '(' operation_actual_list ')'
  | return [ operation_actual_list ]
 
local_declaration ::= operation_declaration | type_declaration

local_definition ::=
    object_definition
  | operation_definition

compound_statement ::=
    if_statement
  | case_statement
  | while_loop_statement
  | for_loop_statement

expression ::=
    primary
  | aggregate
  | operator expression
  | expression operator expression
  | operation_name '(' operation_actual_list ')'
  | expression '[' operation_actual_list ']'
  | expression '.' selector
  | expression [not] in range
  | expression '?' expression ':' expression
 
primary ::=
    object_name
  | integer_literal
  | real_literal
  | character_literal
  | string_literal
  | null
  | '(' expression ')'
  | '[[' expression ']]'
 
operation_actual_list ::= [ operation_actual { ',' operation_actual } ]

operation_actual ::= [ selector '=>' ] expression

operation_name ::= qualified_name

object_name ::= qualified_name

operator ::=
    '+'  | '-' | '*'  | '/' | '**'
  | '=?' | '=' | '!=' | '<' | '<=' | '>' | '>='
  | and [then] | or [else]  | xor  | not | '==>'


aggregate ::= class_aggregate | container_aggregate

class_aggregate ::= '(' operation_actual_list ')'

container_aggregate ::= '[' container_element_list ']'
 
container_element_list ::= container_element { ',' container_element }

container_element ::= container_key '=>' expression_stream

container_key ::= expression

expression_stream ::= expression { '~' expression } [ ':' expression ]

comment ::= '//' { non_end_of_line_character }

string_literal ::= " { non_double_quote_character | escaped_character } "

character_literal ::= ' { non_single_quote_character | escaped_character } '

escaped_character ::= '\' { non_end_of_line_character }