The Main Structures Comprising the Compiler Project Code
Spring 08

Return to Class Page

The scanner generated by lex separates the user input program into tokens based on our definition of the language tokens in simple.lex

The parser generated by yacc performs the syntax-directed translation obeying our statement of the language grammer in simple.lr


The Compiler Structures outlined below are:

(astdef.h)

Prog
PROG
programtree
Prog.main Stmtlist list of statements
Prog.vars Varlist alpha-list of variable names
Prog.const_listptr    list of string constants
   info ^ character string
   offset integer field to hold label index
   next ^ next in list of global strings

 
 
 
 


(symtab.h)
Root (points to SYMTABREC) (our symbol table)



(symboltb.h)
 
 
SYMTABREC
Symbol Table Structure
attrs    ^attrec
left    ^ left child in symtab
right    ^ right child in symtab
        

 
ATTREC 
Symbol Table Atribute Record with all info concerning the "id"
id:   user variable name
level:   procedure level
offset   address offset
      
      
      

 
 
VARLIST
Alpha-list of all variables
cur:     ^ attrptr
next:    ^ next in list of vars
        

 
 
 



(semform.h)
 
  STMTNODE
statement description
type: STMTTYPE AssignStmt StdProcCall IfThenStmt   
     ifthen se.bexpr boolean ExprTree
        se.slist list of statements comprising the "then-block"
     assign se.lhs  ^Address Tree
          se.rhs ^Expression Tree
   procoll se.type ReadProc ReadlnProc WriteProc WriteLnProc
          se.params List of Parameters


 
 
EXPRDESC
Expression Tree Node Description
height:    height of exprTree
OP:    + - * / - fetch
ee. ee.addr ^Address Tree [fetch]
  ee.child  ^Expression Tree [Usubop]
  ee.left  ^Expression Tree
(AddOp SubOp MpyOp DivOp)
  ee.right  ^Expression Tree
(AddOp SubOp MpyOp DivOp)
  ee.btree  ^ Boolean Expression Tree

 
 
ADDRNODE
Address Node
Type:  ADDRKIND (Memory, Immediate)
ae.attrs  Memory
ae.i Integer Immediate

 
 
PARAMNODE
description of actual (I/O) parameter
Type: PARAMDESC (Reference Value String)
pe.loc ^Address Tree
pe.val ^Expression Tree
pe.where ^location of string in constlist
pe.next ^next entry in list of parameters of I/O statement


(semstack.h)



 
Semstack
type   SEMSTACKTAG   type of entry
se.addr     ^address entry
se.expr     ^expression entry
se.id     identifier entry
se.oper     OPERATION entry "typedef enum AddOp,SubOp,MpyOp,DivOp,UsubOp,Fetch,EqOp" in semform.h
se.stmt     statement entry
se.slist first statement list entry
    last    
se.plist first parameter list (I/O) entry
   last