Doc: more details on the syntax of the numbers, strings and boolean

This commit is contained in:
Celestino Amoroso 2024-05-16 07:11:20 +02:00
parent ca89931ca9
commit f0a152a17a
2 changed files with 141 additions and 79 deletions

View File

@ -22,7 +22,7 @@ Expressions calculator
toc::[] toc::[]
#TODO: Work in progress (last update on 2024/05/15, 10:00 p.m.)# #TODO: Work in progress (last update on 2024/05/16, 7:08 a.m.)#
== Expr == Expr
_Expr_ is a GO package capable of analysing, interpreting and calculating expressions. _Expr_ is a GO package capable of analysing, interpreting and calculating expressions.
@ -33,9 +33,9 @@ _Expr_ is a GO package capable of analysing, interpreting and calculating expres
image::expression-diagram.png[] image::expression-diagram.png[]
=== `dev-expr` test tool === `dev-expr` test tool
`dev-expr` is a simple program that can be used to evaluate expressions interactively. As its name suggests, it was created for testing purpose. In fact, beyond in additon to the automatic test suite based on the Go test framework, `dev-expr` provides an important aid for quickly testing of new features during their development. `dev-expr` is a simple program that can be used to evaluate expressions interactively. As its name suggests, it was created for testing purpose. In fact, in additon to the automatic verification test suite based on the Go test framework, `dev-expr` provides an important aid for quickly testing of new features during their development.
It cat work as a _REPL_, _**R**ead-**E**xecute-**P**rint-**L**oop_, or it can process expression acquired from files or standard input. `dev-expr` can work as a _REPL_, _**R**ead-**E**xecute-**P**rint-**L**oop_, or it can process expression acquired from files or standard input.
The program can be downloaded from https://git.portale-stac.it/go-pkg/-/packages/generic/dev-expr/[dev-expr]. The program can be downloaded from https://git.portale-stac.it/go-pkg/-/packages/generic/dev-expr/[dev-expr].
@ -46,19 +46,21 @@ Here are some examples of execution.
---- ----
# Assume the expr source directory. Type 'exit' or Ctrl+D to quit the program. # Assume the expr source directory. Type 'exit' or Ctrl+D to quit the program.
[user]$ tools/expr -- Expressions calculator v1.7.0,2024/05/08 (celestino.amoroso@portale-stac.it) [user]$ ./dev-expr
Type help to get the list of command. expr -- Expressions calculator v1.7.1(build 2),2024/05/16 (celestino.amoroso@portale-stac.it)
Based on the Expr package v0.10.0
Type help to get the list of available commands
See also https://git.portale-stac.it/go-pkg/expr/src/branch/main/README.adoc See also https://git.portale-stac.it/go-pkg/expr/src/branch/main/README.adoc
>>> help >>> help
--- REPL commands: --- REPL commands:
source -- Load a file as input
tty -- Enable/Disable ansi output <1>
base -- Set the integer output base: 2, 8, 10, or 16 base -- Set the integer output base: 2, 8, 10, or 16
exit -- Exit the program exit -- Exit the program
help -- Show command list help -- Show command list
ml -- Enable/Disable multi-line output ml -- Enable/Disable multi-line output
mods -- List builtin modules mods -- List builtin modules
source -- Load a file as input
tty -- Enable/Disable ansi output <1>
--- Command line options: --- Command line options:
-b <builtin> Import builtin modules. -b <builtin> Import builtin modules.
@ -80,9 +82,12 @@ Here are some examples of execution.
.REPL examples .REPL examples
[source,shell] [source,shell]
---- ----
[user]$ tools/expr -- Expressions calculator v1.6.1,2024/05/06 (celestino.amoroso@portale-stac.it) [user]$ ./dev-expr
Type help to get the list of command. expr -- Expressions calculator v1.7.1(build 2),2024/05/16 (celestino.amoroso@portale-stac.it)
Based on the Expr package v0.10.0
Type help to get the list of available commands
See also https://git.portale-stac.it/go-pkg/expr/src/branch/main/README.adoc See also https://git.portale-stac.it/go-pkg/expr/src/branch/main/README.adoc
>>> 2+3 >>> 2+3
5 5
>>> 2+3*(4-1.5) >>> 2+3*(4-1.5)
@ -166,6 +171,20 @@ _sign_ = "**+**" | "**-**" +
_dec-seq_ = _see-integer-literal-syntax_ _dec-seq_ = _see-integer-literal-syntax_
==== ====
.Examples
`>>>` [blue]`1.0` +
[green]`1` +
`>>>` [blue]`0.123` +
[green]`0.123` +
`>>>` [blue]`4.5e+3` +
[green]`4500` +
`>>>` [blue]`4.5E-33` +
[green]`4.5e-33` +
`>>>` [blue]`4.5E-3` +
[green]`0.0045` +
`>>>` [blue]`4.5E10` +
[green]`4.5e+10` +
.Arithmetic operators .Arithmetic operators
[cols="^1,^2,6,4"] [cols="^1,^2,6,4"]
@ -196,19 +215,19 @@ _digit-seq_ = _see-integer-literal-syntax_ +
// ---- // ----
`>>>` [blue]`1 | 2` + `>>>` [blue]`1 | 2` +
[green]`1|2` + [green]`1|2` +
`>>>` [blue]`4|6` + `>>>` [blue]`4|6` [gray]_// Fractions are always reduced to their lowest terms_ +
[green]`2|3` [gray]_Fractions are always reduced to their lowest terms_ + [green]`2|3` +
`>>>` [blue]`1|2 + 2|3` + `>>>` [blue]`1|2 + 2|3` +
[green]`7|6` + [green]`7|6` +
`>>>` [blue]`1|2 * 2|3` + `>>>` [blue]`1|2 * 2|3` +
[green]`1|3` + [green]`1|3` +
`>>>` [blue]`1|2 / 1|3` + `>>>` [blue]`1|2 / 1|3` +
[green]`3|2` + [green]`3|2` +
`>>>` [blue]`1|2 ./ 1|3` [gray]_Force decimal division_ + `>>>` [blue]`1|2 ./ 1|3` [gray]_// Force decimal division_ +
[green]`1.5` + [green]`1.5` +
`>>>` [blue]`-1|2` + `>>>` [blue]`-1|2` +
[green]`-1|2` + [green]`-1|2` +
`>>>` [blue]`1|-2` [gray]_Wrong sign specification_ + `>>>` [blue]`1|-2` [gray]_// Invalid sign specification_ +
[red]_Eval Error: [1:3] infix operator "|" requires two non-nil operands, got 1_ + [red]_Eval Error: [1:3] infix operator "|" requires two non-nil operands, got 1_ +
`>>>` [blue]`1|(-2)` + `>>>` [blue]`1|(-2)` +
[green]`-1|2` [green]`-1|2`
@ -226,7 +245,18 @@ Fractions can be used together with integers and floats in expressions.
=== Strings === Strings
Strings are character sequences enclosed between two double quote [blue]`"`. Example: [blue]`"I'm a string"`. Strings are character sequences enclosed between two double quote [blue]`"`.
.Examples
`>>>` [blue]`"I'm a string"` +
[green]`I'm a string` +
`>>>` [blue]`"123abc?!"` +
[green]`123abc?!` +
`>>>` [blue]`"123\nabc"` +
[green]`123` +
[green]`abc` +
`>>>` [blue]`"123\tabc"` +
[green]`123{nbsp}{nbsp}{nbsp}{nbsp}abc`
Some arithmetic operators can also be used with strings. Some arithmetic operators can also be used with strings.
@ -244,10 +274,9 @@ Some arithmetic operators can also be used with strings.
The items of strings can be accessed using the dot `.` operator. The items of strings can be accessed using the dot `.` operator.
.Item access syntax .Item access syntax
[source,bnf] ====
---- _item_ = _string-expr_ "**.**" _integer-expr_
<item> ::= <string-expr>"."<index-expr> ====
----
.String examples .String examples
`>>>` [blue]`s="abc"` [gray]_assign the string to variable s_ + `>>>` [blue]`s="abc"` [gray]_assign the string to variable s_ +
@ -262,26 +291,25 @@ The items of strings can be accessed using the dot `.` operator.
[green]`3` + [green]`3` +
=== Boolean === Boolean
Boolean data type has two values only: _true_ and _false_. Relational and Boolean expressions produce Boolean values. Boolean data type has two values only: [blue]_true_ and [blue]_false_. Relational and boolean expressions result in boolean values.
.Relational operators .Relational operators
[cols="^1,^2,6,4"] [cols="^1,^2,6,4"]
|=== |===
| Symbol | Operation | Description | Examples | Symbol | Operation | Description | Examples
| [blue]`==` | _Equal_ | True if the left value is equal to the right one | [blue]`5 == 2` _[false]_ + | [blue]`==` | _Equal_ | True if the left value is equal to the right one | [blue]`5 == 2` -> _false_ +
[blue]`"a" == "a"` _[true]_ [blue]`"a" == "a"` -> _true_
| [blue]`!=` | _Not Equal_ | True if the left value is NOT equal to the right one | [blue]`5 != 2` _[true]_ + | [blue]`!=` | _Not Equal_ | True if the left value is NOT equal to the right one | [blue]`5 != 2` -> _true_ +
[blue]`"a" != "a"` _[false]_ [blue]`"a" != "a"` -> _false_
| [blue]`<` | _Less_ | True if the left value is less than the right one | [blue]`5 < 2` _[false]_ + | [blue]`<` | _Less_ | True if the left value is less than the right one | [blue]`5 < 2` -> _false_ +
[blue]`"a" < "b"` _[true]_ [blue]`"a" < "b"` -> _true_
| [blue]`\<=` | _Less or Equal_ | True if the left value is less than or equal to the right one | [blue]`5 \<= 2` _[false]_ + | [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]`"b" \<= "b"` -> _true_
| [blue]`>` | _Greater_ | True if the left value is greater than the right one | [blue]`5 > 2` _[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]`>=` | _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_
|=== |===
@ -290,19 +318,19 @@ Boolean data type has two values only: _true_ and _false_. Relational and Boolea
|=== |===
| Symbol | Operation | Description | Examples | Symbol | Operation | Description | Examples
| [blue]`NOT` | _Not_ | True if the right value is false | [blue]`NOT true` _[false]_ + | [blue]`NOT` | _Not_ | True if the right value is false | [blue]`NOT true` -> _false_ +
[blue]`NOT (2 < 1)` _[true]_ [blue]`NOT (2 < 1)` -> _true_
| [blue]`AND` / [blue]`&&` | _And_ | True if both left and right values are true | [blue]`false && true` _[false]_ + | [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]`"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 true| [blue]`false or true` -> _true_ +
[blue]`"a" == "b" OR (2 == 1)` _[false]_ [blue]`"a" == "b" OR (2 == 1)` -> _false_
|=== |===
[CAUTION] [CAUTION]
==== ====
Currently, boolean operations are evaluated using _short cut evaluation_. This means that, if the left expression of operators [blue]`and` and [blue]`or` is sufficient to establish the result of the whole operation, the right expression would not evaluated at all. Currently, boolean operations are evaluated using _short cut evaluation_. This means that, if the left expression of the [blue]`and` and [blue]`or` operators is sufficient to establish the result of the whole operation, the right expression would not evaluated at all.
.Example .Example
[source,go] [source,go]

View File

@ -584,7 +584,7 @@ pre.rouge .ss {
<div class="sectionbody"> <div class="sectionbody">
<!-- toc disabled --> <!-- toc disabled -->
<div class="paragraph"> <div class="paragraph">
<p><mark>TODO: Work in progress (last update on 2024/05/15, 10:00 p.m.)</mark></p> <p><mark>TODO: Work in progress (last update on 2024/05/16, 7:08 a.m.)</mark></p>
</div> </div>
</div> </div>
</div> </div>
@ -608,10 +608,10 @@ pre.rouge .ss {
<div class="sect2"> <div class="sect2">
<h3 id="_dev_expr_test_tool"><a class="anchor" href="#_dev_expr_test_tool"></a><a class="link" href="#_dev_expr_test_tool">1.2. <code>dev-expr</code> test tool</a></h3> <h3 id="_dev_expr_test_tool"><a class="anchor" href="#_dev_expr_test_tool"></a><a class="link" href="#_dev_expr_test_tool">1.2. <code>dev-expr</code> test tool</a></h3>
<div class="paragraph"> <div class="paragraph">
<p><code>dev-expr</code> is a simple program that can be used to evaluate expressions interactively. As its name suggests, it was created for testing purpose. In fact, beyond in additon to the automatic test suite based on the Go test framework, <code>dev-expr</code> provides an important aid for quickly testing of new features during their development.</p> <p><code>dev-expr</code> is a simple program that can be used to evaluate expressions interactively. As its name suggests, it was created for testing purpose. In fact, in additon to the automatic verification test suite based on the Go test framework, <code>dev-expr</code> provides an important aid for quickly testing of new features during their development.</p>
</div> </div>
<div class="paragraph"> <div class="paragraph">
<p>It cat work as a <em>REPL</em>, <em><strong>R</strong>ead-<strong>E</strong>xecute-<strong>P</strong>rint-<strong>L</strong>oop</em>, or it can process expression acquired from files or standard input.</p> <p><code>dev-expr</code> can work as a <em>REPL</em>, <em><strong>R</strong>ead-<strong>E</strong>xecute-<strong>P</strong>rint-<strong>L</strong>oop</em>, or it can process expression acquired from files or standard input.</p>
</div> </div>
<div class="paragraph"> <div class="paragraph">
<p>The program can be downloaded from <a href="https://git.portale-stac.it/go-pkg/-/packages/generic/dev-expr/">dev-expr</a>.</p> <p>The program can be downloaded from <a href="https://git.portale-stac.it/go-pkg/-/packages/generic/dev-expr/">dev-expr</a>.</p>
@ -624,19 +624,21 @@ pre.rouge .ss {
<div class="content"> <div class="content">
<pre class="rouge highlight"><code data-lang="shell"><span class="c"># Assume the expr source directory. Type 'exit' or Ctrl+D to quit the program.</span> <pre class="rouge highlight"><code data-lang="shell"><span class="c"># Assume the expr source directory. Type 'exit' or Ctrl+D to quit the program.</span>
<span class="o">[</span>user]<span class="nv">$ </span>tools/expr <span class="nt">--</span> Expressions calculator v1.7.0,2024/05/08 <span class="o">(</span>celestino.amoroso@portale-stac.it<span class="o">)</span> <span class="o">[</span>user]<span class="nv">$ </span>./dev-expr
Type <span class="nb">help </span>to get the list of command. <span class="nb">expr</span> <span class="nt">--</span> Expressions calculator v1.7.1<span class="o">(</span>build 2<span class="o">)</span>,2024/05/16 <span class="o">(</span>celestino.amoroso@portale-stac.it<span class="o">)</span>
Based on the Expr package v0.10.0
Type <span class="nb">help </span>to get the list of available commands
See also https://git.portale-stac.it/go-pkg/expr/src/branch/main/README.adoc See also https://git.portale-stac.it/go-pkg/expr/src/branch/main/README.adoc
<span class="o">&gt;&gt;&gt;</span> <span class="nb">help</span> <span class="o">&gt;&gt;&gt;</span> <span class="nb">help</span>
<span class="nt">---</span> REPL commands: <span class="nt">---</span> REPL commands:
<span class="nb">source</span> <span class="nt">--</span> Load a file as input
<span class="nb">tty</span> <span class="nt">--</span> Enable/Disable ansi output <i class="conum" data-value="1"></i><b>(1)</b>
base <span class="nt">--</span> Set the integer output base: 2, 8, 10, or 16 base <span class="nt">--</span> Set the integer output base: 2, 8, 10, or 16
<span class="nb">exit</span> <span class="nt">--</span> Exit the program <span class="nb">exit</span> <span class="nt">--</span> Exit the program
<span class="nb">help</span> <span class="nt">--</span> Show <span class="nb">command </span>list <span class="nb">help</span> <span class="nt">--</span> Show <span class="nb">command </span>list
ml <span class="nt">--</span> Enable/Disable multi-line output ml <span class="nt">--</span> Enable/Disable multi-line output
mods <span class="nt">--</span> List <span class="nb">builtin </span>modules mods <span class="nt">--</span> List <span class="nb">builtin </span>modules
<span class="nb">source</span> <span class="nt">--</span> Load a file as input
<span class="nb">tty</span> <span class="nt">--</span> Enable/Disable ansi output <i class="conum" data-value="1"></i><b>(1)</b>
<span class="nt">---</span> Command line options: <span class="nt">---</span> Command line options:
<span class="nt">-b</span> &lt;<span class="nb">builtin</span><span class="o">&gt;</span> Import <span class="nb">builtin </span>modules. <span class="nt">-b</span> &lt;<span class="nb">builtin</span><span class="o">&gt;</span> Import <span class="nb">builtin </span>modules.
@ -667,9 +669,12 @@ pre.rouge .ss {
<div class="listingblock"> <div class="listingblock">
<div class="title">REPL examples</div> <div class="title">REPL examples</div>
<div class="content"> <div class="content">
<pre class="rouge highlight"><code data-lang="shell"><span class="o">[</span>user]<span class="nv">$ </span>tools/expr <span class="nt">--</span> Expressions calculator v1.6.1,2024/05/06 <span class="o">(</span>celestino.amoroso@portale-stac.it<span class="o">)</span> <pre class="rouge highlight"><code data-lang="shell"><span class="o">[</span>user]<span class="nv">$ </span>./dev-expr
Type <span class="nb">help </span>to get the list of command. <span class="nb">expr</span> <span class="nt">--</span> Expressions calculator v1.7.1<span class="o">(</span>build 2<span class="o">)</span>,2024/05/16 <span class="o">(</span>celestino.amoroso@portale-stac.it<span class="o">)</span>
Based on the Expr package v0.10.0
Type <span class="nb">help </span>to get the list of available commands
See also https://git.portale-stac.it/go-pkg/expr/src/branch/main/README.adoc See also https://git.portale-stac.it/go-pkg/expr/src/branch/main/README.adoc
<span class="o">&gt;&gt;&gt;</span> 2+3 <span class="o">&gt;&gt;&gt;</span> 2+3
5 5
<span class="o">&gt;&gt;&gt;</span> 2+3<span class="k">*</span><span class="o">(</span>4-1.5<span class="o">)</span> <span class="o">&gt;&gt;&gt;</span> 2+3<span class="k">*</span><span class="o">(</span>4-1.5<span class="o">)</span>
@ -836,6 +841,21 @@ pre.rouge .ss {
</div> </div>
</div> </div>
</div> </div>
<div class="paragraph">
<div class="title">Examples</div>
<p><code>&gt;&gt;&gt;</code> <code class="blue">1.0</code><br>
<code class="green">1</code><br>
<code>&gt;&gt;&gt;</code> <code class="blue">0.123</code><br>
<code class="green">0.123</code><br>
<code>&gt;&gt;&gt;</code> <code class="blue">4.5e+3</code><br>
<code class="green">4500</code><br>
<code>&gt;&gt;&gt;</code> <code class="blue">4.5E-33</code><br>
<code class="green">4.5e-33</code><br>
<code>&gt;&gt;&gt;</code> <code class="blue">4.5E-3</code><br>
<code class="green">0.0045</code><br>
<code>&gt;&gt;&gt;</code> <code class="blue">4.5E10</code><br>
<code class="green">4.5e+10</code><br></p>
</div>
<table class="tableblock frame-all grid-all stretch"> <table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 2. Arithmetic operators</caption> <caption class="title">Table 2. Arithmetic operators</caption>
<colgroup> <colgroup>
@ -906,19 +926,19 @@ pre.rouge .ss {
<div class="title">Examples</div> <div class="title">Examples</div>
<p><code>&gt;&gt;&gt;</code> <code class="blue">1 | 2</code><br> <p><code>&gt;&gt;&gt;</code> <code class="blue">1 | 2</code><br>
<code class="green">1|2</code><br> <code class="green">1|2</code><br>
<code>&gt;&gt;&gt;</code> <code class="blue">4|6</code><br> <code>&gt;&gt;&gt;</code> <code class="blue">4|6</code> <em class="gray">// Fractions are always reduced to their lowest terms</em><br>
<code class="green">2|3</code> <em class="gray">Fractions are always reduced to their lowest terms</em><br> <code class="green">2|3</code><br>
<code>&gt;&gt;&gt;</code> <code class="blue">1|2 + 2|3</code><br> <code>&gt;&gt;&gt;</code> <code class="blue">1|2 + 2|3</code><br>
<code class="green">7|6</code><br> <code class="green">7|6</code><br>
<code>&gt;&gt;&gt;</code> <code class="blue">1|2 * 2|3</code><br> <code>&gt;&gt;&gt;</code> <code class="blue">1|2 * 2|3</code><br>
<code class="green">1|3</code><br> <code class="green">1|3</code><br>
<code>&gt;&gt;&gt;</code> <code class="blue">1|2 / 1|3</code><br> <code>&gt;&gt;&gt;</code> <code class="blue">1|2 / 1|3</code><br>
<code class="green">3|2</code><br> <code class="green">3|2</code><br>
<code>&gt;&gt;&gt;</code> <code class="blue">1|2 ./ 1|3</code> <em class="gray">Force decimal division</em><br> <code>&gt;&gt;&gt;</code> <code class="blue">1|2 ./ 1|3</code> <em class="gray">// Force decimal division</em><br>
<code class="green">1.5</code><br> <code class="green">1.5</code><br>
<code>&gt;&gt;&gt;</code> <code class="blue">-1|2</code><br> <code>&gt;&gt;&gt;</code> <code class="blue">-1|2</code><br>
<code class="green">-1|2</code><br> <code class="green">-1|2</code><br>
<code>&gt;&gt;&gt;</code> <code class="blue">1|-2</code> <em class="gray">Wrong sign specification</em><br> <code>&gt;&gt;&gt;</code> <code class="blue">1|-2</code> <em class="gray">// Invalid sign specification</em><br>
<em class="red">Eval Error: [1:3] infix operator "|" requires two non-nil operands, got 1</em><br> <em class="red">Eval Error: [1:3] infix operator "|" requires two non-nil operands, got 1</em><br>
<code>&gt;&gt;&gt;</code> <code class="blue">1|(-2)</code><br> <code>&gt;&gt;&gt;</code> <code class="blue">1|(-2)</code><br>
<code class="green">-1|2</code></p> <code class="green">-1|2</code></p>
@ -939,7 +959,19 @@ pre.rouge .ss {
<div class="sect2"> <div class="sect2">
<h3 id="_strings"><a class="anchor" href="#_strings"></a><a class="link" href="#_strings">2.2. Strings</a></h3> <h3 id="_strings"><a class="anchor" href="#_strings"></a><a class="link" href="#_strings">2.2. Strings</a></h3>
<div class="paragraph"> <div class="paragraph">
<p>Strings are character sequences enclosed between two double quote <code class="blue">"</code>. Example: <code class="blue">"I&#8217;m a string"</code>.</p> <p>Strings are character sequences enclosed between two double quote <code class="blue">"</code>.</p>
</div>
<div class="paragraph">
<div class="title">Examples</div>
<p><code>&gt;&gt;&gt;</code> <code class="blue">"I&#8217;m a string"</code><br>
<code class="green">I&#8217;m a string</code><br>
<code>&gt;&gt;&gt;</code> <code class="blue">"123abc?!"</code><br>
<code class="green">123abc?!</code><br>
<code>&gt;&gt;&gt;</code> <code class="blue">"123\nabc"</code><br>
<code class="green">123</code><br>
<code class="green">abc</code><br>
<code>&gt;&gt;&gt;</code> <code class="blue">"123\tabc"</code><br>
<code class="green">123&#160;&#160;&#160;&#160;abc</code></p>
</div> </div>
<div class="paragraph"> <div class="paragraph">
<p>Some arithmetic operators can also be used with strings.</p> <p>Some arithmetic operators can also be used with strings.</p>
@ -979,10 +1011,12 @@ pre.rouge .ss {
<div class="paragraph"> <div class="paragraph">
<p>The items of strings can be accessed using the dot <code>.</code> operator.</p> <p>The items of strings can be accessed using the dot <code>.</code> operator.</p>
</div> </div>
<div class="listingblock"> <div class="exampleblock">
<div class="title">Item access syntax</div> <div class="title">Example 4. Item access syntax</div>
<div class="content"> <div class="content">
<pre class="rouge highlight"><code data-lang="bnf">&lt;item&gt; ::= &lt;string-expr&gt;"."&lt;index-expr&gt;</code></pre> <div class="paragraph">
<p><em>item</em> = <em>string-expr</em> "<strong>.</strong>" <em>integer-expr</em></p>
</div>
</div> </div>
</div> </div>
<div class="paragraph"> <div class="paragraph">
@ -1002,7 +1036,7 @@ pre.rouge .ss {
<div class="sect2"> <div class="sect2">
<h3 id="_boolean"><a class="anchor" href="#_boolean"></a><a class="link" href="#_boolean">2.3. Boolean</a></h3> <h3 id="_boolean"><a class="anchor" href="#_boolean"></a><a class="link" href="#_boolean">2.3. Boolean</a></h3>
<div class="paragraph"> <div class="paragraph">
<p>Boolean data type has two values only: <em>true</em> and <em>false</em>. Relational and Boolean expressions produce Boolean values.</p> <p>Boolean data type has two values only: <em class="blue">true</em> and <em class="blue">false</em>. Relational and boolean expressions result in boolean values.</p>
</div> </div>
<table class="tableblock frame-all grid-all stretch"> <table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 4. Relational operators</caption> <caption class="title">Table 4. Relational operators</caption>
@ -1025,43 +1059,43 @@ pre.rouge .ss {
<td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">==</code></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">==</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><em>Equal</em></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><em>Equal</em></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">True if the left value is equal to the right one</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">True if the left value is equal to the right one</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">5 == 2</code> <em>[false]</em><br> <td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">5 == 2</code> &#8594; <em>false</em><br>
<code class="blue">"a" == "a"</code> <em>[true]</em></p></td> <code class="blue">"a" == "a"</code> &#8594; <em>true</em></p></td>
</tr> </tr>
<tr> <tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">!=</code></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">!=</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><em>Not Equal</em></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><em>Not Equal</em></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">True if the left value is NOT equal to the right one</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">True if the left value is NOT equal to the right one</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">5 != 2</code> <em>[true]</em><br> <td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">5 != 2</code> &#8594; <em>true</em><br>
<code class="blue">"a" != "a"</code> <em>[false]</em></p></td> <code class="blue">"a" != "a"</code> &#8594; <em>false</em></p></td>
</tr> </tr>
<tr> <tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">&lt;</code></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">&lt;</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><em>Less</em></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><em>Less</em></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">True if the left value is less than the right one</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">True if the left value is less than the right one</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">5 &lt; 2</code> <em>[false]</em><br> <td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">5 &lt; 2</code> &#8594; <em>false</em><br>
<code class="blue">"a" &lt; "b"</code> <em>[true]</em></p></td> <code class="blue">"a" &lt; "b"</code> &#8594; <em>true</em></p></td>
</tr> </tr>
<tr> <tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">&lt;=</code></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">&lt;=</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><em>Less or Equal</em></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><em>Less or Equal</em></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">True if the left value is less than or equal to the right one</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">True if the left value is less than or equal to the right one</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">5 &lt;= 2</code> <em>[false]</em><br> <td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">5 &lt;= 2</code> &#8594; <em>false</em><br>
<code class="blue">"b" &lt;= "b"</code> <em>[true]</em></p></td> <code class="blue">"b" &lt;= "b"</code> &#8594; <em>true</em></p></td>
</tr> </tr>
<tr> <tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">&gt;</code></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">&gt;</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><em>Greater</em></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><em>Greater</em></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">True if the left value is greater than the right one</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">True if the left value is greater than the right one</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">5 &gt; 2</code> <em>[true]</em><br> <td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">5 &gt; 2</code> &#8594; <em>true</em><br>
<code class="blue">"a" &lt; "b"</code> <em>[false]</em></p></td> <code class="blue">"a" &lt; "b"</code> &#8594; <em>false</em></p></td>
</tr> </tr>
<tr> <tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">&gt;=</code></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">&gt;=</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><em>Greater or Equal</em></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><em>Greater or Equal</em></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">True if the left value is greater than or equal to the right one</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">True if the left value is greater than or equal to the right one</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">5 &gt;= 2</code> <em>[true]</em><br> <td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">5 &gt;= 2</code> &#8594; <em>true</em><br>
<code class="blue">"b" &lt;= "b"</code> <em>[true]</em></p></td> <code class="blue">"b" &lt;= "b"</code> &#8594; <em>true</em></p></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -1086,22 +1120,22 @@ pre.rouge .ss {
<td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">NOT</code></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">NOT</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><em>Not</em></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><em>Not</em></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">True if the right value is false</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">True if the right value is false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">NOT true</code> <em>[false]</em><br> <td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">NOT true</code> &#8594; <em>false</em><br>
<code class="blue">NOT (2 &lt; 1)</code> <em>[true]</em></p></td> <code class="blue">NOT (2 &lt; 1)</code> &#8594; <em>true</em></p></td>
</tr> </tr>
<tr> <tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">AND</code> / <code class="blue">&amp;&amp;</code></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">AND</code> / <code class="blue">&amp;&amp;</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><em>And</em></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><em>And</em></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">True if both left and right values are true</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">True if both left and right values are true</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">false &amp;&amp; true</code> <em>[false]</em><br> <td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">false &amp;&amp; true</code> &#8594; <em>false</em><br>
<code class="blue">"a" &lt; "b" AND NOT (2 &lt; 1)</code> <em>[true]</em></p></td> <code class="blue">"a" &lt; "b" AND NOT (2 &lt; 1)</code> &#8594; <em>true</em></p></td>
</tr> </tr>
<tr> <tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">OR</code> / <code class="blue">||</code></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><code class="blue">OR</code> / <code class="blue">||</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock"><em>Or</em></p></td> <td class="tableblock halign-center valign-top"><p class="tableblock"><em>Or</em></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">True if at least one of the left and right values integers true</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">True if at least one of the left and right values integers true</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">false or true</code> <em>[true]</em><br> <td class="tableblock halign-left valign-top"><p class="tableblock"><code class="blue">false or true</code> &#8594; <em>true</em><br>
<code class="blue">"a" == "b" OR (2 == 1)</code> <em>[false]</em></p></td> <code class="blue">"a" == "b" OR (2 == 1)</code> &#8594; <em>false</em></p></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -1113,7 +1147,7 @@ pre.rouge .ss {
</td> </td>
<td class="content"> <td class="content">
<div class="paragraph"> <div class="paragraph">
<p>Currently, boolean operations are evaluated using <em>short cut evaluation</em>. This means that, if the left expression of operators <code class="blue">and</code> and <code class="blue">or</code> is sufficient to establish the result of the whole operation, the right expression would not evaluated at all.</p> <p>Currently, boolean operations are evaluated using <em>short cut evaluation</em>. This means that, if the left expression of the <code class="blue">and</code> and <code class="blue">or</code> operators is sufficient to establish the result of the whole operation, the right expression would not evaluated at all.</p>
</div> </div>
<div class="listingblock"> <div class="listingblock">
<div class="title">Example</div> <div class="title">Example</div>
@ -1627,7 +1661,7 @@ The value on the left side of <code class="blue">=</code> must be an identifier.
</div> </div>
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Last updated 2024-05-15 22:00:00 +0200 Last updated 2024-05-16 07:10:03 +0200
</div> </div>
</div> </div>
</body> </body>