Tutorial



English Script Programming Tutorial

Introduction

High Level Language

The English Script is a high level programming language, much higher than any of the traditional programming languages around there today (like C/C++, JavaScript, Lisp). It means that the English Script language is designed for implementing applications for processing and solving of high level tasks and problems. It provides means for describing abstract things, their relations, logic related to them and procedural means to interact with them. In short, ES is for implementing an Artificial Intelligence.

It is not superior to other programming languages, instead it is just different and meant for different kind of applications than traditional programming languages.

It also means that it may not be optimum for low level tasks like heavy number crunching or massive bit manipulations, there some lower level languages, like C/C++, perform a lot better. Therefore you should mix ES with other programming languages to implement complete applications.

English as a Reference

The ES programming language has adopted the basic structure and nature from the natural English language. However it is not following or supporting all features of the English language, instead it is a sub-set of it and have more strict rules how to use it. In contrast to natural languages it does not permit any mistakes (e.g. typing mistakes) in the implemented piece of code.

Deterministic

The ES is a deterministic programming language, which means that it is expected that any implemented application implemented with it provides always repeatable and deterministic results, no matter how many times and when the application is executed.

Therefore no statistical methods or other non-deterministic methods are used in the ES language.

Human-Computer Interaction

As such ES is not very usable for implementing normal (error prone) Human-Computer Interaction applications. Instead the human interacting with the application (implemented with ES language) must ensure correct syntax in provided input and expect the application to non-tolerate any errors in the input.

Also most of the time the implemented application knows only very strict amount of words and knowledge about some specifically selected application domain. In practice the human user of the application needs to know what the application knows and what it is capable to do.

Interpreted Language

The English Script language is an interpreted language, meaning that the source code is first compiled to a “binary” format that can then later be executed using an interpreter.

When application is being executed it is also possible to compile any received text input (e.g. from a file, a socket etc.) on-the-fly and execute it after that. It is possible since the ES compiler is incorporated to the ES runtime environment.

One-pass Compiler

The ES compiler processes the ES source code as it is read from e.g. a file. This means that all referenced things in a source code must be defined before they are used. E.g. to define meaning of a “car” word before using it:

"car" is a noun.
A car.

Language Structure and Format

Format

English Script programming language is written as plain 8-bit ASCII text, using any ASCII text editor. All code is written as a sequence of sentences, e.g.

English Script is a programming language.

Strings

A string is a number of characters, encapsulated with two double quote characters (“). E.g.

"ABC"
"U.S.A"
"Finland"
"1234567890"
"Hello World!"
"http://www.englishscript.com"

In ES all strings are in UTF-8 format. This means that strings can contain also non 8-bit ASCII characters (e.g. Chinese characters). Also it is possible to add single characters using a backslash char (‘\’) and a following number. ES converts such automatically to UTF-8 format internally. E.g.

\NNN            a byte with octal value NNN (1 to 3 digits)
\xHH            a byte with hexadecimal value (2 digits)
\uHHHH          a Unicode character (ISO/IEC 10646) with hexadecimal value (4 digits)
\UHHHHHHHH      a Unicode character with hexadecimal value (8 digits)

e.g.

"\105\123"     a string "ES"
"\x45\x53"     a string "ES"
"\u2318"       a unicode character U+2318 i.e. ⌘
"\u2614\uFE0F" a unicode variation sequence of U+2614 and U+FE0F i.e. ☔️
"\U0001F61B"   a unicode character U+1F61B i.e. 😛

A string can include also the double quote character itself by adding a backslash (\) character in front of it, e.g.

"24\" long"
"He said \"Hi!\""
"Double quote \" inside a string"

The contents of the string are not being interpreted by the ES compiler, except for the following encodings.

\n    Replaced with a line feed character.
\r    Replaced with a carriage return character.
\t    Replaced with a tabulator character.
\\    Replaced with a single '\' character.

A string can also be given as multiple lines, e.g.

The code is
    "For each of my cars.\n
    \    Drive the car.\n
     End.".

Words

To start programming you need to first define the words you are going to use in your application and what are their types. This information is used by the ES compiler to correctly analyze your application code. There are the following word types available:

noun           E.g. "car", "boat", "man", "men", "computers".
verb           E.g. "is", "drive", "sit", "eat".
adjective      E.g. "big", "small", "blue", "pretty".
adverb         E.g. "very".
preposition    E.g. "to", "from", "at", "on".

Nouns

Nouns are subjects like “car”, “dog”, “doctor” etc. And to define a noun using ES:

"car" is a noun.

Normally also the plural form of the noun word should be defined at the same time:

"car" and "cars" are nouns.

Then the relations between them are defined as follows:

The noun "cars" is the plural form of the noun "car".

Also uncountable nouns can be defined:

"water" is a noun.
The noun "water" is uncountable.

Also it is possible to define any number of nouns in one sentence:

"car", "cars", "boat", "boats", "computer" and "computers" are nouns.

Verbs

Verbs are words that mean doing or being something, e.g. “eat”, “sit”, “is”, “include”. And to define a verb using ES:

"eat" is a verb.

Normally also all forms of the verb are defined at the same time:

"eat", "eats", "ate" and "eaten" are verbs.

Then each of them and their relations are defined more specifically:

The verb "eat" is the 1st form of the verb "eat".
The verb "ate" is the 2nd form of the verb "eat".
The verb "eaten" is the 3rd form of the verb "eat".
The verb "eats" is the 3rd person form of the verb "eat".

Adjectives

Adjectives are words of value like a color (e.g. “blue”), size (e.g. “big”) etc. To define an adjective in ES:

"blue" is an adjective.
"small" is an adjective.

It is possible also to define the different forms of adjectives:

"small", "smaller" and "smallest" are adjectives.
The adjective "small" is the 1st form of the adjective "small".
The adjective "smaller" is the 2nd form of the adjective "small".
The adjective "smallest" is the 3rd form of the adjective "small".

