Report on CHAD Designed Implemented and Documented by Haronil Estevez Diana Jackson Catherine MacInnes Adam Rosenzweig Table of Contents Introduction the white paper Language Tutorial Language Reference Manual Project Plan Architectural Design Test Plan Lessons Learned Appendix A Sample test code and write ups Appendix B Complete Listing of Interpreter Code WHITE PAPER Language Overview The instruction of computer science is often hampered by the abstract nature of programming Data and data structures are represented in programs with formal language and some students have difficulty visualizing what is actually going on This problem is made worse when the data structures are manipulated in algorithms even ones as simple a searches and sorts Instructors are often reduced to drawing crude illustrations on the board or even calling on students to act as array elements It is our belief that many instructors would appreciate a way to easily illustrate these data structures and algorithms in the context of a program which could then be included as part of a class demonstration We hope to implement some of the more common complex data structures in a language that is syntactically and semantically easy to extend to other data structures Goal The goal of our language is to allow instructors to quickly and easily write algorithms pertaining to the arrays queues and stacks which are then illustrated through the interpreting process To this end CHAD provides a set of basic functions for each of the native data types which allow them to be easily manipulated in the context of the language and which the interpreter then knows how to illustrate Easy to Use One of the main goals of this language is to make the illustration of data structures and algorithms easy To this end we will implement a syntactically simple language sacrificing power for simplicity The language will be able to express certain data structures and algorithms very succinctly at the expense of not being able to express other data structures at all We will also maintain a syntactic style that will be familiar to users of other common programming languages Complex Native Data Types Programming in our language will be oriented around a small number of native types which include the complex data types arrays queues and stacks In the future the language could easily be extended to include other complex types such as linked lists or trees Portable One of the things which is most important in terms of actually making CHAD useful is that it will be extremely portable Instructors will be able to run CHAD programs anywhere and can even make them available for students online This is possible because the CHAD interpreter will be written in Java and will be the only thing necessary to run a CHAD program Language Tutorial CHAD Tutorial Section I Getting Started with Basic Operators Control Statements Section II Working with Integers Strings Arrays Queues Stacks Section III Writing your own Functions Section IV Displaying with CHAD GUI Section V Simple Example Section I a Basic Operators Provided below is a table listing all of the supported CHAD operators along with a description Operator Description Assignment Assigns a value to a variable Addition Adds integers Concatenates strings Subtraction Multiplication Division Increment Decrement Parentheses Subtracts integers Denotes Negation Multiplies integers Divides integers Increases integer variable by 1 Decreases integer variable by 1 Specifies which operations to evaluate first Examples int i 0 string s1 string int j 1 string s2 s int k j i k 1 string s3 s1 s2 s3 strings k k j k 0 k 1 k 3 4 k 12 k 12 3 k 4 k k 5 k k 4 k 5 4 2 k 18 because the 5 4 is evaluated first then multiplied by 2 Comparison Operators Description Examples In each of these cases as well as cases to follow in the Logical Conjunction Operators section 0 is returned if the comparison yields a false result 1 is returned if it yields a true one Typically these comparison operators will be used in the context of an if statement but for the purpose of demonstrated its use that notion is not demonstrated here Compares both sides of operator k 18 returns 1 IsEqualTo for equality Compares both sides of operator to see if the right is greater than k 19 returns 0 IsGreaterThan the left Compares both sides of operator to see if the right is less than the k 19 returns 1 IsLessThan right Compares both sides of operator IsGreaterThanOrEqualT to see if the right is greater than or k 15 returns 1 o equal to the left Compares both sides of operator IsLessThanOrEqualTo to see if the right is lessgreater k 15 returns 0 than or equal to the left Logical Conjunction Description Examples Operators Signifies logical conjunction of K 15 AND K 20 true AND two expressions Signifies logical disjunction of OR K 15 OR K 1 true two expressions Signifies logical negation of an NOT NOT K 15 true expression Section I b Control Statements For Loops allow a block of code to be run multiple times The syntax is as follows for int i 0 i 10 i statements endfor The first parameter takes an integer for which the iteration should begin The second parameter specifies when the iteration will end In this case the range will be from zero to 9 The third parameter specifies that the integer variable will increment with each iteration Next statements represent whatever action you want to occur with each iteration of this loop Finally a for loop must be ended with the keyword endfor If Then Else Statements allow statements to be executed provided that a test expression proves true Let s say for example that you have the numbers five and six You would like to assign the variable i to be equal to the greater of the two Here is the code int int5 5 int int6 6 int i if int5 int6 i int5 endif else i int6 endelse Additionally you can use an elseif statement if you want to check multiple expression prior to resulting to the execution of the statements in the body of the else block Finally an important point to mention is that regardless of which type you use each must be ended with the appropriate keyword if endif elseif endelseif else endelse Section II a Integers Integers must be in the range of 999 to 999 The syntax along with the relevant operators has been demonstrated previously See Section on Operators One function associated with integers is the min and max function They both take two integer arguments and return the smaller or greater of the two respectively Note
View Full Document
Unlocking...