Now that a full-fledged lexer and parser for our TOY language grammar are defined, it's time to run it on example TOY language.
To do this, you should have understanding of TOY language grammar and all the previous recipes of this chapter.
Run and test the Lexer and Parser on TOY Language, as shown in the following:
toy.cpp
program into an executable:$ clang++ toy.cpp -O3 -o toy
toy
executable is our TOY compiler frontend. The toy
language to be parsed is in a file called example
:$ cat example def foo(x , y) x + y * 16
toy
compiler:$ ./toy example
The TOY compiler will open the example
file in read mode. Then, it will tokenize the stream of words. It will come across the def keyword and return DEF_TOKEN
. Then, the HandleDefn()
function will be called, which will store the function name and the argument. It will recursively check for the type of token and then call the specific token handler functions to store them into respective ASTs.
3.137.217.220