Project-1---Parser is a project mainly written in RUBY and C, it's free.
Parser for a subset of the C language
README file for CS 5363 Project 2 submission
Troy Toman [email protected]
This parser currently recognizes all token types and language constructs as specified in the Project 1 guidelines. It was corrected based on Project1 feedback to handle: nested if fails else if fails var dec + initialization fails complex expression evaluation fails commenting fails keywords cannot be identifiers I believe these are all working correctly at this time. The program has been updated for project 2 so that it produces a type-checked AST. The tree can be printed to the screen or converted to json format. The resulting json format can be then used to re-create the AST tree.
This project was implemented using the Ruby language and leverages a Ruby Parser library called Treetop which is available as open source.
You can find more information about Treetop at
http://treetop.rubyforge.org/
INSTALLATION INSTRUCTIONS
You must install Ruby on the system
Once Ruby is installed you must install the Treetop gem
At this point you can run the program with the following command:
ruby project1.rb
You will be prompted for an input file. I have provided "testinput.c" which contains the sample input from the project specification. I have also included "badtestinput.c" which has a syntax error and will be rejected by the parser.
In this version of the program, a json version of the tree will be output in addition to printing out the tree on the screen.
CURRENT STATE OF THE COMPILER
- The project is complete as specified.
- Type checking will validate int variables are not assigned a float value.
- Type checking does allow float variables to be assigned integer values
- Type checking also validates that only integers are used as array indices
- Known bugs: None known.
PROJECT TESTING
I tested the program manually with the two input files mentioned above.
I also used TDD (test driven development) to build the program using a tool called Rspec. You can run the unit test by installing Rspec:
gem install rspec
To run tests (with little output) use following command (assuming rspec 2.0):
rspec parser_spec.rb --format d
To run tests (with verbose output) use following command (assuming rspec 2.0):
rspec parser_spec_w_print.rb --format d
if you are running a prior version of rspec then the command is:
spec parser_spec.rb --format specdoc
In parser_spec.rb and parser_spec_w_print.rb, you will find the tests used on the project. I have incorporated the additional tests that were provided after the Project 1 feedback.