Compare commits
2 Commits
b012e557f0
...
3f1db0aa13
Author | SHA1 | Date | |
---|---|---|---|
3f1db0aa13 | |||
15f59a7806 |
|
@ -66,6 +66,27 @@ and building up our project. We'll cover:
|
||||||
|
|
||||||
We'll be creating a __lazily evaluated__, __functional__ language.
|
We'll be creating a __lazily evaluated__, __functional__ language.
|
||||||
|
|
||||||
|
#### What we won't cover
|
||||||
|
Surely a guide written by one person can't be comprehensive. Not only
|
||||||
|
do I have a finite amount of time to share this informatiom with you,
|
||||||
|
but I also don't want to dilute the content of the posts in this series. Furthermore,
|
||||||
|
many things that we'll be using for this tutorial are taught
|
||||||
|
by numerous other sources, and those sources do a better job than I would.
|
||||||
|
So, here are some things that you might want to know for this series,
|
||||||
|
which won't be covered by the series itself:
|
||||||
|
|
||||||
|
* [Theory of computation](https://en.wikipedia.org/wiki/Theory_of_computation),
|
||||||
|
or, more specifically, [automata theory](https://en.wikipedia.org/wiki/Automata_theory).
|
||||||
|
Deterministic and nondeterministic finite automata are briefly mentioned
|
||||||
|
during tokenizing, and context free grammars are used in our parser. However,
|
||||||
|
I don't provide a real explanation for either of those things.
|
||||||
|
* [Functional programming](https://en.wikipedia.org/wiki/Functional_programming),
|
||||||
|
with a touch of [lambda calculus](https://en.wikipedia.org/wiki/Lambda_calculus).
|
||||||
|
We jump straight into implementing the concepts from these.
|
||||||
|
* C++. I do my best to use correct and modern C++, but I'm not an expert. I will
|
||||||
|
not explain the syntax / semantics of C++ code included in these posts, but I will
|
||||||
|
explain what my code does in the context of compilers.
|
||||||
|
|
||||||
#### The syntax of our language
|
#### The syntax of our language
|
||||||
Simon Peyton Jones, in his two works regarding compiling functional languages, remarks
|
Simon Peyton Jones, in his two works regarding compiling functional languages, remarks
|
||||||
that most functional languages are very similar, and vary largely in syntax. That's
|
that most functional languages are very similar, and vary largely in syntax. That's
|
||||||
|
|
|
@ -69,7 +69,7 @@ but we don't need indentation, or recursion:
|
||||||
{{< codelines "C++" "compiler/04/ast.cpp" 116 121 >}}
|
{{< codelines "C++" "compiler/04/ast.cpp" 116 121 >}}
|
||||||
|
|
||||||
Let's print the bodies of each function we receive from the parser:
|
Let's print the bodies of each function we receive from the parser:
|
||||||
{{< codelines "C++" "compiler/04/main.cpp" 44 53 >}}
|
{{< codelines "C++" "compiler/04/main.cpp" 41 56 >}}
|
||||||
|
|
||||||
### Printing Types
|
### Printing Types
|
||||||
Types are another thing that we want to be able to inspect, so let's
|
Types are another thing that we want to be able to inspect, so let's
|
||||||
|
@ -82,7 +82,7 @@ The implementation is simple enough:
|
||||||
{{< codelines "C++" "compiler/04/type.cpp" 5 24 >}}
|
{{< codelines "C++" "compiler/04/type.cpp" 5 24 >}}
|
||||||
|
|
||||||
Let's also print out the types we infer. We'll make it a separate loop
|
Let's also print out the types we infer. We'll make it a separate loop
|
||||||
in the `typecheck_program` function, because it's mostly just
|
at the bottom of the `typecheck_program` function, because it's mostly just
|
||||||
for debugging purposes:
|
for debugging purposes:
|
||||||
{{< codelines "C++" "compiler/04/main.cpp" 34 38 >}}
|
{{< codelines "C++" "compiler/04/main.cpp" 34 38 >}}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user