aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 5b8eca88875c0560230c441cbd52affe86635513 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Frontend for language

Tiny beginnings of a parser for a toy language, written in C99.

Currently only capable of parsing simple arithmetic expressions, limited to
positive numbers, addition, subtraction, multiplication, and division.


## Compiling

To build `frontend`:

```
make
```


## Running

Simply run `./frontend INPUT_FILE` and it should parse and print the resulting
AST in polish notation with surrounding parenthesis,
ie. `1 + 2 * 3` turns into `( + 1 ( * 2 3 ) )`,
and `1 + 2 + 3` becomes `( + ( + 1 2 ) 3 )`.

Example input can be found in the `program.input` file.


## Next steps

* Allocating all memory up front, an inefficient but very simple use of memory
  would exploit the fact that the number of lines and tokens is bounded by the total
  number of bytes in `INPUT_FILE`, and the number of sub-expressions are bounded
  by the number of tokens, so a naive approach is to allocate
  `length(INPUT_FILE) * sizeof(char + line_t + expression_t)`.
* Streaming parsing; the implementation currently supports reading a limited
  amount of input at each step, extending it to "pause-at-X" and resume once
  more input is available should be a trivial feat.
* Fix precedence implementation, currently we just compare operators, which is
  unmaintainable and inefficient once the grammar is extended.
* Extend the arithmetic grammar to support more operators.
* Boolean grammar parsing.
* Argument parsing to better control the output and debug different parts of the
  implementation.
* Tests.

Currently only simple arithmetic is implemented.