Miranda lexical syntax
In this section square brackets are used to enclose a set of literal
characters, using lex-style conventions, so eg [a-z] means a lower case
letter. As usual * and ? are used to mean zero-or-more, and
zero-or-one, occurrences of the preceding entity. Parentheses are used
for grouping, and subtraction of one syntactic entity from another means
set difference. We also revert to using |
for alternatives, as in
standard BNF.
script:= (token | layout)*
layout:= nl | tab | formfeed | space | comment
comment:= vertical_bar vertical_bar (any - nl)* nl
token:= identifier | IDENTIFIER | literal | typevar | delimiter
identifier:= ([a-z] [a-zA-Z0-9_']* ) - delimiter
IDENTIFIER:= [A-Z] [a-zA-Z0-9_']*
literal:= numeral | charconst | stringconst
literal1:= literal - float
numeral:= nat | float
nat:= [0-9] [0-9]*
float:= [0-9]* [.] nat epart? | nat epart
epart:= [e] [+|-]? nat
charconst:= ['] (visible-[\]|escape) [']
stringconst:= ["] (visible-[\"]|escape)* ["]
escape:= [\] ([ntfrb\'"]|nl|ascii_code)
typevar:= [*][*]*
delimiter:= - | prefix1 | infix1 | other
infix1:= ++ | -- | : | \/ | & | > | >= | = | ~= | <= | < | + | * |
/ | div | mod | ^ | . | ! | $identifier | $IDENTIFIER
infix:= infix1 | -
prefix1:= ~ | #
prefix:= prefix1 | -
other:= abstype | if | otherwise | readvals | show | type | where |
with | %export | %free | %include | %insert | %list | %nolist |
= | == | ::= | :: | => | vertical_bar | // | -> | ; | , | ( |
) | [ | ] | { | } | <- | .. | $$ | $- | $+ | $*
vertical_bar:= |
Notes
visible means any non-control character, including space (but not including eg newline), nl means literal newline, and ascii_code is a nat in the range 0..255 (maximum length 3 digits).
Notice that the syntax of numeral
does not include negative numbers.
Negative constants, such as -3 or -5.05e-17 are parsed by Miranda as
applications of the prefix operator -
to a positive numeral. This has
no semantic significance.
Omission - the definition of layout
does not include the additional
comment rules for LITERATE SCRIPTS (see separate manual section).