Invoking a driver for parsing

In this recipe, you will learn how to call the parser function from the main function of our TOY parser.

How to do it…

To invoke a driver program to start parsing, define the driver function as shown in the following:

  1. Open the toy.cpp file:
    $ vi toy.cpp
  2. A Driver function called from the main function, and a parser can now be defined as follows:
    static void Driver() {
      while(1) {
        switch(Current_token) {
        case EOF_TOKEN : return;
        case ';' : next_token(); break;
        case DEF_TOKEN : HandleDefn(); break;
        default : HandleTopExpression(); break;
      }
      }
    }
  3. The main() function to run the whole program can be defined as follows:
    int main(int argc, char* argv[]) { LLVMContext &Context = getGlobalContext(); init_precedence(); file = fopen(argv[1], ...

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.