Skip to content

lucianHymer/cs440Final

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AUTHORS:
Lucian Hymer
Jack Kerby

DESCRIPTION:
This is a compiler for the z-plus language. This is only a demo, demonstrating
the function of if/then/else, getn(), and basic for-loops.

USAGE:
  # Build both the compiler and pstack:
  bnfc -cpp_stl -m ./zp.cf
  make
  make -f Makefile.codegen

  # Compile fib.cmm, producing fib.apm:
  ./compiler fib.cmm fib.apm

  # Disassemble fib.apm:
  ./pstack/apd fib
  # Execute fib.apm:
  ./pstack/api fib

  # Test with (note that this script
  # is modified from the original)
  ./test.sh myTESTS

FILES:
  * Makefile.codegen
      * The Makefile for `zp2pstack`
  * zp.cf
      * Grammar of the zp language used by `bnfc`
  * Absyn.C/H
      * Abstract syntax tree files generated by `bnfc`
  * zp.l/y
      * Flex and Bison files generated by bnfc
  * codegen.cc/h
      * Defines the p-code generation class
  * Lexer.C/H
      * Lexer files generated by `bnfc`
  * Parser.C/H
      * Parser files generated by `bnfc`
  * Parser.C/H
      * Printer files generated by `bnfc`
  * pstcode.cc/h
      * Implements prolog functions such as `getnum()`` and other functions
  * Skeleton.C/H
      * Skeleton files generated by `bnfc`
  * symbtable.cc/h
      * Defines the Symbol and SymbolTable classes
  * typescript
      * Script of the tests being run
  * myTests
      * Directory containing the tests
  * pstack
      * Directory containing the pstack supplied by the instructor
  * test.sh
      * Test script

BUILT-IN-FUNCTIONS:
  The cmm standard library contains these functions:

  exit()       : ends the program immediately
  puts("...")  : prints a string (only literal strings are supported)
  putn(int)    : prints an integer (like printf("\t%d\n", int))
  putd(double) : prints a double (like printf("\t%d\n", double))
  getnum()     : gets an integer
  itod(int)    : returns int as a double
  dtoi(double) : returns double as an integer

All functions return a value.

IMPLEMENTED-FEATURES:
  * if and if-else: **Complete**
  * for2-loop: **Complete**
  * for3-loop: **Complete**
  * Optimization: **Complete**
  * Globals: **Complete**
  * repeat-until-loop: **Complete**
  * Scoped for-loop: **Complete**
  * Argument count checking: **Complete**
  * Type checking: **Complete**
  * Doubles: **Complete**

EXTRA-FEATURES:
  * itod and dtoi      : Built-in functions to typecast between ints and doubles
  * multiple arguments : Functions work with multiple arguments

DEVELOPERS NOTES:
We tried to modify the existing structure as little as possible. The most difficult part was typechecking.
For function parameters and arguments, it was not too difficult because all types were evaluated in the
visitFunc and visitCall definitions respectively. So, we just pass the parameter type list when creating a function symbol
and this creates an ArgumentChecker object which can be called at function call time with the list of argument types. Same
for the return value. After doing this, however, we realized that typechecking involved much more than checking function argument
and return types. So, we had to modify most visit* calls to set currtype at the correct time.
It was difficult to implement doubles as well. We had to change most I_ calls to check the type, and it took a while
to realize we needed to call I_TO_R when loading in a double. We also had to find some way to deal with mixed
types. We decided to disallow mixing types, and provided builtin typecasting functions itod and dtoi.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published