Tidy up
This commit is contained in:
103 files changed
+3663
-3779
No files matched your search
@@ -28,7 +28,7 @@ exp -> exp + exp
|
||||
-> 7 + (10 / 3) * (-2)
|
||||
```
|
||||
|
||||
This grammar is **ambiguous**, this means one input expression could be generated in several different ways.
|
||||
This grammar is **ambiguous**: this means one input expression could be generated in several different ways.
|
||||
|
||||
$$
|
||||
5 - 4 \times 7
|
||||
@@ -43,7 +43,7 @@ exp -> exp - exp
|
||||
-> 5 - 4 * 7
|
||||
```
|
||||
|
||||
However there is another way to derive this expression starting with `*`
|
||||
However, there is another way to derive this expression starting with `*`
|
||||
|
||||
```haskell
|
||||
exp -> exp * exp
|
||||
@@ -52,7 +52,7 @@ exp -> exp * exp
|
||||
-> 5 - 4 * 7
|
||||
```
|
||||
|
||||
These give us two different ASTs, which gives us two different numeric answers. We must use more terminal symbols to follow BIDMAS.
|
||||
These give us two different ASTs, which give us two different numeric answers. We must use more terminal symbols to follow BIDMAS.
|
||||
|
||||

|
||||
|
||||
@@ -74,7 +74,7 @@ This grammar is unique (non-ambiguous)
|
||||
|
||||
## Semantics of Expressions
|
||||
|
||||
On the left hand side the $+$ is just a symbol, however on the right hand side it is an arithmetic sum operation.
|
||||
On the left-hand side, the $+$ is just a symbol; however, on the right-hand side it is an arithmetic sum operation.
|
||||
|
||||
$[\![ exp + exp ]\!] = [\![exp ]\!] + [\![exp ]\!]$ | $[\![ exp - exp ]\!] = [\![exp ]\!] - [\![exp ]\!]$ ... same for all binary operations
|
||||
|
||||
@@ -99,14 +99,12 @@ $[\![d_0 ]\!] = value(d_0)$
|
||||
|
||||
$[\![d_s d_0]\!] = [\![d_s ]\!]\times10 + value(d_0)$
|
||||
|
||||
|
||||
|
||||
## Scanners and Parsers
|
||||
|
||||

|
||||
|
||||
Scanners take the source language as input and outputs a stream of tokens.
|
||||
Scanners take the source language as input and output a stream of tokens.
|
||||
|
||||
A **token** is a chunk of input; "words" of the language eg. integers, operator symbols, identifiers (function & variable names etc), parenthesis.
|
||||
A **token** is a chunk of input; "words" of the language, e.g. integers, operator symbols, identifiers (function & variable names etc.), parentheses.
|
||||
|
||||
The **grammar of tokens is always regular**, this means it can be generated and recognised by a DFA (deterministic finite automata).
|
||||
The **grammar of tokens is always regular**: this means it can be generated and recognised by a DFA (deterministic finite automaton).
|
||||
Reference in new issue
Block a user