May 2015
Intermediate to advanced
296 pages
5h 10m
English
In this recipe, you will learn how to parse a binary expression.
We must have the custom-defined language—that is, the toy language in this case—and also stream of tokens generated by lexer. The binary expression parser requires precedence of binary operators for determining LHS and RHS in order. An STL map can be used to define precedence of binary operators.
To parse a binary expression, proceed with the following code flow:
toy.cpp file as follows:$ vi toy.cpp
map for operator precedence to store the precedence at global scope in the toy.cpp file as follows:static std::map<char, int>Operator_Precedence;
The TOY language for demonstration has 4 operators where precedence of operators ...
Read now
Unlock full access