Programming Assignment 2 (Scheme)

Final - with base programs for help

DUE: Feb 27 by midnight


You are to complete as many of the following as you can. You have 10 days from the date of assignment. This is individual work BUT you may discuss it in general terms (NOT lines of code)

E-mail your answers to me (drkriggs ...) by the due date.

POSTING: I will post all submitted code solutions by the May 1 (no late work allowed!)


1.        Report (a version of "control break processing")
Given a facts of the sort:      
   BUSINESS ::=  '('  STOREFACT*  ')'
   STORE FACT ::= '(' NAME  (‘(‘ 'sale' AMOUNT’)’ | ‘('expense' AMOUNT’)’ ) + ')'
                            where
   AMOUNT ::= number
   NAME ::= identifier
Calculate and printout:
1.              The profit for each store  (å sales -å expenses) 
2.              The profit for all stores as a value
 
RSLT ::= ‘(‘ totalProfit  (NAME storeProfit)* ‘)’
TotalProfit, storeProfit ::= number
 
i.e. define a function (profit stores)
Base code (if you want to use it!)

2.     Matrix Addition

     MAT ::= '(' ROW* ')

     ROW = '(' NUM* ')'

 

Assume matrices are proper, return the array C which is the sum of the two input parameters

 

BASE CODE


3.     Parsing  ( a form of sentential logic called "postfix")

Write a function to parse a list (sequence) of symbols  
 
Determine if the sequence is valid by the following grammar:      
                                             
   PROP ::= ATOM |   PROP UNIOP | PROP PROP BINOP
   ATOM ::= 'A' | 'B' | 'C' | 'D' | 'E' | 'F'
   UNIOP ::= 'not'
   BINOP ::= 'and' | 'or' | 'if' | 'iff'
 
Return the value "valid" or "in-valid" as the case may be from the function (parse stack string)
 
BASE CODE

4.     Path Cost ('distance' in a directed, weighted graph (i.e. a weighted digraph))

Given facts of the sorts:
 
   GRAPH ::= '(' NODES EDGES ')'
   NODES ::= ’(‘ NAME* ‘)’
   EDGES ::= ‘(‘ EDGE* ‘)’
   EDGE  ::=  ‘(‘ SRC TRGT COST ‘)’
   START ::= NAME
   GOAL ::= NAME        
 
PATH ::= '(' pathCost NODE+ ')'
                         
                           where 
   SRC, TRGT ::= NAME                                    
   NAME  ::= symbol
   COST, pathCost ::= number
 
If there is a path from start to end, return the shortest such path.                                                                                                                             

      I.e. define   (shortestPath src trgt graph))

      BASE CODE