Pr1 - COP4020 Programming Assignment 1 Spring 2011 In this...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
COP4020 Programming Assignment 1 - Spring 2011 In this programming assignment we design and implement a small imperative program- ming language “Micro-PL”. To execute Mirco-PL code we translate the code to Scheme and execute it in Scheme. This translator/compiler for Micro-PL will be written in Scheme. The objective of this assignment is to apply programming language design principles, implement program translation, and practice Scheme programming. For the Scheme pro- gramming we use the most common Scheme programming constructs discussed in class and some extras that will be explained in this document. A New Programming Language Micro-PL Our Micro-PL programming language is imperative. It adopts a procedural style pro- gramming with side effects (explicit state changes by variable assignment). Our Micro- PL programming language supports assignments to variables, function calls (including functions to perform arithmetic), programming statement sequences, if-then-else control flow, and loops. Micro-PL is dynamically typed, so any type of value can be assigned to a variable as long as the variable is declared in the outer scope. The syntax of Micro-PL is relatively simple and is designed to simplify reading and pars- ing of Micro-PL programs by our translator/compiler. By keeping the syntax simple we do not need to implement advanced parsing techniques for our translator. Our transla- tor looks for keyword commands to trigger a translation to Scheme. As a consequence, Micro-PL programs have a command-based appearance. Each programming statement starts with a keyword command. The following commands are supported. The set command assigns a value to a variable. For example: set greeting = ”Hello, world!” assigns a string value to foo . The begin command is used to sequence a series of statements in a begin . . . end block, for example: begin set foo = 0 set bar = 1 end 1
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
which is similar to all Algol-like programming languages (C/C++ and Java use { . . . } instead). In our Micro-PL programming language we do not use semicolons to sepa- rate or terminate statements (taking a neutral position in the semicolon wars). State- ments are simply chained together by white space (blanks, tabs, and newlines). Local variables are declared with the declare command that is followed by a be- gin . . . end block in which the variables are visible (are “in scope”). Thus, variables have a local scope, limited to the scope of the block. Each variable must be initial- ized. This requirement prevents any accidental use of uninitialized variables and values. (The use of uninitialized values is a typical programming error that can sometimes, but not always, be flagged by a compiler.) For example: declare foo = 0 bar = 1 begin set foo = bar end where foo and bar have a local scope and are initialized to 0 and 1, respectively. The value of foo is reassigned in the block. The local scope means that the values of foo and bar are not accessible outside of the scope of the declare . . . begin . . . end block.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern