Build a hash table using chaining as the collision resoultion technique. Insertions into the hash table will correspond to declarations of variables and values in a program, searches will be requests for the value of a variable. Some variables will be local and have a narrow scope while some variables will be global.

The program will take input from a file, another program written in the omnipotent programming language BORG (Bionicly Omnipotent Resistance Grinders) and generate ouput from this program.

The BORG language has the following commands (keywords):

  • START-FINISH blocks. Indicating different scopes.
  • COM - Single line comments: Text should be ignored if on the same line
  • value = expression – Assignment statements, ie GEORGE = 122. This language is not option explicit, so the statement GEORGE = 122 will put a variable into the table and associate the value 122 with it.
  • ++ - increment operator, syntax: VARIABLE ++
  • -- - decrement operator, syntax: VARIABLE --
  • expressions, expressions are limited to unary and binary arithmatic, or variable names
  • supported operators: + - / * % ^ (plus, minus, divide, multiple, modulo, exponent)
  • PRINT – syntax PRINT expression. If the expression is a variable, and this variable is not in scope, then an error message indicating unknow variable x at line number y. The value printed if there is a variable in scope should be the variable with the closest scope.
  • errors – other than the print statements, our interpreter will not be responsible for detecting errors, syntax errors should be disregarded if encountered, assume that the source file is correct.

Our hash function: sum the ordinal values of the characters of the variable multiplied by their position in the string (1-indexing), then taking the modulo by TABLESIZE.

ie. The variable ABC = (65 * 1 + 66 * 2 + 67 * 3) % TABLESIZE

All tokens are seperated by one space or a new line.

Output: for this , run your interpreter on this sample source program as well as a program of your own, and turn it the output from both, as well as the source code from your BORG program as well as source code of the assignment and its executable. Zip is good.

may implement one additional feature to the language, such as adding if, methods, more capable print statements. Only one student may implement a given extension to the language, and each extension must first be cleared with me.

Sample program and its output:
Input

COM HERE IS OUR FIRST BORG PROGRAM

COM WHAT A ROBUST LANGUAGE IT IS

START

BORAMIR = 25

LEGOLAS = 101

PRINT BORAMIR
BORAMIR ++

PRINT LEGOLAS LEGOLAS IS 25

PRINT BORAMIR * 2
COM

COM NESTED BLOCK

COM

START

GANDALF = 49

PRINT GANDALF
PRINT BORAMIR
FINISH

PRINT GANDALF
START

LEGOLAS = 1000

PRINT LEGOLAS
FINISH

PRINT LEGOLAS
LEGOLAS --

PRINT LEGOLAS
FINISH
OUTPUT
Output


BORAMIR IS 25

LEGOLAS IS 25
GANDALF IS UNDEFINED
BOARAMIR * 2 IS 50

GANDALF IS 49
BORAMIR IS 25

GANDALF IS UNDEFINED


LEGOLAS IS 1000

LEGOLAS IS 101

LEGOLAS IS 101


CAn anybody write code for this program?

Thank uu

What do you need help with? Nobody's going to do your homework for you; you need to ask yourself why you can't do this yourself and then figure out specific questions that will help you to solve the problem yourself.

If you want somebody to write the whole thing for you, offer money. But even then the person might turn you in to your professor.

In fact, searching on Google gives matches at Rent-A-Coder.


In fact, searching on Google gives matches at Rent-A-Coder.

OMG! I didn't realize this was going on. :-O And to think I have been working my buns off for the last 20 years when I could have been drinking a beer while letting RentACoder do my work. I would hope universities will expell any student who does that.

This article has been dead for over six months. Start a new discussion instead.