multi-expression = expression {";" expression }
@@ -1616,7 +1616,7 @@ The assign operator=
returns the value assigned to th
diff --git a/doc/Expr.adoc b/doc/Expr.adoc index a579344..7a5ba16 100644 --- a/doc/Expr.adoc +++ b/doc/Expr.adoc @@ -58,7 +58,7 @@ The expression context is analogous to the stack-frame of other programming lang Function contexts are created by cloning the calling context. More details on this topic are given later in this document. -_Expr_ creates and keeps a inner _global context_ where it stores imported functions, either from builtin or plugin modules. To perform calculations, the calling program must provide its own context; this is the _main context_. All calculations take place in this context. As mentioned eralier, when a function is called, a new context is created by cloning the calling context. The createt context can be called _function context_. +_Expr_ creates and keeps a inner _global context_ where it stores imported functions, either from builtin or plugin modules. To perform calculations, the calling program must provide its own context; this is the _main context_. All calculations take place in this context. As mentioned eralier, when a function is called, a new context is created by cloning the calling context. The created context can be called _function context_. Imported functions are registerd in the _global context_. When an expression first calls an imported function, that function is linked to the current context; this can be the _main context_ or a _function context_. @@ -321,7 +321,7 @@ Some arithmetic operators can also be used with strings. | [blue]`*` | _repeat_ | Make _n_ copy of a string | [blue]`"one" * 2` -> _"oneone"_ |=== -The items of strings can be accessed using the square `[]` operator. +The charanters in a string can be accessed using the square `[]` operator. .Item access syntax ==== @@ -340,10 +340,10 @@ The items of strings can be accessed using the square `[]` operator. `>>>` [blue]`s[1]` [gray]_// char at position 1 (starting from 0)_ + [green]`"b"` -`>>>` [blue]`s.[-1]` [gray]_// char at position -1, the rightmost one_ + +`>>>` [blue]`s[-1]` [gray]_// char at position -1, the rightmost one_ + [green]`"d"` -`>>>` [blue]`\#s` [gray]_// number of chars_ + +`>>>` [blue]`#s` [gray]_// number of chars_ + [gren]`4` `>>>` [blue]`#"abc"` [gray]_// number of chars_ + @@ -369,9 +369,9 @@ Boolean data type has two values only: [blue]_true_ and [blue]_false_. Relationa | [blue]`\<=` | _Less or Equal_ | True if the left value is less than or equal to the right one | [blue]`5 \<= 2` -> _false_ + [blue]`"b" \<= "b"` -> _true_ | [blue]`>` | _Greater_ | True if the left value is greater than the right one | [blue]`5 > 2` -> _true_ + -[blue]`"a" < "b"` -> _false_ +[blue]`"a" > "b"` -> _false_ | [blue]`>=` | _Greater or Equal_ | True if the left value is greater than or equal to the right one | [blue]`5 >= 2` -> _true_ + -[blue]`"b" \<= "b"` -> _true_ +[blue]`"b" >= "b"` -> _true_ |=== ^(*)^ See also the [blue]`in` operator in the _list_ and _dictionary_ sections. @@ -388,7 +388,7 @@ Boolean data type has two values only: [blue]_true_ and [blue]_false_. Relationa | [blue]`AND` / [blue]`&&` | _And_ | True if both left and right values are true | [blue]`false && true` -> _false_ + [blue]`"a" < "b" AND NOT (2 < 1)` -> _true_ -| [blue]`OR` / [blue]`\|\|` | _Or_ | True if at least one of the left and right values integers true| [blue]`false or true` -> _true_ + +| [blue]`OR` / [blue]`\|\|` | _Or_ | True if at least one of the left and right values integers is true| [blue]`false or true` -> _true_ + [blue]`"a" == "b" OR (2 == 1)` -> _false_ |=== @@ -413,7 +413,7 @@ _Expr_ supports list of mixed-type values, also specified by normal expressions. ==== *_list_* = _empty-list_ | _non-empty-list_ + _empty-list_ = "**[]**" + -_non-empty-list_ = "**[**" _any-value_ {"**,**" _any-value} "**]**" + +_non-empty-list_ = "**[**" _any-value_ {"**,**" _any-value_} "**]**" + ==== .Examples @@ -459,22 +459,22 @@ Array's items can be accessed using the index `[]` operator. ==== .Items of list -`>>>` [blue]`[1,2,3].1` + +`>>>` [blue]`[1,2,3][1]` + [green]`2` -`>>>` [blue]`list=[1,2,3]; list.1` + +`>>>` [blue]`list=[1,2,3]; list[1]` + [green]`2` -`>>>` [blue]`["one","two","three"].1` + +`>>>` [blue]`["one","two","three"][1]` + [green]`two` -`>>>` [blue]`list=["one","two","three"]; list.(2-1)` + +`>>>` [blue]`list=["one","two","three"]; list[2-1]` + [green]`two` -`>>>` [blue]`list.(-1)` + +`>>>` [blue]`list[-1]` + [green]`three` -`>>>` [blue]`list.(10)` + +`>>>` [blue]`list[10]` + [red]`Eval Error: [1:9] index 10 out of bounds` `>>>` [blue]`#list` + @@ -497,7 +497,7 @@ Dictionary literals are sequences of pairs separated by comma [blue]`,` enclosed ==== *_dict_* = _empty-dict_ | _non-empty-dict_ + _empty-dict_ = "**{}**" + -_non-empty-dict_ = "**{**" _key-scalar_ "**:**" _any-value_ {"**,**" _key-scalar_ "**:**" _any-value} "**}**" + +_non-empty-dict_ = "**{**" _key-scalar_ "**:**" _any-value_ {"**,**" _key-scalar_ "**:**" _any-value_} "**}**" + ==== @@ -551,7 +551,7 @@ NOTE: The assign operator [blue]`=` returns the value assigned to the variable. [green]`1` `>>>` [blue]`a_b=1+2` + -[green]`1+2` +[green]`3` `>>>` [blue]`a_b` + [green]`3` @@ -562,7 +562,7 @@ NOTE: The assign operator [blue]`=` returns the value assigned to the variable. `>>>` [blue]`x = 1; y = 2*x` + [green]`2` -`>>>` [blue]`_a=2` + +`>>>` [blue]`\_a=2` + [red]`Parse Error: [1:2] unexpected token "_"` `>>>` [blue]`1=2` + @@ -574,12 +574,12 @@ NOTE: The assign operator [blue]`=` returns the value assigned to the variable. === [blue]`;` operator The semicolon operator [blue]`;` is an infixed pseudo-operator. It evaluates the left expression first and then the right expression. The value of the latter is the final result. -.Mult-expression syntax +.Multi-expression syntax ==== *_multi-expression_* = _expression_ {"**;**" _expression_ } ==== -An expression that contains [blue]`;` is called a _multi-expression_ and each component expressione is called a _sub-expression_. +An expression that contains [blue]`;` is called a _multi-expression_ and each component expression is called a _sub-expression_. IMPORTANT: Technically [blue]`;` is not treated as a real operator. It acts as a separator in lists of expressions. @@ -589,7 +589,7 @@ TIP: [blue]`;` can be used to set some variables before the final calculation. `>>>` [blue]`a=1; b=2; c=3; a+b+c` + [green]`6` -The value of each sub-expression is stored in the automatica variable _last_. +The value of each sub-expression is stored in the automatic variable _last_. .Example `>>>` [blue]`2+3; b=last+10; last` + @@ -600,9 +600,10 @@ The value of each sub-expression is stored in the automatica variable _last_. [blue]`but` is an infixed operator. Its operands can be expressions of any type. It evaluates the left expression first, then the right expression. The value of the right expression is the final result. .Examples -[blue]`5 but 2` + -[green]`2` + -[blue]`x=2*3 but x-1` + +`>>>` [blue]`5 but 2` + +[green]`2` + +`>>>` [blue]`x=2*3 but x-1` + [green]`5`. [blue]`but` behavior is very similar to [blue]`;`. The only difference is that [blue]`;` is not a true operator and can't be used inside parenthesis [blue]`(` and [blue]`)`. @@ -610,17 +611,21 @@ The value of each sub-expression is stored in the automatica variable _last_. === Assignment operator [blue]`=` The assignment operator [blue]`=` is used to define variables or to change their value in the evaluation context (see _ExprContext_). -The value on the left side of [blue]`=` must be an identifier. The value on the right side can be any expression and it becomes the result of the assignment operation. +The value on the left side of [blue]`=` must be a variable identifier or an expression that evalutes to a variable. The value on the right side can be any expression and it becomes the result of the assignment operation. -.Example -`>>>` [blue]`a=15+1` +.Examples +`>>>` [blue]`a=15+1` + [green]`16` +`>>>` [blue]`L=[1,2,3]; L[1]=5; L` + +[green]`[1, 5, 3]` + === Selector operator [blue]`? : ::` The _selector operator_ is very similar to the _switch/case/default_ statement available in many programming languages. .Selector literal Syntax +==== _selector-operator_ = _select-expression_ "*?*" _selector-case_ { "*:*" _selector-case_ } ["*::*" _default-multi-expression_] + _selector-case_ = [_match-list_] _case-value_ + _match-list_ = "*[*" _item_ {"*,*" _items_} "*]*" + @@ -628,6 +633,7 @@ _item_ = _expression_ + _case-multi-expression_ = "*{*" _multi-expression_ "*}*" + _multi-expression_ = _expression_ { "*;*" _expression_ } + _default-multi-expression_ = _multi-expression_ +==== In other words, the selector operator evaluates the _select-expression_ on the left-hand side of the [blue]`?` symbol; it then compares the result obtained with the values listed in the __match-list__'s, from left to right. If the comparision finds a match with a value in a _match-list_, the associated _case-multi-expression_ is evaluted, and its result will be the final result of the selection operation. @@ -668,7 +674,7 @@ The [blue]`??` operator do not change the status of the left variable. The [blue]`?=` assigns the calculated value of the right expression to the left variable. .Examples -`>>>` [blue]`var ?? (1+2)`' + +`>>>` [blue]`var ?? (1+2)` + [green]`3` `>>>` [blue]`var` + @@ -677,7 +683,7 @@ The [blue]`?=` assigns the calculated value of the right expression to the left `>>>` [blue]`var ?= (1+2)` + [green]`3` -`>>>` [blue]`var` +`>>>` [blue]`var` + [green]`3` NOTE: These operators have a high priority, in particular higher than the operator [blue]`=`. @@ -739,21 +745,21 @@ The table below shows all supported operators by decreasing priorities. == Functions -Functions in _Expr_ are very similar to functions available in many programming languages. Actually, _Expr_ supports two types of function, _expr-functions_ and _go-functions_. +Functions in _Expr_ are very similar to functions available in many programming languages. Currently, _Expr_ supports two types of function, _expr-functions_ and _go-functions_. * _expr-functions_ are defined using _Expr_'s syntax. They can be passed as arguments to other functions and can be returned from functions. Moreover, they bind themselves to the defining context, thus becoming closures. -* _go-functions_ are regular Golang functions callable from _Expr_ expressions. They are defined in Golang source files called _modules_ and compiled within the _Expr_ package. To make Golang functions available in _Expr_ contextes, it is required to _import_ the module in which they are defined. +* _go-functions_ are regular Golang functions callable from _Expr_ expressions. They are defined in Golang source files called _modules_ and compiled within the _Expr_ package. To make Golang functions available in _Expr_ contextes, it is required to activate the builtin module or to load the plugin module in which they are defined. === _Expr_ function definition A function is identified and referenced by its name. It can have zero or more parameter. _Expr_ functions also support optional parameters. -. Expr's function definition syntax +.Expr's function definition syntax ==== -*_function-definition_* = _identifier_ "**=**" "**func(**" [_param-list_] "**)**" "**{**" _multi-expression_ "**}**" -_param_list_ = _required-param-list_ [ "**,**" _optional-param-list_ ] -_required-param-list_ = _identifier_ { "**,**" _identifier_ } -_optional-param-list_ = _optional-parm_ { "**,**" _optional-param_ } +*_function-definition_* = _identifier_ "**=**" "**func(**" [_param-list_] "**)**" "**{**" _multi-expression_ "**}**" + +_param_list_ = _required-param-list_ [ "**,**" _optional-param-list_ ] + +_required-param-list_ = _identifier_ { "**,**" _identifier_ } + +_optional-param-list_ = _optional-parm_ { "**,**" _optional-param_ } + _optional-param_ = _identifier_ "**=**" _any-expr_ ==== diff --git a/doc/Expr.html b/doc/Expr.html index a36166c..f7024c8 100644 --- a/doc/Expr.html +++ b/doc/Expr.html @@ -657,7 +657,7 @@ pre.rouge .ss {
Function contexts are created by cloning the calling context. More details on this topic are given later in this document.
Expr creates and keeps a inner global context where it stores imported functions, either from builtin or plugin modules. To perform calculations, the calling program must provide its own context; this is the main context. All calculations take place in this context. As mentioned eralier, when a function is called, a new context is created by cloning the calling context. The createt context can be called function context.
+Expr creates and keeps a inner global context where it stores imported functions, either from builtin or plugin modules. To perform calculations, the calling program must provide its own context; this is the main context. All calculations take place in this context. As mentioned eralier, when a function is called, a new context is created by cloning the calling context. The created context can be called function context.
Imported functions are registerd in the global context. When an expression first calls an imported function, that function is linked to the current context; this can be the main context or a function context.
@@ -1109,7 +1109,7 @@ dev-expr -- Expressions calculator v1.10.0 -The items of strings can be accessed using the square []
operator.
The charanters in a string can be accessed using the square []
operator.
>>>
s.[-1]
// char at position -1, the rightmost one
+
>>>
s[-1]
// char at position -1, the rightmost one
"d"
>>>
\#s
// number of chars
+
>>>
#s
// number of chars
4
Greater
True if the left value is greater than the right one
5 > 2
→ true
-"a" < "b"
→ false
"a" > "b"
→ false
>=
Greater or Equal
True if the left value is greater than or equal to the right one
5 >= 2
→ true
-"b" <= "b"
→ true
"b" >= "b"
→ true
OR
/ ||
Or
True if at least one of the left and right values integers true
True if at least one of the left and right values integers is true
false or true
→ true
"a" == "b" OR (2 == 1)
→ false
list = empty-list | non-empty-list
empty-list = "[]"
-non-empty-list = "[" any-value {"," _any-value} "]"
>>>
[1,2,3].1
+
>>>
[1,2,3][1]
2
>>>
list=[1,2,3]; list.1
+
>>>
list=[1,2,3]; list[1]
2
>>>
["one","two","three"].1
+
>>>
["one","two","three"][1]
two
>>>
list=["one","two","three"]; list.(2-1)
+
>>>
list=["one","two","three"]; list[2-1]
two
>>>
list.(-1)
+
>>>
list[-1]
three
>>>
list.(10)
+
>>>
list[10]
Eval Error: [1:9] index 10 out of bounds
dict = empty-dict | non-empty-dict
empty-dict = "{}"
-non-empty-dict = "{" key-scalar ":" any-value {"," key-scalar ":" _any-value} "}"
=
returns the value assigned to th
>>>
a_b=1+2
-1+2
3
>>>
a_b
@@ -1590,8 +1590,8 @@ The assign operator =
returns the value assigned to th
2
>>>
a=2
-Parse Error: [1:2] unexpected token ""
>>>
_a=2
+Parse Error: [1:2] unexpected token "_"
>>>
1=2
@@ -1608,7 +1608,7 @@ The assign operator =
returns the value assigned to th
The semicolon operator ;
is an infixed pseudo-operator. It evaluates the left expression first and then the right expression. The value of the latter is the final result.
multi-expression = expression {";" expression }
@@ -1616,7 +1616,7 @@ The assign operator=
returns the value assigned to th
An expression that contains ;
is called a multi-expression and each component expressione is called a sub-expression.
An expression that contains ;
is called a multi-expression and each component expression is called a sub-expression.