Adjectives are usually used together with a noun.

a blue color.
a small size.
a fast car.
an excellent driver.

Adverbs

Adverbs are words that define way (e.g. “easily”), time (e.g. “now”), place (e.g. ????), state (?????), size (e.g. “very”).

"easily" is an adverb.
"very" is an adverb.

An adverb that defines a size can then be used together with an adjective e.g.

very big

An adverb that defines way, time, place etc. can be used together with a verb, e.g.

I have it now.
He did it easily.

Prepositions

Prepositions are words that can be used to add more details to the verb, e.g.

"to" is a preposition.
I gave it to him.

Sentences

ES is written using complete sentences of English language. There are four different sentence types in ES. A statement, a question, an order and a condition.

A sentence can be in present, past and future tense, e.g.

I eat a banana.
I ate a banana.
I will eat a banana.

Statement

A statement is a sentence where you provide some information, e.g.

I ate a cake.
He eats a banana.
They will eat pizza.

Question

A question is a sentence where you ask some information, e.g.

Did you eat a cake?
Does he eat a banana?
Will they eat pizza?
What is his name?
What is the number of cars?

Order

An order is a sentence where you command someone to do something, e.g.

Eat a cake.
Go for a walk.
Give it to him.

Condition

A condition is a sentence where you evaluate some statement and do differently based on the result or state some new statement, e.g.

If your stomach is empty, then you are hungry, else you are not hungry.
If you are hungry, then eat food.

For more info on conditions and how to use them, see the the “Conditions” section in this document.

Classes

Classes are used for defining things e.g. a car, a boat, a man. A class is defined by simply using it. The classes can have relations between each other, usually the “be”-relation (i.e. inheritance relation), e.g.

"car" and "vehicle" are nouns.
A car is a vehicle.     /* i.e. "car" class inherits "vehicle" class */

A class can have properties, e.g.

A car has wheels.
A year has 12 months.

Things

Things are instances of some class (or even multiple classes). To create a new thing for a class, e.g. an instance of a car:

A car.

After this the created thing can be referenced, e.g.:

The car is fast.

To create a collection of multiple things:

10 cars.
The 10 cars are expensive.

To refer to one thing from a collection of things:

10 cars.
The 1st car is small.
The 2nd car is large.

To refer to next thing from a collection of things:

10 cars.
The 1st car is small.
The next car is large.     /* same as: The 2nd car is large. */

To give a class some properties and then use them in things:

A year has 12 months.
The 7th month of a year is hot.          /* now the 7th month ie. July is hot for any year */
Years.                                   /* years since Epoc */
The 7th month of the year 2015 is cold.  /* to make an exception */

To increase or decrease the number of some collection of things:

5 cars.
Increase the number of the cars.   /* now there are 6 cars. */
Decrease the number of the cars.   /* now there are 5 cars again. */

(NOT SUPPORTED YET)

A collection can be used also as a vector or an array of things:

A coordinate is meters.
An x-coordinate, a y-coordinate and an z-coordinate are coordinates.
A position has 3 coordinates.
The 1st coordinate is an x-coordinate.
The 2nd coordinate is a y-coordinate.
The 3rd coordinate is an z-coordinate.

A position.
The coordinates of the position are 41.0 (meters), 5.3 (meters) and -10.23 (meters).
/* Same as: */
The 1st coordinate of the position is 41.0 (meters).
The 2nd coordinate of the position is 5.3 (meters).
The 3rd coordinate of the position is -10.23 (meters).

/* Same as: */
The x-coordinate of the position is 41.0 (meters).
The y-coordinate of the position is 5.3 (meters).
The z-coordinate of the position is -10.23 (meters).

(NOT SUPPORTED YET)

Names

Each thing should be named individually to be able to refer to it later on, E.g.

A boy.
The boy has a name "Joe".
Joe is nice.

A man.
The man has a name "Michael \"The Dude\" Brown".
Michael "The Dude" Brown lives in Boston.

Personal Pronouns

Personal pronouns are used to refer to latest things that have been mentioned or referenced previously, e.g.

A car.
It is blue.

A man.
He is cool.

All supported personal pronouns are:

I      The peer that is sending a sentence.
       Usually the remote peer (e.g. a file or a client).
you    The peer that is receiving a sentence.
       Usually the ES program itself.
he     A latest referenced thing that is a man.
she    A latest referenced thing that is a woman.
it     A later referenced thing that is not defined as a man nor a woman.
we     The peer that is sending a sentence and one or more other peers.
they   A latest referenced group of things.

The “you” and “I” pronouns have special meaning. The “you” refers to the application itself. The “I” refers to the external thing that provides the stream of characters for compilation, e.g. the ES compiler or a remote peer of inter-process communication. E.g.

You are a tourist guide.
I am the ES compiler.
I am a remote host.

Also the object and possessive forms of all the supported personal pronouns are supported:

me, my, mine           The remote peer or ES compiler.
your, yours            The ES program itself.
him, his               A latest referenced thing that is a man.
her, hers              A latest referenced thing that is a woman.
its                    A later referenced thing that is not defined as a
                       man nor a woman.
us, our, ours          The remote peer or ES compiler.
them, their, theirs    A latest referenced group of things.

E.g.

Give it to me.
It is your car.
I gave it to her.
It is mine.          /* UNSUPPORTED STILL */

Sometimes it is not so clear to which thing/person the personal pronoun refers to. However in ES language there is a strict rules for it. The logic is that a personal pronoun refers to a previously referenced thing in this priority order:

1. if the preposition was used in previous sentence then it refers to the same thing.
2. object,
3. indirect object,
4. thing in preposition,
5. subject.

Here is list of examples and related rules for them:

The robot asked the dog a question in the kitchen.
It was dirty. (2. it -> the question)

