Finally Done with the Semester-long Project

Above you will find a project that is the accumulation of approximately 60 hours of coding over the semester.  The language we are parsing was created by the professor and its details can be found below.  The parser shown was built from the ground up.  In other words, I made the Lexer for it, a wrapper class for c-strings, a wrapper class for an input file stream, a ternary tree to hold data structures, and the underlying calculator program that actually processes the instruction written in the professor’s language.  It is the best feeling in the world after tens of hours of debugging to have something this big run the way it should.

 Specifications of the PCALC, a programmable calculator.

PCALC consists of a screen, room for 10 variables, and a stack of size 20.  It operates on doubles.

The syntax of programs that can be run on PCALC are given at http://www.lehigh.edu/~ejk0/pcalc.jpg

Using my emulation of PCALC

The emulator is located in the file:/proj/csc109/bin/pcalc

The call to the file takes the form pcalc <input> [-v]

where <input> is the input file that contains the PCALC program and –v is an optional command that leads to more verbose output.

The input file for pcalc should consist of lines of code, followed by “end”, followed, possibly, by a single line of input data. On any line of code(including blank lines) the dollar sign ($) and all text following the dollar sign are ignored.

Lines can be labeled

A stack operation (e.g., “stack +” ) pops two items, performs the operation <op> in the order <2nd item popped> <op> <first item>, and pushes the result.

The operation “pop” pops the top of the stack and stores it in screen.

The “push” operation pushes the contents of the screen onto the stack.

The operation “getScreen” displays the contents of the screen on the console.

The operation “clear” (without any argument) sets the screen to 0.

The operation “clear <IDENT>” (where <IDENT> is a variable

specfied by an identifier as described by the syntax diagram for IDENT) sets the contents of <IDENT> to 0.  If the <IDENT> had not been previously used, it is created (unless there is no room for any more variables, in which case pcalc crashes).

The operation “enter” reads a number from the last line in the program file (the line after “end”) and stores the number on the screen. If there is no number, pcalc crashes.

The operation “enter -<NUMBER>” stores the given value on the screen.

The operation “enter <IDENT>” stores the contents of the variable <IDENT> on the screen.

The operation “<IDENT> +” adds the contents of the screen to the

contents of the given variable.

An arithmetic operator followed by a variable or a number (e.g., “* <IDENT>” or ” / <NUMBER>”) performs the operation given with the screen on the left hand side and the <IDENT> or <NUBMER> on the right hand side, and then it stores the result on the screen.

The operation “jump <IDENT>” jumps to the line with label <IDENT>.

The operation “jumpL <IDENT>” jumps to the line with label <IDENT> if the contents of the screen is less than 0.

The operation “jumpG <IDENT>” jumps to the line with label <IDENT> if the contents of the screen is greater than 0.

Specifications of the FPCALC, a programmable calculator.

FPCALC is an enhanced version of PCALC. It has more “jump” instructions, and it can push the results of arithmetic expressions on the stack.  See above for instructions on how to use PCALC. Below I provide only information about the enhancements to PCALC that are provided by FPCALC.

Using my emulation of FPCALC

The emulator is located in the file: /proj/csc109/bin/fpcalc

The call to the file takes the form fpcalc <input> where <input> is the input file that contains the FPCALC program.

The input file for pcalc should consist of lines of code, followed by “end”, followed, possibly, by a single line of input data. On any line of code (including blank lines) the dollar sign ($) and all text following the dollar sign are ignored.

The “push <arithmetic expression>” operation pushes the results of computing the given <arithmetic expression> onto the stack. E.g., push 2*x/(3-y).

The operation “jumpLE <IDENT>” jumps to the line with label <IDENT> if the value of the screen is less than or equal to 0.

The operation “jumpGE <IDENT>” jumps to the line with label <IDENT> if the value of the screen is greater than or equal to 0.

The operation “jumpE <IDENT>” jumps to the line with label <IDENT> if the value of the screen is equal to 0.

The operation “jumpNE <IDENT>” jumps to the line with label <IDENT> if the value of the screen is not equal to 0.

Advertisements

About lumax15

My name is Maxwell S. Smith and I am getting dual degrees in Computer Science and Cognitive Science. I hail from Lebanon, PA which is about 15 minutes from Hershey Park and 40 minutes from Lancaster(Yes I have seen horse and buggies. No I am not Amish or Mennonite). As a person I like to work hard and play hard. I enjoy philosophy and deeper level thinking. Recreationally I enjoy doing things in nature like fishing and camping as well as playing video games. At Lehigh, I am involved with the local chapter of the ACM and I am a member of the Chi Phi Fraternity. In the fraternity I am currently our steward and Web/PR chair. Junior spring and senior fall I aspire to be the president. Generally I balance my academic life with my social life well and enjoy life as a whole. My life motto: "The only thing we know for sure is that we know nothing at all"
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s