Skip to content
Home
Go back

Compiler Design - OC

Edit page

All source code can be found HERE

SYNOPSIS

oc [-ly] [-@ flag ...] [-D string] program.oc

OPTIONS

OUTPUT FILES

Output TypeFilename
String setprog_name.str
Scanned tokensprog_name.tok
Abstract syntax treeprog_name.ast
Symbol tableprog_name.sym
Interm. languageprog_name.oil

The 5 Stages of Compilation

  1. I. Preprocessor and token generation
  2. II. Lexical Analyzer (using flex)
  3. III. LALR(1) Parser (using bison)
  4. IV. Symbols and Type Checking
  5. V. Intermediate Language Emission

I. Preprocessor and String Set Generation

The first part of the compiler consisted of writing a main program for the language oc. Included in it was a string set ADT used to create unique string sets based on the output from the C preprocessor.

The purpose of the string set is to keep track of strings uniquely. For example, if “abc” is entered multiple times, it appears only once in the table. This allows the compiler to compare pointers instead of using strcmp(3).

II. Lexical Analyzer

The second part augmented the string table into a scanner written in flex. Tokens are identified based on regex in the scanner.l file.

III. LALR Parser

This stage involved writing an LALR parser using bison.


Edit page
Share this post on:

Previous Post
Regarding theory of the learnable and cortical learning