Syntactical analysis
Syntactical analysis is done by the parser, which we will implement next. Its base is the grammar and the lexer from the previous sections. The result of the parsing process is a dynamic data structure called an abstract syntax tree (AST). The AST is a very condensed representation of the input and is well-suited for semantic analysis. First, we will implement the parser. After that, we will have a look at the AST.
A handwritten parser
The interface of the parser is defined in the Parser.h
header file. It begins with some include
statements:
#ifndef PARSER_H #define PARSER_H #include "AST.h" #include "Lexer.h" #include "llvm/Support/raw_ostream.h"
The AST.h
header file declares the interface for the AST and will be shown later. The coding guidelines from LLVM forbid the use of the <iostream>
library, so the header of the equivalent LLVM functionality must be included. It is required to emit an error message. Let&apos...