The robot washes the dog in the kitchen.
It is dirty. (2. it -> the dog)

The robot is in the kitchen.
It is dirty. (4. it -> the kitchen)

The robot is tired.
It is dirty. (5. it -> the robot)

The robot is tired.
Its motor is hot. (5. it -> the robot)
Its hands are dirty. (1. it -> the robot)

You should always remember that there is a limit, even though quite long, how long the ES interpreter remembers the previously referenced things. So, if you have not referenced a thing in previous sentences it is better to refer to them by name instead of personal pronouns. E.g.

Jack gave Mary a call.
Mary's car is blue.

It is also possible to refer by class to previously defined things, e.g.

A car.
The car is blue.

I have a blue car.
The blue car is very fast.

Joe has 3 cars.
The 1st car is very expensive.
... or later ...
Joe's 1st car is very nice.
The 2nd car of Joe is cheap.

Also other pronouns are supported.

someone
somebody
something

These three can be used to refer to something or somebody. E.g.

Does Joe have something?
Does Joe love someone?
Does someone have money?

Procedures

A procedure is a sequence of sentences. All four sentence types can be used i.e. statements, questions, orders and conditions, e.g.

To bake a cake.
  Put 2 decilitres of flour to a bowl.
  ...
  You have a cake.
End.

And to call the procedure:

Bake a cake.

You can also refer to the given parameters:

To eat a cake.
  Forget the cake.
End.

You have a cake.
Eat the cake.

You can also call a procedure for multiple things at once:

To eat a banana.
  Peel it.
  Swallow it.
End.

3 bananas.
The 1st banana is green.
The 2nd banana is yellow.
The 3rd banana is brown.
Eat the 1st banana. Eat the 2nd banana. Eat the 3rd banana.
/* OR: Eat the 1st banana, the 2nd banana and the 3rd banana. */
/* OR: Eat the bananas. */       /* NOT YET SUPPORTED */.
/* OR: Eat the 3 bananas. */.    /* NOT YET SUPPORTED */.

To process more than one thing at a time you can use collections of them, e.g.

To peel a fruit.
  ...
End.

To mix fruits together.
  Peel the fruits.
  ...
End.

Mix the banana and the apple together.  /* The procedure "To mix fruits." is called
                                             only once, both the banana and the apple
                                             as parameters. They get first peeled, one
                                             at a time */

There is also a collection of system procedures that are always defined and usable. E.g. the “print” procedure that can be used to print anything.

Print "Hello World!".     /* prints "Hello World!" to standard output */

A man.
He has a name "John".
Print John's name.        /* prints "John" */.

The pronouns can be used in the procedure parameters to make them more generic:

To eat something.
  Put something to your mouth.
  Swallow something.
End.

A banana.
Eat the banana.
There is an apple.
Eat the apple.

To give something to someone.
  Go to someone.
  Pass something to someone.
End.

"ring" and "woman" are nouns.
A ring.
A woman.
Give the ring to the woman.

There can be also more than one thing of the same type:

To put a 1st thing into a 2nd thing.
  Open the 2nd thing.
  Move the 1st thing to the 2nd thing.
  Close the 2nd thing.
End.

A bin is a thing.
A thrash is a thing.
A bin.
A thrash.
Put the thrash into the bin.

Same can be used with pronouns (to avoid having a common class):

To put 1st something into 2nd something.
  Open 2nd something.
  Move 1st something to 2nd something.
  Close 2nd something.
End.

A bin.
A thrash.
Put the thrash into the bin.

Conditions

The ES provides a basic collection of condition types for implementing logic for the application. There are available the following condition types:

If-then-else.
If-unknown-if.
If-unsure-if.
If-and-only-if.             /* UNSUPPORTED YET */
While.
Until.

There are two ways to use conditions, alone and inside a procedure. It depends on the condition type whether it can be used alone or only inside a procedure, or both.

In any of the condition types the “else”-branch of a condition statement is always optional.

If-then-else

The If-then-else condition is the most commonly used type from all the condition types. Here is the syntax for it:

If <sentence of statements>,
  then <sentence>,
  [else <sentence>].

/* Or alternatively */

If <sentence of statements>, then.
  <sentences>.
[Else.
  <sentences>.]
End.

When an If-then-else condition is used alone it can be used to globally define some conditional statements or to conditionally trigger execution of some procedures, e.g.

If your stomach is empty, then you are hungry, else you are not hungry.

If you are hungry, then eat food.

Your stomach is empty.

When an If-then-else condition is used in a procedure it can be used to implement conditional branches of execution, e.g.

To bake a cake.
  If you don't have a bowl, then get a bowl.
  If you don't have flour, then get flour.
  ...
End.

/* or alternatively */

To bake a cake.
  If you don't have a bowl, then.
    Get a bowl.
  End.
  If you don't have flour, then.
    Get flour.
  End.
  ...
End.

There is also an optional “else”-branch that can be used:

To go for a walk.
  If the temperature is above 0 celcius, then put a cap on your head,
  else put a woolly hat on your head.
  ...
End.

/* or alternatively */

To go for a walk.
  If the temperature is above 0 celcius, then.
    Put a cap on your head.
  Else.
    Put a woolly hat on your head.
  End.
  ...
End.

Notice that if the condition is evaluated as an unknown, then the else-branch is executed. If you do not want that, then you should use the if-unknown-if condition first (described below).

If-unknown-if

The If-unknown-if condition is for checking if the sentence of statements in the condition is known or not. Here is the syntax for it:

If unknown if <sentence of statements>,
  then <sentence>,
  [else <sentence>].

/* Or alternatively */

If unknown if <sentence of statements>, then.
  <sentences>.
[Else.
  <sentences>.]
End.

E.g. to use it alone, to automatically check for weather of tomorrow:

If unknown if it is going to rain tomorrow, then read the weather forecast for tomorrow.

E.g. to use it inside a procedure:

