Running lexer and parser on our TOY language

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.

Getting ready

To do this, you should have understanding of TOY language grammar and all the previous recipes of this chapter.

How to do it…

Run and test the Lexer and Parser on TOY Language, as shown in the following:

  1. First step is to compile the toy.cpp program into an executable:
    $ clang++ toy.cpp  -O3 -o toy
  2. The 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
  3. This file is passed as argument to be processed by the toy compiler:
    $ ./toy example

How it works…

The TOY compiler will open the

Get LLVM Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.