CS112_37_Assignment_5B - CS112 Assignment 5B Due date May...

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

View Full Document Right Arrow Icon
CS112 Assignment 5B Due date: May 26 In this assignment, your mission is to build an interpreter for a simplified version of the language BASIC. This assignment is designed to accomplish the following objectives: l To give you practice working with trees and function pointers. l To provide you with a better sense of how programming languages work on the inside. Learning how programming languages work helps you develop valuable intuition about the programming process. l To allow you to implement a recursive descent parser. What is BASIC? The programming language BASIC—the name is an acronym for Beginner ’ s All-purpose Symbolic Instruction Code—was developed in the mid-1960s at Dartmouth College by John Kemeny and Thomas Kurtz. It was one of the first languages designed to be easy to use and learn and remains popular as a medium for teaching programming at the elementary and secondary school level. In BASIC, a program consists of a sequence of numbered statements, as illustrated by the simple program below: 10 REM Program to add two numbers 20 INPUT n1 30 INPUT n2 40 LET total = n1 + n2 50 PRINT total 60 END The line numbers at the beginning of the line establish the sequence of operations in a program. In the absence of any control statements to the contrary, the statements in a program are executed in ascending numerical order starting at the lowest number. Here, for example, program execution begins at line 10, which is simply a comment— the keyword REM is short for REMARK — indicating that the purpose of the program is to add two numbers. Lines 20 and 30 request two values from the user, which are stored in the variables n1 and n2 , respectively. The LET statement in line 40 is an example of an assignment in BASIC and sets the variable total to be the sum of n1 and n2 . Line 50 displays the value of total on the console, and line 60 indicates the end of execution. A sample run of the program therefore looks like this: ? 2 ? 3 5
Background image of page 1

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

View Full Document Right Arrow Icon
2 Line numbers are also used to provide a simple editing mechanism. Statements need not be entered in order, because the line numbers indicate their relative position. Moreover, as long as the user has left gaps in the number sequence, new statements can be added in between other statements. For example, to change the program that adds two numbers into one that adds three numbers, you would need to make the following changes: 1. Add a new line to read in the third value by typing in the command 35 INPUT n3 This statement then goes logically between line 30 and line 40. 2. Type in a new assignment statement, as follows: 40 LET total = n1 + n2 + n3 This statement replaces the old line 40, which is no longer part of the program. If you just want to delete a line from a program
Background 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 ]}

Page1 / 15

CS112_37_Assignment_5B - CS112 Assignment 5B Due date May...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online