To go for a walk.
  If unknown if the temperature is above 0 celcius, then.
    Read the temperature from the meter.
  End.
  If the temperature is above 0 celcius, then.
    Put a cap on your head.
  Else.
    Put a woolly hat on your head.
  End.
  ...
End.

It is also possible to use “if not known if” instead of “if unknown if”.

If-unsure-if

The If-unsure-if condition is for checking whether something is not true or false, or is unknown. Here is the syntax for it:

If unsure if <sentence of statements>,
  then <sentence>,
  [else <sentence>].

/* Or alternatively */

If unsure if <sentence of statements>, then.
  <sentences>.
[Else.
  <sentences>.]
End.

E.g. to use it alone, to automatically check for weather of tomorrow:

If unsure if it is going to rain tomorrow, then read the weather forecast for tomorrow.

E.g. to use it inside a procedure:

To go for a walk.
  If unsure if the temperature is above 0 celcius, then.
    Read the temperature from the meter.
  End.
  If the temperature is above 0 celcius, then.
    Put a cap on your head.
  Else.
    Put a woolly hat on your head.
  End.
  ...
End.

It is also possible to use “if not sure if” instead of “if unsure if”.

If-and-only-if

The If-and-only-if condition is for defining two way equality. Here is the syntax for it:

/* UNSUPPORTED YET */

If and only if <sentence of statements>,
  then <sentence>.

/* Or alternatively */

If and only if <sentence of statements>, then.
  <sentences>.
End.

E.g. to define that if I am at work, only then I am working, and when I am working, only then I am at work.

If and only if I am at work, then I am working.

This would mean that if I would be at work, then I would be working and if I would be working, I would be at work. I.e. the above would be identical to the following:

If I am at work, then I am working.
If I am working, then I am at work.

While

The While condition is for looping until some conditional statements are not true anymore. Here is the syntax for it:

While <sentence of statements>,
  then <sentence>,
  [else <sentence>].

/* Or alternatively */

While <sentence of statements>, then.
  <sentences>.
[Else.
  <sentences>.]
End.

E.g. to stir a porridge until it is ready.

While the porridge is not ready, then stir it.

Until

The Until condition is for waiting until some conditional statements are evaluated as true. Here is the syntax for it:

Until <sentence of statements>, then <sentences>.

E.g. to wait until a porridge is ready:

Until the porridge is ready, then wait.

Alternatively the order of words can be different.

Wait until the porridge is ready.

/* NOT SUPPORTED YET */

Pronouns in conditions

Pronouns can be used also in conditions to make them more generic.

If I have something, then I own something.
If someone has a lot of money, then someone is not poor.
If you do something, then I do something.

Peers

In the ES language there is a concept of a “peer”. A peer is an end point of a one-to-one or one-to-many communication e.g. via a socket connection. The ES application is a local peer and the others are remote peers that can be e.g. a file whose contents are streamed to the ES application (like the ES compiler does), standard input & output, and a client at the remote end of a INET/UNIX socket.

The communication between the peers can be illustrated more conveniently using ‘>’ for a remote peer and ‘<‘ for the ES application itself:

> You are hungry.
> Are you hungry?
< Yes.

When the ES application code is compiled by the ES compiler, the ES source code is sent to the ES application as a stream of characters, thus the ES compiler acts like a remote peer. The ES compiler ignores any characters (sentences) send by the ES application.

When all contents of the ES application code has been sent, then the ES compiler saves the ES application contents in a “binary” format to file system that can be later on run by using any of the different ES runtime executables.

When the ES application binary is run in some ES runtime version, the ES application can be connected to some remote peer e.g. a client at the other end of an INET/UNIX socket connection. The remote peer can then send and receive ES language sentences to/from the ES application.

Assignments

In ES language the statements are used for assigning some value to some property of a thing.

To assigning an adjective to some thing, e.g.

A car.
The car is fast.

When an adjective is related to some noun (e.g. blue is a color), then the relation of them must be defined before using the adjective to ensure correct assignment.

"blue" is an adjective.
Blue is a color.

After this it is possible to use the blue color in assignments:

A car.
The car has a color.
The color of the car is blue.

Alternatively:

A car.
The car has a blue color.

After that the assigned value can be also referenced:

The blue color of the car is nice.

To assign a numerical amount of units to some property, e.g. a boy with a height:

A boy.
The boy has a height.
The height of the boy is 1.8 meters.

And to update the value later:

The height of the boy is 1.9 meters.

And to update the value from another property:

A length.
The length is 1.7 meters.
The height of the boy is the same as the length.

And to assign a password with a string value:

A password.
The password is "abc123".

Or more easily:

A password "abc123".

And to update the value later:

The password is "qwerty123".

And to refer to that password in case there are many:

The password "qwerty123" is not secure.

In case a thing has both a numerical value and a literal string value, then the numerical value is used and the literal string is assumed to be one of the nouns that identify the thing.

A length "x".
The length "x" is 10 meters.

For uncountable things (e.g. matter like gold, sugar, milk, flower, powder etc.) it is possible to use a short form to tell a certain amount of matter:

"sugar", "gold", "matter", "teaspoon", "teaspoons", "gram", "grams",
 "weight", "weights", "volume", "volumes" are nouns.

The noun "teaspoons" is the plural form of the noun "teaspoon".
The noun "grams" is the plural form of the noun "gram".
The noun "weights" is the plural form of the noun "weight".
The noun "volumes" is the plural form of the noun "volume".

The noun the noun "sugar", the noun "gold" and the noun "matter" are uncountable.

A weight is grams.
A volume is teaspoons.
Matter has a weight and a volume.
Sugar and gold are matter.

You have 10 grams of gold.
(Same as "You have gold. The gold has a weight. The weight is 10 grams.")

You have 5 teaspoons of sugar.
(Same as "You have sugar. The sugar has a volume. The volume is 5 teaspoons.")

