This section presents the grammar for Theta. This grammar is authoritative wherever it conflicts with syntax productions in the previous section of the manual.
program units, routine specifications, and equates
<program_unit> -> <routine_interface> | <equate> | <type_interface> | <module> <routine_interface> -> <proc_interface> | <iter_interface> <equate> -> <idn> "=" <expr> | <idn> "=" <type_designator> <proc_interface> -> <idn> [<parms>] <formal_args> [<returns>] [<signals>] [<where>] <iter_interface> -> <idn> [<parms>] <formal_args> <yields> [<signals>] [<where>] <parms> -> "[" <idn_list> "]" <idn_list> -> <idn> ["," <idn>]* <formal_args> -> "(" [<decl> ["," <decl>]*] ")" <decl> -> <idn_list> ":" <type_designator> <returns> -> returns "(" <type_list> ")" <type_list> -> <type_designator> ["," <type_designator>]* <yields> -> yields "(" <type_list> ")" <signals> -> signals "(" <exception> ["," <exception>]* ")" <exception> -> <name> ["(" <type_list> ")"] <name> -> <idn> <where> -> where <restriction> ["," <restriction>]* <restriction> -> <idn> has <nonparam_interface> ["," <nonparam_interface>]* <nonparam_interface> -> <idn> <nonparam_proc_sig> | <idn> <nonparam_iter_sig> <nonparam_proc_sig> -> "(" [<type_list>] ")" [<returns>] [<signals>] <nonparam_iter_sig> -> "(" [<type_list>] ")" <yields> [<signals>]
type specifications
<type_interface> -> <idn> "=" type [<parms>] [<supertypes>] [<where>] [<interface_or_equate>]* end <idn> <supertypes> -> "<" <superinfo> ["," <superinfo>]* <superinfo> -> <type_designator> ["{" <renames> ["," <renames>]* "}" ] <renames> -> <idn> for <idn> <interface_or_equate> -> <routine_interface> | <equate>
type designators
<type_designator> -> <simple_type_desig> | <routine_type_desig> | <parm_type_desig> | <tagged_type_desig> <simple_type_desig> -> <idn> | 'null' | 'bool' | 'char' | 'int' | 'real' | 'string' | 'any' <routine_type_desig> -> proc <nonparam_proc_sig> | iter <nonparam_iter_sig> <parm_type_desig> -> <parm_type> <actual_parms> <parm_type> -> <idn> | 'array' | 'sequence' | 'vector' | 'maybe' <actual_parms> -> "[" <type_list> "]" <tagged_type_desig> -> <tagged_type> "[" <field> ["," <field>]* "]" <tagged_type> -> 'record' | 'struct' | 'oneof' <field> -> <idn_list> ":" <type_designator>
modules
<module> -> module [<implements>] [<impl_elt>]* end <implements> -> implements <exported_item> ["," <exported_item>]* <exported_item> -> <idn> [ "{" <idn_list> "}" ] | <idn> <actual_parms> "{" <idn_list> "}" <impl_elt> -> <routine_def> | <class_def> | <maker_def> | <equate> <routine_def> -> <routine_interface> <body> end <idn> <maker_def> -> <maker_interface> <body> end <idn> <maker_interface> -> <idn> [<parms>] <formal_args> <makes> [<signals>] [<where>] <makes> -> makes "(" <type_designator> ")" <body> -> [<equate>]* [<statement>]* <class_def> -> <idn> "=" class [<parms>] [<for_type>] [<inherits>] [<where>] [<provides>] [<hides>] [<equate_or_ivar_decl>]* [<equate_or_routine_def>]* end <idn> <for_type> -> for <type_designator> <inherits> -> inherits <type_designator> ["{" <renames> ["," <renames>]* "}"] <provides> -> provides <idn_list> <hides> -> hides <idn_list> <equate_or_ivar_decl> -> <equate> | <ivar_decl> <ivar_decl> -> <decl> | <decl_with_impls> <decl_with_impls> -> <idn> ":" <type_designator> implements <idn> ["," <idn>] <equate_or_routine_def> -> <equate> | <routine_def>
statements
<statement> -> <decl> | <lhs> ":=" <expr> ["," <expr>]* | <lhs> ":=" <invoc> | <simple_invoc> | <primary> "[" <expr> "]" ":=" <expr> | return ["(" <expr> ["," <expr>]* ")"] | yield "(" <expr> ["," <expr>]* ")" | signal <name> ["(" <expr> ["," <expr>]* ")"] | exit <name> ["(" <expr> ["," <expr>]* ")"] | if <expr> then <body> [elseif <expr> then <body>]* [else <body>] end | while <expr> do <body> end | for <for_idns> in <invoc> do <body> end | break | continue | begin <body> end | tagcase <expr> <tag_arm> [<tag_arm>]* [others ":" <body>] end | typecase <expr> <type_arm> [<type_arm>]* [others ":" <body>] end | <statement> except [<handler>]* [others ["(" <idn> ":" 'string' ")"] ":" <body>] end | <statement> resignal <name> ["," <name>]* | make "{" [<ivar_inits>] "}" [then <body> end] <lhs> -> <var> ["," <var>]* | <decl> ["," <decl>]* <var> -> <idn> | <primary> "." <idn> <invoc> -> <expr> "(" [<args>] ")" <args> -> <expr> ["," <expr>]* ["," <varying_args>] | <varying_args> <varying_args> -> .. | .. <expr> ["," <expr>]* <simple_invoc> -> <primary> "(" [<args>] ")" <for_idns> -> <idn_list> | <decl> ["," <decl>]* <tag_arm> -> when <name> ["," <name>]* ["(" <idn> ":" <type_designator> ")"] ":" <body> <type_arm> -> when <type_designator> ["(" <idn> ")"] ":" <body> <handler> -> when <name> ["," <name>]* ["(" <decl> ["," <decl>]* ")"] ":" <body> <ivar_inits> -> <field_inits> ";" <maker_invoc> | <field_inits> | <maker_invoc> <field_inits> -> <field_init> ["," <field_init>]* <field_init> -> <idn> ":=" <expr> <maker_invoc> -> <idn> [<actual_parms>] "(" [<args>] ")"
expressions
<expr> -> <simple_expr> | <expr> "." <idn> | <expr> "." <method_idn> | <invoc> | <expr> "[" <expr> "]" | "~" <expr> | "-" <expr> | <expr> <binary_op> <expr> | "(" <expr> ")" <primary> -> <simple_expr> | <primary> "." <idn> | <primary> "." <method_idn> | <simple_invoc> | <primary> "[" <expr> "]" <simple_expr> -> <literal> | <idn> [<actual_parms>] | self | <method_idn> | <tagged_type_desig> "{" <field_inits> "}" | <type_designator> "{" [<ivar_inits>] "}" | bind "(" <expr> <bind_args> ")" <method_idn> -> ["^"] <idn> [<actual_parms>] <bind_args> -> ["," <bind_arg>]* ["," <varying_args>] <bind_arg> -> <expr> | "*" <literal> -> 'nil' | 'true' | 'false' | <int_literal> | <char_literal> | <real_literal> | <string_literal> <binary_op> -> "**" | "//" | "/" | "*" | "||" | "+" | "-" | "<" | "<=" | "=" | ">=" | ">" | "==" | "~=" | "&" | "|"