github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

johngunderman / dragon-compiler

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 2
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (6)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (6)
    • hmwk6
    • hmwk5
    • hmwk4
    • hmwk3
    • hmwk2
    • hmwk1
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

A compiler based off the Dragon Book / EECS 337 — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Updated the README for homework 6. 
johngunderman (author)
Thu Dec 03 09:26:29 -0800 2009
commit  d565beff02d2edff3f3e5798d0ced27766c93197
tree    be7300f3e0652cf1032ce0f9a69c94c578348207
parent  5e1ac49d23cf6c3d22a6f4e5318315ed7ce4c84b
dragon-compiler /
name age
history
message
file .gitignore Loading commit data...
directory Documentation/
file Makefile
file README
file hash_tables.c
file hash_tables.h
file intmdt_code_gen.c
file intmdt_code_gen.h
file lexer.lex
file linked_lists.c
file linked_lists.h
file parser.yacc
file test.code
file test2.code
file test3.code
file test_suite.c
README
This compiler is a project for Case Western Reserve University's 
EECS 337 course (Compiler Design).
By John Gunderman

The parser runs seperately from the test suite.
Compiling the parser is as easy as a 'make -B parser', and
running it is as easy as a './parser [filename]', where filename
is one of the three source files in the project. These source files
are named test.code, test2.code, and test3.code.

The test suite can be compiled by running 'make test'. It will create
the './test_suite' executable, which can then be run.

Locations of variables are printed out when the symbol table gets printed out.

Error Handing:
=============
Error handling is rather primitive, but generally prints a vague message about
where the error might be.

UPDATE: you may get a segfault if you try and treat a number as a boolean
or vice versa.


Also, implicit widening does not occur in the given test program,
but it can be shown to work by adding the line

x = i + v;

to the end of the main block.



TEST PROGRAM:

{
  int i; int j; float v; float x; float[100] a;
  while (true) {
    do i = i+1; while(a[i] < v);
    do j = j-1; while(a[j] > v);
    if(i >= j) break;
    x = a[i]; a[i] = a[j]; a[j] = x;
  }
}

Other test programs can be found in the root directory of this project.
Their output is not included here for the simple reason that it would
make this document way to long (aka I'm running low on printer paper).
Feel free to run them and check them out.

OUTPUT:

decls->empty
type-> BASIC 
decl-> type ID
decls->decls decl
type-> BASIC 
decl-> type ID
decls->decls decl
type-> BASIC 
decl-> type ID
decls->decls decl
type-> BASIC 
decl-> type ID
decls->decls decl
type-> BASIC 
type-> type [ NUM ]
decl-> type ID
decls->decls decl
stmts->empty
getting next instruction...
getting next instruction...
factor->TRUE
urnary->factor
term->urnary
expr->term
rel->expr
equality->rel
join->equality
bool->join
getting next instruction...


Entering New Scope

decls->empty
stmts->empty
getting next instruction...
getting next instruction...
loc->ID
loc->ID
factor->loc
urnary->factor
term->urnary
expr->term
factor->NUM
urnary->factor
term->urnary
expr->expr + expr
rel->expr
equality->rel
join->equality
bool->join
stmt->loc = bool
loc->ID
loc->ID
factor->loc
urnary->factor
term->urnary
expr->term
rel->expr
equality->rel
join->equality
bool->join
loc-> loc [ bool ]
factor->loc
urnary->factor
term->urnary
expr->term
loc->ID
factor->loc
urnary->factor
term->urnary
expr->term
rel->expr < expr
equality->rel
join->equality
bool->join
stmt->DO stmt WHILE ( bool ) ;
stmts->stmts stmt
getting next instruction...
getting next instruction...
loc->ID
loc->ID
factor->loc
urnary->factor
term->urnary
expr->term
factor->NUM
urnary->factor
term->urnary
expr->expr - expr
rel->expr
equality->rel
join->equality
bool->join
stmt->loc = bool
loc->ID
loc->ID
factor->loc
urnary->factor
term->urnary
expr->term
rel->expr
equality->rel
join->equality
bool->join
loc-> loc [ bool ]
factor->loc
urnary->factor
term->urnary
expr->term
loc->ID
factor->loc
urnary->factor
term->urnary
expr->term
rel->expr > expr
equality->rel
join->equality
bool->join
stmt->DO stmt WHILE ( bool ) ;
stmts->stmts stmt
getting next instruction...
loc->ID
factor->loc
urnary->factor
term->urnary
expr->term
loc->ID
factor->loc
urnary->factor
term->urnary
expr->term
rel->expr >= expr
equality->rel
join->equality
bool->join
getting next instruction...
getting next instruction...
stmt->BREAK ;
stmt->IF ( bool ) stmt
stmts->stmts stmt
getting next instruction...
loc->ID
loc->ID
loc->ID
factor->loc
urnary->factor
term->urnary
expr->term
rel->expr
equality->rel
join->equality
bool->join
loc-> loc [ bool ]
factor->loc
urnary->factor
term->urnary
expr->term
rel->expr
equality->rel
join->equality
bool->join
stmt->loc = bool
stmts->stmts stmt
getting next instruction...
loc->ID
loc->ID
factor->loc
urnary->factor
term->urnary
expr->term
rel->expr
equality->rel
join->equality
bool->join
loc-> loc [ bool ]
loc->ID
loc->ID
factor->loc
urnary->factor
term->urnary
expr->term
rel->expr
equality->rel
join->equality
bool->join
loc-> loc [ bool ]
factor->loc
urnary->factor
term->urnary
expr->term
rel->expr
equality->rel
join->equality
bool->join
stmt->loc = bool
stmts->stmts stmt
getting next instruction...
loc->ID
loc->ID
factor->loc
urnary->factor
term->urnary
expr->term
rel->expr
equality->rel
join->equality
bool->join
loc-> loc [ bool ]
loc->ID
factor->loc
urnary->factor
term->urnary
expr->term
rel->expr
equality->rel
join->equality
bool->join
stmt->loc = bool
stmts->stmts stmt
block->decls stmts
stmt->block


Leaving Scope

stmt->WHILE ( bool ) stmt
stmts->stmts stmt
block->decls stmts


Environment Table (Top - 0)
Key: i
Value: {loc=0, &int_var,0,0,NULL,NULL}

Key: j
Value: {loc=4, &int_var,0,0,NULL,NULL}

Key: v
Value: {loc=8, &float_var,0,0,NULL,NULL}

Key: x
Value: {loc=12, &float_var,0,0,NULL,NULL}

Key: a
Value: {loc=16, &float_var,1,100,{loc=16, &float_var,0,0,NULL,0x8ba4538},NULL}

Intermediate Code:
Op  Arg1    Arg2    Result
goto          Code: 0x804d47d  
+  Symbol: i  Symbol: @1  Symbol: @2  
=  Symbol: @2      Symbol: i  
<  Symbol: a  Symbol: v  Code: 0x804d47d  
goto          Code: 0x804d491  
-  Symbol: j  Symbol: @4  Symbol: @5  
=  Symbol: @5      Symbol: j  
>  Symbol: a  Symbol: v  Code: 0x804d491  
goto          Code: 0x804d44b  
>=  Symbol: i  Symbol: j  Code: 0x804d284  
goto          Code: 0x804d251  
goto          Code: 0x804d251  
=  Symbol: a      Symbol: x  
=  Symbol: a      Symbol: a  
=  Symbol: x      Symbol: a  
goto          Code: 0x804d284  
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server