Also conditional assignments are possible using conditions.

If the boy did not smoke, then the height of the boy is 2 meters.

Questions

A question can be used to query trueness, value, amount, subject, time, place, doing, kindness, reason, way, level, ownership and existence. A question can be used alone and also inside procedures.

When used alone the result is sent to the remote peer, which can be e.g. the standard output or a client on the other side of a socket connection. E.g.

> You are hungry.
> Are you hungry?
< Yes.

When a question is used inside a procedure the question is sent to the remote peer and the remote peer is assumed to answer the sent question. E.g.

To ask.
  Are you hungry?
End.

When we call the “ask” procedure it will result to the following dialogue:

> Ask.
< Ok.
< Am I hungry?
> Yes.
> Are you hungry?
< Yes.

As you can see the answers to the given questions are remembered automatically.

Here is a more complicated example, where values for known things are asked and remembered:

A pickup time.
A pickup location.
Passengers.
A destination.

To order a taxi.
  What is the pickup time?
  What is the pickup location?
  What is the number of passengers?
  What is the destination?
End.

Then we can ask the ES application to order a taxi.

> Order a taxi.
< Ok.

This makes the the ES application to start asking the questions defined in the procedure and we can answer them. Notice that all the given answers are automatically assigned to the asked things:

< What is the pickup time?
> The 7th hour of tomorrow.
< What is the pickup location?
> "Beacon St., Burlington, MA".
< What is the number of passengers?
> 3.
< What is the destination?
> "Logan airport".

Then we can check if needed that the ES application really got all the answers right by asking them from it:

> What is the pickup time?
< The 7th hour of tomorrow.
> What is the pickup location?
< "Beacon St., Burlington, MA".
> What is the number of passengers?
< 3.
> What is the destination?
< "Logan airport".

In this way it suppose to be easy to create complete dialogues with a remote peer.

Trueness

Trueness can be evaluated to know whether or not some statement is true or not. E.g.

> Are you hungry?
> Do you have money?
> Did you eat a banana?

The answer can be either:

< Yes.
< No.
< Maybe.
< I don't know.
< Sorry.    /* question was not understood */

Value

A value can be asked for any property of a thing. E.g.

> A man.
< Ok.
> The man has a name "Joe".
< Ok.
> What is Joe's name?
< "Joe".

> A password.
> The password is "abc123".
> What is the password?
< "abc123"

> Joe has a height.
< Ok.
> Joe's height is 2 meters.
< Ok.
> What is Joe's height?
< 2 meters.

> A car.
< Ok.
> The car has a blue color.
< Ok.
> What is the color of the car?
< Blue.

If an adjective is used as an identifying information, then it is not treated as a value as such, e.g.

> A long length.
< Ok.
> A short length.
< Ok.

> What is the long length?
< Long.
> What is the short length?
< Short.

> The long length is 10 meters.
< Ok.
> The short length is 2 meters.
< Ok.
> What is the long length?
< 10 meters.
> What is the short length?
< 2 meters.

It is also possible to ask if something is known or not, e.g.

> A password.
< Ok.
> Is the password unknown?
< Yes.
> Is the password known?
< No.
> The password is "abc123".
< Ok.
> Is the password unknown?
< No.
> Is the password known?
< Yes.

> Blue is a color.
< Ok.
> A color "bg".
< Ok.
> Is the color "bg" unknown?
< Yes.
> The color "bg" is blue.
< Ok.
> Is the color "bg" unknown?
< No.

> A length is meters.
< Ok.
> A length "x".
< Ok.
> Is the length "x" unknown?
< Yes.
> The length "x" is 10 meters.
< Ok.
> Is the length "x" unknown?
< No.

/* NOT SUPPORTED YET */

Amount/Number

It is also possible to ask the amount/number of some collection of things. E.g.

> 10 cars.
< Ok.
> What is the number of cars?
< 10.

> A weight.
< Ok.
> It is 10.5 kilos.
< Ok.
> What is the amount of the kilos?
< 10.5.

> How many kilos is the weight?
< 10.5.

For uncountable things (e.g. matter like gold, sugar, milk, flower, powder etc.) it is possible to use a short form to ask about the amount of matter:

>You have 10 grams of gold.
<Ok.
>Do you have 10 grams of gold?
<Yes.
>Do you have 4 grams of gold?
<No.
>What is the weight of the gold?
<10 grams.

>Is the weight of the gold 10 grams?     (NOT SUPPORTED YET)
<Yes.

Subject

To ask who did something:

> Who drove the car?
< John.
> Who did drive the car?
< John.

> Who has a car?
< I.
> Who has the car?
< I.

> Which of the cars are blue?
< The 1st car and the 3rd car.
> Which of the cars are red?
< The 2nd car and the 6th car.
> Which of them have 4 doors?
< The 2nd car.

Time

To ask when something happened:

> When did he buy the car?          /* NOT SUPPORTED YET */
< Yesterday.

Place

To ask where something happened:

> Where was he born (in)?
< Helsinki.
> Where did he go (to)?
< Boston.
> Where did he come (from)?
< Oulu.
> Where did he visit?
< Melbourne.

/* NOT SUPPORTED YET */

Doing

To ask how to do something:

> How to bake a cake?
< To bake a cake.
<   Take a bowl.
<   Put 1 deciliter of flour to the bowl.
<   ...
<   End.

You can also ask what the A.I. can do in general:

> What can you do?
< I can bake a cake. I can drive a car.

You should normally expect a very long list of things that the A.I. can do.

Therefore it is usually better that you ask what the A.I. can do with some thing:

> What can you do with a car?
< I can drive a car.

/* NOT SUPPORTED YET */

Kindness

To ask kindness of a thing:

>What kind is your car?
<Blue and very fast.

/* NOT SUPPORTED YET */

Reason

To ask why something was done.

> Why did you eat the cake?
< I was hungry.

