According to the silent policy, no questions asked in any form after
11:00 pm, Thursday, February 2nd will be answered. Please ask any
questions and ask for clarification early.
A - All strings over the alphabet {a, b, c, d} with at least four instances of c and at least two instances of a
B - All strings over the alphabet {a, b, c, d} where there are more a's than d's
C - All strings over the alphabet {a, b, c, d} where no b is immediately followed by an a and no c is immediately followed by a d.
D - All binary (alphabet {0,1}) strings which represent integers in the Fibonacci series (integers encoded in the normal way, no leading zeros)
E - All binary strings which represent multiples of 3 (all strings are nonnegative integers encoded in the normal way).
F - All strings over the alphabet {a, b, c, d} where there are at least three times as many a’s as b’s
We have the following binary operations:
Addition (+), Subtraction (-), Multiplication (*), Division (/).
We do not have unary negation in this system, and we consider negative integers to be integers.
We do not need parentheses () for grouping, except for unary negation. For example
1 + 1 is in infix notation.
+ 1 1 is the same thing in prefix notation
16 / ( -5 + 3) - 8 is in infix notation
- / 16 + -5 3 8 is its equivalent prefix form
(4 + 5) * 12 / 13 - 4 * -2 in infix becomes
- / * + 4 5 12 13 * 4 -2 in prefix
Write a context-free grammar for arithmetic on integers in prefix notation. Be sure to define your terminals.
The first line of your file should be: #lang racket
Your code will be run on the mathlab system, using Doctor Racket.
Your task is to write a scheme program that takes, as input, a fully parenthesized infix arithmetic expression (with binary operators +, - *, and / ), and to turn it into a fully parenthesized prefix expression. Your function should be called infix_to_prefix and it should be called as follows:
(infix_to_prefix '((16 / ( -5 + 3)) - 8))
>(- (/ 16 (+ -5 3)) 8)
(Note - the quote needs to be there for execution, and initially the output expression was not fully parenthesized)
You may not use any of the imperative features of scheme, this includes all of the functions beginning with "!". Your solution should be properly tail recursive. You should create your solution as much as possible from the only the basic functions you've learned in class: first, rest, cons, and the predicates list? and eq?. You are expected to code in a functional style, and to make your code as readable as possible. Your code should be commented as necessary, and include a brief comment explaining your algorithm.