File BigPicture.html    Author McKeeman    Copyright © 2007    index

Putting it all Together

Overview

The action starts with a context-free grammar X.cfg and the C runtime.
  1. makeCfg.m builds grammar tables offline. (cfg.mat)
  2. makeMex.m builds the MEX files offline.
For each X source file or program named on the MATLAB command line
  1. build a lexeme stream (Lexer.m)
  2. build a shift/reduce sequence (Parser.m), one of
    • top down (recursive)
    • bottom up (LR)
  3. build a tree (Tree.m), one of
    • syntax tree
    • AST, abstract syntax tree
  4. build a symbol table (Symbols.m tree walk)
  5. generate a sequence of semantic actions (Generator.m tree walk), which
  6. emits a sequence of hardware instructions (EmitX86.m), which
  7. are assembled as bits in an array (AsmX86.m)
Once the compilation(s) are done
  1. Input variables are initialized from the MATLAB command line.
  2. The rightmost X source file or program is executed, having been linked to builtins and other X programs named on the command line.
  3. Output variables are reported to the MATLAB command line.

Preparation

    *.c -> makeMex.m -> MEX -> *.mexw32
    
    X.cfg -> makeCfg.m
               |
               v
             Cfg.m -> cfg.mat

Front end

          *.x ->  xcom.m
                    |         <-- source text
                    v
                 Lexer.m
                    |         <-- token stream
                    v
                Parser.m
                 /     \
            bottomup  topdown <-- shift/reduce sequence
                 \     /
                 Tree.m
                 /     \
              syntax   AST    <-- tree
                 \     /
                Symbols.m
                    |         <-- symbol table
                    v

Back end

                   | |        <-- symbol table and tree
                   v v
               Generator.m
                    |         <-- semantic actions
                    v
                EmitX86.m
                    |         <-- symbolic hardware instructions
                    v
                AsmX86.m    
                    |         <-- hex hardware instructions
                    v

Runtime

                 
                    |        <-- user input
                    v
                  xcom.m
                 /     \
        EmulateX86.m  RunX86.c
                 \     /
                 xcom.m
                    |        <-- user output
                    v