/* NOT SUPPORTED YET */

Way

To ask how something has happened:

> How did you get the money?
< My father gave it to me.

/* NOT SUPPORTED YET */

Level

To ask how e.g. easily something was done:

> How easily did you pass the exam?
< Very easily.

> How easy it is to pass the exam?
< Very easy.

/* NOT SUPPORTED YET */

Ownership

To ask what someone has:

> What do you have?
< A car, a bike and a dog.

/* NOT SUPPORTED YET */

Existence

To ask if something is known to exist:

> Is there a phone?
< Yes.

> Is there a nice weather?
< No.

> Is there a car with a blue color?
< I don't know.

/* NOT SUPPORTED YET */

Notice that the existence can be used also in conditions:

If there is a car with a blue color, then buy the car.

/* NOT SUPPORTED YET */

Multiple questions

It is possible also to ask multiple questions at the same time:

Are you ill or are you tired?
Did you take money and did you call mom?

Any alternative questions (“or” between questions) are expected to be answered with full alternative e.g.:

> Are you ill or are you tired?
< I am tired.

/* NOT SUPPORTED YET */

Any combined questions (“and” between questions) are expected to be answered with a single “yes” / “no” / “maybe” / “don’t know” answer.

> Did you take money and did you call mom?
< Yes.

Notice that it is not supported to ask any other that trueness of something in any combined questions.

References

In ES language there is a concept called as a “reference” that can be used as a way to refer to a thing, a place or time.

A reference is usually a thing that is created with the adjectives “current”, “next”, “previous”, “upper”, “lower”, “left” and “right” etc. E.g. the current animal in the next example:

"current", "nice" and "bad" are adjectives.
"animal", "dog" and "bird" are nouns.
A bird is an animal.
A dog is an animal.

A current animal.

10 dogs.
6 birds.

The 5th bird is the current animal.
The current animal is nice. /* This makes the 5th bird nice */

The 1st dog is the current animal.
The current animal is bad. /* This makes the 1st dog bad */

Also ordered things are often used as a references to other things to tell the order of things e.g. order of cars in a car race competition:

"fast" is an adjective.
Cars.

I have a car.
My car is the 1st car.
The 1st car is fast.  /* This makes your car a fast one */

Also any things that have a literal string value is often used as a references to other things, e.g.

Cars.
A car "A".
The 6th car is the car "A".
The car "A" is nice.   /* this makes the 6th car a nice one */

Also some time representations are treated as references. For more information about time representations, see the chapter “Time representations”. Here is an example of a time representation called as “this day”:

A time representation.
It has a name "this day".
This day is the 1st day of this month.     /* notice the order used here */
This day is nice.   /* this makes the 1st day of this month a nice one */.

Notice that for time representations the order of the sentence is different compared to other references.

The references can not be chained together, instead a reference always gets resolved before it is assigned to another reference, e.g.

Birds.

A current bird.
A current animal.

The 5th bird is the current bird.
The current bird is the current animal.  /* current bird is resolved to 5th bird */
The 6th bird is the current bird.
The current animal is nice. /* This makes the 5th bird nice, not the 6th one */

It is also possible to define a collection of references.

Animals.
You have a dog.

Your dog is the 1st animal.    /* now 1st animal refers to your dog. */
/*OR*/
The animals include your dog.  /* now 1st animal refers to your dog. */

The 1st animal is big.         /* now your dog is big. */

A collection of references can be used also as a reference to a collection of things.

Animals.
You have dogs.
Your dogs are the animals.     /* now animals refers to your dogs. */
The animals are big.           /* now your dogs are big. *//

There are some predefined procedures that can be used with references:

Ascend        Ascend a reference to point to the next thing in a collection
              of things (e.g. 10 cars).
Descend       Descend a reference to point to the previous thing in a
               collection of things.

E.g. to go through a collection of cars:

10 cars.
"current" is an adjective.
A current car.
The 1st car is the current car.  /* Now the current car points to the 1st car. */

Ascend the current car.  /* Now the current car points to the 2nd car. */
Descend the current car.  /* Now the current car points to the 1st car. */

/* Below forms NOT SUPPORTED YET */
Ascend the current car (as a reference) (by 1 thing).
Descend the current car (as a reference) (by 1 thing).
Ascend the current car (as a reference) by 5 things.
Descend the current car (as a reference) by 5 things.

It is possible to reference also to a collection of things that are different kind and then move the reference between them by specifying a class of the thing.

Animals.
A dog.
2 cats.
A bird.
The dog is the 1st animal.
The 1st cat is the 2nd animal.
The bird is the 3rd animal.
The 2nd cat is the 4th animal.
A current animal.
The 1st animal is the current animal. /* Now current animal points to the dog */
The current animal is old.            /* Now the dog is old */
Ascend the current animal (as a reference) by one cat. /* now the current animal points to the 1st cat */
The current animal is pretty.         /* Now the 1st cat is pretty */
Ascend the current animal (as a reference) by one cat. /* now the current animal points to the 2nd cat */
The current animal is pretty.         /* Now also the 2nd cat is pretty */

/* NOT SUPPORTED YET */

If the reference is not pointing to any thing, then nothing is done.

A current car.
Ascend the current car.  /* Nothing happens */
Descent the current car. /* Nothing happens */

If there is no more things in a collection then the reference is not ascending/descending and keeps pointing to the original thing.

10 cars.
A current car.
The 1st car is the current car.
Descend the current car. /* Nothing happens */
The 10th car is the current car.
Ascend the current car.  /* Nothing happens */

/* NOT SUPPORTED YET */

Post-linking things

It is possible to link two things together by just stating that the other is the another.

A criminal.
The criminal robbed a bank.

A man.
His name is "John".

John is the criminal.     /* now John robbed the bank */
The criminal is in jail.  /* now John is in jail. */
John is not the criminal. /* now John did not rob the bank, but
                               is still in jail. */

