Write first draft of Bison-based parser and lexer
This commit is contained in:
@@ -226,6 +226,10 @@ It's called Bison, and it is frequently used with Flex. Before we get to bison,
|
||||
incurred - the implementation of our AST. Such a tree is language-specific, so Bison doesn't generate it for us. Here's what
|
||||
I came up with:
|
||||
{{< codeblock "C++" "compiler_ast.hpp" >}}
|
||||
We create a base class for an expression tree, which we call `ast`. Then, for each possible syntactic construct in our language
|
||||
(a number, a variable, a binary operation, a case expression) we create a subclass of `ast`. The `ast_case` subclass
|
||||
is the most complex, since it must contain a list of case expression branches, which are a combination of a `pattern` and
|
||||
another expression.
|
||||
|
||||
Finally, we get to writing our Bison file, `parser.y`. Here's what I come up with:
|
||||
{{< rawblock "compiler_parser.y" >}}
|
||||
|
||||
Reference in New Issue
Block a user