slices are first class citizens

This commit is contained in:
Araq
2011-04-22 10:53:43 +02:00
parent 1985ac6995
commit 8dda362fa6
12 changed files with 177 additions and 127 deletions

View File

@@ -1,26 +1,27 @@
module ::= ([COMMENT] [SAD] stmt)*
comma ::= ',' [COMMENT] [IND]
operator ::= OP0 | OR | XOR | AND | OP3 | OP4 | OP5 | OP6 | OP7
operator ::= OP1 | OP2 | OP3 | OP4 | OP5 | OP6 | OP7 | OP8 | OP9
| 'or' | 'xor' | 'and'
| 'is' | 'isnot' | 'in' | 'notin'
| 'div' | 'mod' | 'shl' | 'shr' | 'not'
| 'div' | 'mod' | 'shl' | 'shr' | 'not' | '..'
prefixOperator ::= OP0 | OP3 | OP4 | OP5 | OP6 | OP7 | 'not'
prefixOperator ::= operator
optInd ::= [COMMENT] [IND]
optPar ::= [IND] | [SAD]
lowestExpr ::= otherExpr ('..' optInd otherExpr)*
otherExpr ::= orExpr (OP0 optInd orExpr)*
orExpr ::= andExpr (OR | 'xor' optInd andExpr)*
andExpr ::= cmpExpr ('and' optInd cmpExpr)*
cmpExpr ::= ampExpr (OP3 | 'is' | 'isnot' | 'in' | 'notin' optInd ampExpr)*
ampExpr ::= plusExpr (OP4 optInd plusExpr)*
plusExpr ::= mulExpr (OP5 optInd mulExpr)*
mulExpr ::= dollarExpr (OP6 | 'div' | 'mod' | 'shl' | 'shr' optInd dollarExpr)*
dollarExpr ::= primary (OP7 optInd primary)*
lowestExpr ::= orExpr (OP1 optInd orExpr)*
orExpr ::= andExpr (OP2 optInd andExpr)*
andExpr ::= cmpExpr (OP3 optInd cmpExpr)*
cmpExpr ::= sliceExpr (OP4 optInd sliceExpr)*
sliceExpr ::= ampExpr (OP5 optInd ampExpr)*
ampExpr ::= plusExpr (OP6 optInd plusExpr)*
plusExpr ::= mulExpr (OP7 optInd mulExpr)*
mulExpr ::= dollarExpr (OP8 optInd dollarExpr)*
dollarExpr ::= primary (OP9 optInd primary)*
indexExpr ::= '..' [expr] | expr ['=' expr]
indexExpr ::= expr ['=' expr]
castExpr ::= 'cast' '[' optInd typeDesc optPar ']' '(' optInd expr optPar ')'
addrExpr ::= 'addr' '(' optInd expr optPar ')'
@@ -120,7 +121,7 @@ caseStmt ::= 'case' expr [':'] ('of' exprList ':' stmt)*
('elif' expr ':' stmt)*
['else' ':' stmt]
whileStmt ::= 'while' expr ':' stmt
forStmt ::= 'for' symbol (comma symbol)* 'in' expr ['..' expr] ':' stmt
forStmt ::= 'for' symbol (comma symbol)* 'in' expr ':' stmt
exceptList ::= [qualifiedIdent (comma qualifiedIdent)*]
tryStmt ::= 'try' ':' stmt

View File

@@ -346,29 +346,38 @@ notation:
``0B0_10001110100_0000101001000111101011101111111011000101001101001001'f64``
is approximately 1.72826e35 according to the IEEE floating point standard.
Operators
---------
In Nimrod one can define his own operators. An `operator`:idx: is any
combination of the following characters::
= + - * / < >
@ $ ~ & % |
! ? ^ . : \
These keywords are also operators:
``and or not xor shl shr div mod in notin is isnot``.
`=`:tok:, `:`:tok:, `::`:tok: are not available as general operators; they
are used for other notational purposes.
``*:`` is as a special case the two tokens `*`:tok: and `:`:tok:
(to support ``var v*: T``).
Other tokens
------------
The following strings denote other tokens::
( ) { } [ ] , ; [. .] {. .} (. .)
: = ^ .. `
`..`:tok: takes precedence over other tokens that contain a dot: `{..}`:tok: are
the three tokens `{`:tok:, `..`:tok:, `}`:tok: and not the two tokens
`{.`:tok:, `.}`:tok:.
In Nimrod one can define his own operators. An `operator`:idx: is any
combination of the following characters that is not listed above::
+ - * / < >
= @ $ ~ & %
! ? ^ . | \
These keywords are also operators:
``and or not xor shl shr div mod in notin is isnot``.
` ( ) { } [ ] , ; [. .] {. .} (. .)
The `slice`:idx: operator `..`:tok: takes precedence over other tokens that
contain a dot: `{..}`:tok: are the three tokens `{`:tok:, `..`:tok:, `}`:tok:
and not the two tokens `{.`:tok:, `.}`:tok:.
Syntax
@@ -378,7 +387,7 @@ This section lists Nimrod's standard syntax in ENBF. How the parser receives
indentation tokens is already described in the `Lexical Analysis`_ section.
Nimrod allows user-definable operators.
Binary operators have 8 different levels of precedence. For user-defined
Binary operators have 9 different levels of precedence. For user-defined
operators, the precedence depends on the first character the operator consists
of. All binary operators are left-associative, except binary operators starting
with (or only consisting of) ``^``.
@@ -386,14 +395,15 @@ with (or only consisting of) ``^``.
================ ============================================== ================== ===============
Precedence level Operators First characters Terminal symbol
================ ============================================== ================== ===============
7 (highest) ``$ ^`` OP7
6 ``* / div mod shl shr %`` ``* % \ /`` OP6
5 ``+ -`` ``+ ~ |`` OP5
4 ``&`` ``&`` OP4
3 ``== <= < >= > != in not_in is isnot`` ``= < > !`` OP3
2 ``and`` OP2
1 ``or xor`` OP1
0 (lowest) ``? @ ` : .`` OP0
9 (highest) ``$ ^`` OP9
8 ``* / div mod shl shr %`` ``* % \ /`` OP8
7 ``+ -`` ``+ ~ |`` OP7
6 ``&`` ``&`` OP6
5 ``..`` ``.`` OP5
4 ``== <= < >= > != in not_in is isnot not`` ``= < > !`` OP4
3 ``and`` OP3
2 ``or xor`` OP2
1 (lowest) `` @ : ? `` OP1
================ ============================================== ================== ===============
@@ -2948,7 +2958,11 @@ string expressions in general:
proc myImport(s: cstring) {.cdecl, importc, dynlib: getDllName().}
**Note**: Patterns like ``libtcl(|8.5|8.4).so`` are only supported in constant
strings, because they are precompiled.
strings, because they are precompiled.
**Note**: Passing variables to the ``dynlib`` pragma will fail at runtime
because of order of initialization problems.
Dynlib pragma for export
------------------------