Notice that after linking John to “the criminal”, “the criminal” refers to John, so anything you state about “the criminal” will be true for John.

Variables

In ES language it is possible to create local things inside a procedure, e.g.

/* diagonal = sqrt( length^2 + width^2 ) */
To calculate a total length from a 1st length and a 2nd length.
  A value.
  The value is meters.
  Assign the 1st length to the value.
  Sum the 2nd length to the value.
  Assign the value to the total length.
End.

2 lengths.
The 1st length is 10 meters.
The 2nd length is 20 meters.
A total length.
The total length is meters.
Calculate the total length from the 1st length and the 2nd length.

It is also possible to remember a local thing, thus create a new thing to the application memory.

To imagine a car.
  A car.
  Remember the car.
End.

Imagine a car.
The car is black.

Loops

Loops are used to repeat something for some times or for a collection of things. E.g.

For each of your cars.
  Drive the car to the garage.
End.

Search

Anywhere in procedures it is possible to search something from the application memory. E.g.

To go to somewhere.
    If you have a car, then.
        Drive the car to somewhere.
    End.
End.

Also a “you know” sentence can be used to search from application memory for a specific thing or things. E.g.

To read literature.
    If you know a book that is good, then.
        Read the book.
    End.
End.

/* NOT SUPPORTED YET */

A sentence can also contain more limiting conditions. E.g.

To go somewhere.
    If you have a car and (you have) the keys of the car, then.
        Drive the car to somewhere.
    End.
End.

Mathematical operations

ES support some simple mathematical operations, they are: assign, multiply, divide, sum and substract. Here is a simple example of using the assign, the multiply and the sum operations:

A neclace.
The neclace has 20 pearls and a medaljong.
The pearls have a diameter.
The diameter is 0.005 meters.
The medaljong has a width.
The width is 0.03 meters.

The neclace has a length.
The length is 0.0 meters.
Assign the diameter to the length.
Multiply the length by the number of pearls.
Sum the width of the medaljong to the length.

And here are two examples of using the divide and substract operations:

2 lengths.
The 1st length is 2.8 meters.
The 2nd length is 1.3 meters.

A ratio.
The ratio is 0.0 units.
Assign the 1st length to the ratio.
Divide the ratio by the 2nd length.

A difference.
The difference is 0.0 meters.
Assign the 1st length to the difference.
Substract the 2nd length from the difference.

Parallel processing

ES language allows things to happen in parallel. Any procedure can be called to execute it in its own thread, which is a parallel path of execution. E.g.

"eat", "eats", "ate", "eaten" are verbs.
"eating" is a noun.
The verb "eat" has a noun form.
The noun "eating" is the noun form of the verb "eat".
/* Eating is to eat. */

To eat an apple.
  ...
  You ate the apple.
End.

You have 2 apples.
Start eating the 1st apple.
Start eating the 2nd apple.
 
/* Now you are eating two apples at the same time. */

It is possible to suspend, resume and stop parallel processing, e.g.:

Suspend eating the 1st apple.
Resume eating the 1st apple.
Stop eating the 1st apple.

It is possible to check whether the parallel processing is still being executed:

If you are eating the 1st apple, then stop eating the 1st apple.

… or if it has been paused:

If you are suspended for eating the 1st apple, then stop eating the 1st apple.
/* NOT SUPPORTED YET */

… or was stopped:

If unknown if you ate the 1st apple, then ...

… or has been finished already (completely or was stopped):

If you are not eating the 1st apple, then ...
 
/* NOT SUPPORTED YET */

Time representations

Any time representations (e.g. “today”) used in sentences are not resolved to exact global time i.e. UTC time. This means that any used time representations get resolved only when they are compared internally e.g. when evaluating whether something is true or not e.g:

I ate an apple today.
Did you eat an apple today?

This means that any time representations are treated as local time i.e. it depends on where the subject is located to resolve the time representations from local time to global time:

I was in Boston yesterday.
I met Mary yesterday at 2 pm.  (2 pm Boston local time)

Inter-Process Communication

When the ES source code (.es) is compiled to a binary format (.eso) using the ES compiler (es-c) there is no inter-process communication mechanisms available. Reason for this is that the ES compiler itself is the remote peer that the compiled application is communicating with.

But when the binary of the application is being run (e.g. with es-sh) then there is inter-process communication channel available. Usually this communication is mapped to the standard input and output thus normal terminal window and keyboard can be used to interact with the application.

However in some more advanced application environments it is possible to map the inter-process communication e.g. to a TCP/IP socket, thus allowing remote programs or human clients to interact with the application over the Internet.

Preprocessor

Comments

Here is the list of preprocessor directives available for ES compiler:

#include "<filename>"
#define <DEFINE_NAME> <value>           /* NOT SUPPORTED YET */
#undef <DEFINE_NAME>                    /* NOT SUPPORTED YET */
#if <evaluation>                        /* NOT SUPPORTED YET */
#ifdef <DEFINE_NAME>                    /* NOT SUPPORTED YET */
#ifndef <DEFINE_NAME>                   /* NOT SUPPORTED YET */
#else                                   /* NOT SUPPORTED YET */
#endif                                  /* NOT SUPPORTED YET */

The #include directive can be used for including any ES script source file:

#include "source.es"

Here is an example program:

#include "stdlib.es"
#include "stdio.es"
To begin.
  Print "Hello World!".
  Exit.
End.

3rd party libraries

Introduction

Since EnglishScript, as a programming language, is not very good for implementing any lower level stuff the ES Runtime provides a way to call native C/C++ code from an external dynamically linked library (an .so file in Linux OS).

The HAP library provides a public C API for communicating with HAP from the external library. The HAP expects a specific kind of function API from the external library. Any number of libraries can be used at the same time.

Public HAP C API

