From 8459bebceb9533948193774371cbd9fd571b78ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 16 Oct 2019 09:48:31 +0200 Subject: Cowboy 2.7.0 --- articles/xerl-0.3-atomic-expressions/index.html | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'articles/xerl-0.3-atomic-expressions/index.html') diff --git a/articles/xerl-0.3-atomic-expressions/index.html b/articles/xerl-0.3-atomic-expressions/index.html index e7c6ab25..086c0de3 100644 --- a/articles/xerl-0.3-atomic-expressions/index.html +++ b/articles/xerl-0.3-atomic-expressions/index.html @@ -70,7 +70,7 @@

We will be adding atomic integer expressions to our language. These look as follow in Erlang:

-
@@ -79,28 +79,28 @@ http://www.gnu.org/software/src-highlite -->

And the result of this expression is of course 42.

We will be running this expression at compile time, since we don't have the means to run code at runtime yet. This will of course result in no module being compiled, but that's OK, it will allow us to discuss a few important things we'll have to plan for later on.

First, we must of course accept integers in the tokenizer.

-
{D}+ : {token, {integer, TokenLine, list_to_integer(TokenChars)}}.

We must then accept atomic integer expressions in the parser. This is a simple change. The integer token is terminal so we need to add it to the list of terminals, and then we only need to add it as a possible expression.

-
expr -> integer : '$1'.

A file containing only the number 42 (with no terminating dot) will give the following result when parsing it. This is incidentally the same result as when tokenizing.

-
[{integer,1,42}]

We must then evaluate it. We're going to interpret it for now. Since the result of this expression is not stored in a variable, we are going to simply print it on the screen and discard it.

-
@@ -117,28 +117,28 @@ http://www.gnu.org/software/src-highlite -->

This is what happens when we create a file that contains two integers on two separate lines:

-
[{integer,1,42},{integer,2,43}]

And on the same lines:

-
[{integer,1,42},{integer,1,43}]

Does this mean we do not need separators between expressions? Not quite. The + and - operators are an example of why we can't have nice things. They are ambiguous. They have two different meanings: make an atomic integer positive or negative, or perform an addition or a substraction between two integers. Without a separator you won't be able to know if the following snippet is one or two expressions:

-
42 - 12

Can we use the line ending as an expression separator then? Some languages make whitespace important, often the line separator becomes the expression separator. I do not think this is the best idea, it can lead to errors. For example the following snippet would be two expressions:

-
@@ -166,6 +166,10 @@ http://www.gnu.org/software/src-highlite --> +
  • Cowboy 2.7
  • + + +
  • Gun 2.0 pre-release 1
  • -- cgit v1.2.3