What is Backus-Naur Form, and what is it used for?
AnswerShow a parse tree for string aacacab according to the following grammar, where the start nonterminal is S. In this grammar, upper case letters are nonterminals and lower case letters are tokens.
S -> F a S | b F -> a F | cAnswer
Show that the following grammar is ambiguous. The start symbol is S. Upper case letters are nonterminals and lower case letters are tokens.
S -> S a | a S | aAnswer
Write a grammar that describes sequences of left and right parentheses that are balanced. A sequence of parentheses is balanced if parentheses match and are well nested. For example, (( )(( ))) is balanced, but )( and ( ))( )( are not balanced.
AnswerScheme is a typeless language. What does that mean? Can type errors ever occur?
What is the value of Scheme expression (car (cdr (cons 'horse (cons 'zebra '( )))))?
What is the value of Scheme expression (cons 'salamander (list 'frog 'toad))
Write a Scheme function called prefix so that (prefix x y) returns true if list x is a prefix of list y (and false if not). It is not necessary for x to be a proper prefix of y. Every list is a prefix of itself, and the empty list is a prefix of every list. Be careful to use Scheme syntax correctly.
Write a Scheme function called descending so that (descending L) is true for a list of numbers L if L is in descending order. (The Scheme function < does a less-than test, and > does a greater-than test.) List (a b c d) is in descending order if a > b > c > d. The empty list is in descending order by definition, as is a singleton list. Be careful to use Scheme syntax correctly.
Write a Scheme function called drop so that (drop n L) returns the result of removing the first n members from list L. If L has fewer than n members, then (drop n L) should return the empty list. For example, (drop 2 '(4 8 3 5 7)) = (3 5 7) and (drop 3 '(5 2)) = ( ). Be careful to use Scheme syntax correctly.
Write the filter function in Scheme. That is, write a filter function so that (filter f L) returns a list of all members x of list L such that (f x) is not #f. Be careful to use Scheme syntax correctly.