6.13 Summary of the Malaga Syntax
The syntax of Malaga source texts is defined formally by a sort of EBNF
notation:
- Terminals like
assert and `:=' stand for themselves.
- Nonterminals like assignment are defined by productions.
- A bar `|' separates alternatives.
- Brackets `[]' enclose optional parts.
- Curly braces `{}' enclose parts that are repeated zero times, one time, or
multiple times.
- Parentheses `()' are used for grouping.
The start productions for Malaga source texts are
lexicon-file, rule-file, and symbol-file. A
nonterminal marked with `*' in its definition is a lexical
symbol.
- assert-statement:
- (
assert | `!') condition `;'
- assignment:
- path (`:=' | `:=+' | `:=-' | `:=*' |
`:=/') expression `;' | `<' path {`,'
path} `>' `:=' expression `;'
- break-statement:
break [label] `;'
- choose-statement:
choose variable in expression `;'
- comment*:
- `#' {printing-char}
- comparison:
- [
not] (expression [comparison-operator
expression] | match-comparison)
- comparison-operator:
- `=' | `/=' | `~' | `/~' |
in | less |
greater | less_equal | greater_equal
- condition:
- comparison ({
and comparison} | {or
comparison})
- constant*:
- `@' identifier
- constant-definition:
- (
define | default) constant `:='
constant-expression `;'
- constant-expression:
- expression
- continue-statement:
continue [label] `;'
- define-statement:
define variable `:=' expression `;' |
define `<' variable {`,' variable}
`>' `:=' expression `;'
- error-statement:
error expression `;'
- expression:
- term {(`+' | `-') term}
- factor:
- value {`.' value}
- foreach-statement:
- [label `:']
foreach variable in
expression `:' statements end
[foreach] `;'
- identifier*:
- (letter | `_' | `&') {letter | digit |
`_' | `&'}
- if-statement:
if condition then statements
{elseif condition then statements}
[else statements] end [if] `;'
- if-expression:
if condition then expression
{elseif condition then expression}
else expression end [if]
- include:
include string `;'
- initial:
initial constant-expression `,' rule-set `;'
- label:
- identifier
- lexicon-file:
- {constant-definition | constant-expression `;'}
- list:
- `<' {expression {`,' expression}} `>'
- match:
- constant-expression [`:' variable] | variable
`:' constant-expression
- match-comparison:
- expression
matches ( `(' match {`,'
match} `)' | match {`,' match} )
- number*:
- digit {digit} ( `L' | `R' | [`.' digit
{digit}] [`E' digit {digit}] )
- path:
- variable {`.' value}
- record:
- `[' {symbol-value-pair {`,'
symbol-value-pair}} `]'
- repeat-statement:
repeat statements while condition `;'
statements end [repeat] `;'
- require-statement:
- (
require | `?') condition `;'
- result-statement:
result expression [`,' (rule-set |
accept)] `;'
- return-statement:
return expression `;'
- rule:
- rule-type rule-name `(' variable {`,'
variable} `)' `:' statements
end
[rule-type] [rule-name] `;'
- rule-file:
- {rule | constant-definition | initial |
include}
- rule-name:
- identifier
- rule-set:
rules (rules {else rules} | `('
rules {else rules} `)')
- rule-type:
allo_rule | combi_rule | end_rule |
pruning_rule | robust_rule | input_filter |
output_filter | subrule
- rules:
- rule-name {`,' rule-name}
- select-statement:
select statements {or statements}
end [select] `;'
- statements:
- {assert-statement | assignment | break-statement |
choose-statement | continue-statement | define-statement |
error-statement | foreach-statement | if-statement |
select-statement | repeat-statement | require-statement |
result-statement | return-statement | stop-statement}
- stop-statement:
stop `;'
- string*:
- `"' {char-except-double-quotes | `\"' | `\\'} `"'
- subrule-invocation:
- rule-name `(' expression {`,' expression}
- symbol:
- identifier
- symbol-definition:
- symbol [`:=' `<' symbol {`,' symbol}
`>'] `;'
- symbol-file:
- {symbol-definition | include}
- symbol-value-pair:
- expression `:' expression
- term:
- factor {(`*' | `/') factor}
- value:
- [`-'] (symbol | string | number | list |
record | constant | subrule-invocation |
variable | `(' condition `)') | if-expression
- variable*:
- `$' identifier