CS112_45_Assignment7A

# CS112_45_Assignment7A - CS112 Assignment 7A Problem 1...

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

CS112 Assignment 7A Problem 1: Substitution in Trees In mathematics, there are several common procedures that require you to replace all instances of a variable in a formula with some other variable. Working entirely at the client level of exp.h , write a function expressionADT ChangeVariable(expressionADT exp, string oldName, string newName); that returns a new expression which is the same as exp except that every occurrence of the identifier oldName is replaced with newName . For example, if exp is the expression calling newExp = ChangeVariable(exp, "x", "y"); will assign the following expression tree to newExp : Problem 2: Recognizing a Language Write a program capable of recognizing whether an expression typed in by the user is a valid sentence, where the following rules define the grammar. S -> <name>P P -> T P -> TP T -> [<int>] These rules are actually the rules for statically declaring arrays in C. The following are examples of valid sentences:

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

View Full Document
x[1] abc[42] y[1][2][3][4][5] The program will be easiest to write if you make use of the
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/06/2010 for the course CS 112 taught by Professor Yinlinwang during the Spring '08 term at Shanghai Jiao Tong University.

### Page1 / 3

CS112_45_Assignment7A - CS112 Assignment 7A Problem 1...

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

View Full Document
Ask a homework question - tutors are online