-
Book Overview & Buying
-
Table Of Contents
LLVM Cookbook
By :
In this recipe, you will learn how to parse a simple expression. A simple expression may consist of numeric values, identifiers, function calls, a function declaration, and function definitions. For each type of expression, individual parser logic needs to be defined.
We must have the custom-defined language—that is, the TOY language in this case—and also stream of tokens generated by lexer. We already defined ASTs above. Further, we are going to parse the expression and invoke AST constructors for every type of expression.
To parse simple expressions, proceed with the following code flow:
Open the toy.cpp file as follows:
$ vi toy.cpp
We already have lexer logic present in the toy.cpp file. Whatever code follows needs to be appended after the lexer code in the toy.cpp file.
Define the parser function for numeric expression as follows:
static BaseAST *numeric_parser() {
BaseAST *Result = new NumericAST(Numeric_Val);
next_token();
return...
Change the font size
Change margin width
Change background colour