To let an external 3rd party library to integrate with HAP and Alvin A.I., HAP provides a public C-language API (Application Programming Interface). It can be found from the ES SDK in the path “inc/c/hap.h”. It also provides the HAP library to link against in the path “lib/libhap.so”. There is also an API documentation in the path “doc/hap_api.html” (NOT YET AVAILABLE) and an example implementation in the path “examples/library.c” and “examples/library.es”.

Both the ES Debugger and ES Shell support loading of a dynamic library as a command line parameter. Please see the Chapter “ES tools” for details.

Example for a 3rd party function

Here is an example for a 3rd party function; how to introduce it, how to implement it in C language and how to use it in ES application.

To implement a 3rd party function (for a dynamic library) see the “examples/library.c” in ES SDK:

/* ------ examples/library.c ------ */

#include <stdio.h>
#include <string.h>
#include "hap.h"

/* Remove heading and tailing quotes */
char * strip_quotes(const char *in, char *out, const int out_max)
{
    ...
}

double print_strings (tHAP *hap, tHAP_Exec *exec, int cnt, tHAP_Ref **refs)
{
    tHAP_Thing *thing;
    tHAP_Noun  *noun;
    tHAP_Word  *word;
    const char *string;
    char        buf[1024];
    int         i;

    for (i = 0; i < cnt; i++)
    {
        thing = hap_ref_get_thing(refs[i]);
        if (thing)
        {
            noun = hap_thing_get_noun(thing);
            if (noun)
            {
                word = hap_noun_get_word(noun);
                string = hap_word_get_string(word);
                printf("%s", strip_quotes(string, buf, sizeof(buf)));
            }
        }
    }

    return HAP_TRUE;
}

/* Once for each library: */

void __attribute__ ((constructor)) load()
{
    /* To init your library. */
}

void __attribute__ ((destructor)) unload()
{
    /* To cleanup your library. */
}

To introduce the 3rd party function in ES language:

A function "print_strings".

To use the 3rd party function:

/* print "Hello World!\n" */
Call the function "print_strings" with "Hello World!" and "\n".

/* print the value of a password */
A password "abc123".
Call the function "print_strings" with "The password is \"", the password and "\".".

Typically a 3rd party function is encapsulated inside a procedure to hide unnecessary details:

/* ------ examples/library.es ------ */

A function "print_strings".

To print something.
    Call the function "print_strings" with something.
End.

To build and run the library example in ES SDK:

$ . setup_env.sh
$ cd examples
$ make all
$ es-sh library.eso library.so
EnglishScript Shell v0.1.1
Copyright (c) Tommi Manttari

> Print "Hello World!\n".
Hello World!
< Ok.

ES tools

ES Compiler

To compile an ES source code (“hello.es”) to a binary format (“hello.eso”):

$ es-c hello.es -o hello.eso

ES Shell

To run a compiled ES application (“hello.eso”):

$ es-sh hello.eso

ES Debugger

To debug a compiled ES application (“hello.eso”):

$ es-db hello.eso

This launches the ES debugger which loads the given compiled ES application (“hello.eso”) and outputs debugger version info, a copyright and an input prompt for debugging commands.

English Script Debugger v0.1
Copyright (c) Tommi Manttari

(db) 

The debugger provides the following debugging commands:

help          Prints a list of available commands.
run           Starts execution of the application and continues
              execution until a breakpoint is reached or
              the execution of the application ends.
break         Adds a breakpoint for execution.
continue      Continues execution of the debugger ES application.
print         Prints value of some thing in application's memory.
eval          Evaluates given statement.  (NOT SUPPORTED YET)
load          Loads an application to memory for debugging.  (NOT SUPPORTED YET)
list          Lists source code.  (NOT SUPPORTED YET)
next          Proceeds code execution until the next code sentence
              proceeding throught possible sub-procedures.
step          Proceeds code execution until the next code sentence
               stepping into possible sub-procedure.
quit          Exits debugger.

Here is an example shown for each of the debugging commands. Here is the code of the example “Hello World!” ES program (hello.es) that we then compile and debug:

#include <stdlib.es>
#include <stdio.es>
To begin.
  Print "Hello World!".
  Exit.
End.

To compile it and start the debugger for debugging it:

$ es-c hello.es -o hello.eso
$ es-db hello.eso
English Script Debugger v0.1
Copyright (c) Tommi Manttari

(db) 

“run” debug command

To start debugging the program (hello.eso):

(db) run
Starting program: hello.eso
 
Hello World!
[Application exited normally]
(db) 

The debugger tries to find an optional “begin” procedure from the application binary and if found then calls it. The application execution continues until the application stops application execution (by calling “exit” procedure) or some fatal runtime exception occurs. If the “begin” procedure is not found then the debugger just resumes the execution of the application.

“break” debug command

Examples for adding breakpoints to the debugged application (hello.eso):

$ es-db hello.eso
English Script Debugger v0.1
Copyright (c) Tommi Manttari

(db) break hello.es:4
Breakpoint 1 added to hello.es, line 4.
(db) 

When the “begin” procedure is called the execution of the debugged application is aborted and the debug prompt “(db)” is shown to the user for giving further debugging commands.

(db) run
Starting program: hello.eso
 
Breakpoint 1 at hello.es, line 4.
4   Print "Hello World!".
(db) 

“print” debug command

Examples for printing values of some things of the below example program:

A dog.
The dog has a name "Buzz".

10 cars.

A man.
The man has a name "Joe".
Joe has a length.
The length is 1.89 meters.

(db) print dog's name
"Buzz"
(db) print the number of cars
10
(db) print Joe's length
1.89
(db) print the dog.
The dog is a dog.
The dog has the name "Buzz".
(db) print the man.
The man is a man.
The man has the name "Joe".
The man has the length.

Copyright (C) Tommi Manttari (2014). All Rights Reserved.

Leave a Reply

Your email address will not be published. Required fields are marked *