Problem Consider the following partial grammar: We have a datatype s to represent this: data S = S1 Char S Char S2 Char
Posted: Fri Jul 01, 2022 5:47 am
Problem Consider the following partial grammar: We have a datatype s to represent this: data S = S1 Char S Char S2 Char E deriving (Show, Eq) This grammar is LL. Write the corresponsing parsing function parses: [Char] -> (S, [Char]) that takes a list of characters and returns the corresponding s tree and remaining input. You can assume the existence of a properly written parsee that you may call, and that the E portion of the grammar (not shown here) introduces no ambiguities. If you need to test locally, you can pretend that E accepts any character given to it, and use this function: data E = E [Char] deriving (Show, Eq) S→ x Sy | ZE parseE parseE (x:xs) = (E [x], xs) Please don't submit that with your code or you will break the autograder and not get credit. Example [Char] -> (E, [Char]) Lib.hs Prelude> parses "xxxzayyy" (S1 'x' (S1 'x' (51 'x' (52 'z' (E "a")) 'y') 'y') 'y', []) Your Solution Starter Code 1 parses: [Char] > (S,[Char]) 2 parses = undefined