From 4755774edd8f29c4b35a6acdd1e1dd8f77000a12 Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Thu, 12 Sep 2024 06:57:43 +0200 Subject: [PATCH] Doc: Fixed a lot of typos --- doc/Expr.adoc | 76 ++++++++++++++++++++++------------------- doc/Expr.html | 94 +++++++++++++++++++++++++++------------------------ 2 files changed, 90 insertions(+), 80 deletions(-) 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.

Example 4. Item access syntax
@@ -1137,11 +1137,11 @@ dev-expr -- Expressions calculator v1.10.0"b"

-

>>> 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

@@ -1208,14 +1208,14 @@ dev-expr -- Expressions calculator v1.10.0

Greater

True if the left value is greater than the right one

5 > 2true
-"a" < "b"false

+"a" > "b"false

>=

Greater or Equal

True if the left value is greater than or equal to the right one

5 >= 2true
-"b" <= "b"true

+"b" >= "b"true

@@ -1256,7 +1256,7 @@ dev-expr -- Expressions calculator v1.10.0

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 truetrue
"a" == "b" OR (2 == 1)false

@@ -1314,7 +1314,7 @@ dev-expr -- Expressions calculator v1.10.0

list = empty-list | non-empty-list
empty-list = "[]"
-non-empty-list = "[" any-value {"," _any-value} "]"

+non-empty-list = "[" any-value {"," any-value} "]"

@@ -1416,27 +1416,27 @@ dev-expr -- Expressions calculator v1.10.0
Items of list
-

>>> [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

@@ -1466,7 +1466,7 @@ dev-expr -- Expressions calculator v1.10.0

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} "}"

@@ -1575,7 +1575,7 @@ The assign operator = 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.

-
Example 12. Mult-expression syntax
+
Example 12. Multi-expression syntax

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.

@@ -1648,7 +1648,7 @@ Technically ; is not treated as a real operator. It ac 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
@@ -1663,9 +1663,11 @@ Technically ; is not treated as a real operator. It ac
Examples
-

5 but 2
-2
-x=2*3 but x-1
+

>>> 5 but 2
+2

+
+
+

>>> x=2*3 but x-1
5.

@@ -1678,21 +1680,27 @@ Technically ; is not treated as a real operator. It ac

The assignment operator = is used to define variables or to change their value in the evaluation context (see ExprContext).

-

The value on the left side of = 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 = 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
-

>>> a=15+1 +

Examples
+

>>> a=15+1
16

+
+

>>> L=[1,2,3]; L[1]=5; L
+[1, 5, 3]

+

4.4. Selector operator ? : ::

The selector operator is very similar to the switch/case/default statement available in many programming languages.

+
+
Example 13. Selector literal Syntax
+
-
Selector literal Syntax

selector-operator = select-expression "?" selector-case { ":" selector-case } ["::" default-multi-expression]
selector-case = [match-list] case-value
match-list = "[" item {"," items} "]"
@@ -1701,6 +1709,8 @@ Technically ; is not treated as a real operator. It ac 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 ? 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.

@@ -1765,8 +1775,8 @@ If the left variable is defined, the right expression is not evaluated at all.
Examples
-

>>> var ?? (1+2)’
-[green]`3

+

>>> var ?? (1+2)
+3

>>> var
@@ -1777,7 +1787,7 @@ If the left variable is defined, the right expression is not evaluated at all. 3

-

>>> var +

>>> var
3

@@ -2106,7 +2116,7 @@ These operators have a high priority, in particular higher than the operator 6. 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.

    @@ -2114,7 +2124,7 @@ These operators have a high priority, in particular higher than the operator 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.

@@ -2123,20 +2133,14 @@ These operators have a high priority, in particular higher than the operator

A function is identified and referenced by its name. It can have zero or more parameter. Expr functions also support optional parameters.

-
-
    -
  1. -

    Expr’s function definition syntax

    -
  2. -
-
+
Example 14. 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

@@ -2200,7 +2204,7 @@ These operators have a high priority, in particular higher than the operator