Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 2 (15 Points) I Add list manipulation expressions to the allowed expressions the mython language. We allow list expressions (use a new non terminal
Problem 2 (15 Points) I Add list manipulation expressions to the allowed expressions the mython language. We allow list expressions (use a new non terminal called ListExpr). Formally, a list expression is defined as one of the following: The empty list use a constructor symbol EmptyList. It should not have arguments. A new list made up of zero or more arithmetic expressions: use constructor symbol NewList. It has as arguments a list of arithmetic expressions. Use Kleene-star in your grammar to specify one or more of". Appending an arithmetic expression to the front of a list: use constructor symbol Cons. Cons must have two arguments: first argument is an arithmetic expression and second argument is a list expression. Concatenate two lists defined by list expressions: use constructor symbol Concat. must have two arguments that are both list expressions. Filter elements of a list which meet a certain condition: use constructor symbol Filter. It must have three arguments: (a) a list expression denoting the list being filtered, (b) an identifier name (use the nonterminal Identifier), and (c) a conditional expression capturing the filtering criterion. We would use such an expression, for instance, as following: filter (x in my_list) where x>. This would create a new list with all elements x from my_list where x>0. Next, we add the following rule to CondExpr (conditional expressions): A condition expression to check if a list is empty: Use constructor IsEmptyList . Its argument must be a list expression that we check for emptiness. Finally, we add a special foreach loop statement over the elements of a list. foreach (x in list_expr) begin .. list of statements... end Add a statement to loop over the elements of a list use constructor ForEach. Its arguments must include (a) the identifier, (b) the list expression to be iterated over and (c) the body of the loop (list of statements). Write down the extra grammar rules that you would add to the overall mython grammar to create these functionalities. YOUR ANSWER HERE Problem 2 (15 Points) I Add list manipulation expressions to the allowed expressions the mython language. We allow list expressions (use a new non terminal called ListExpr). Formally, a list expression is defined as one of the following: The empty list use a constructor symbol EmptyList. It should not have arguments. A new list made up of zero or more arithmetic expressions: use constructor symbol NewList. It has as arguments a list of arithmetic expressions. Use Kleene-star in your grammar to specify one or more of". Appending an arithmetic expression to the front of a list: use constructor symbol Cons. Cons must have two arguments: first argument is an arithmetic expression and second argument is a list expression. Concatenate two lists defined by list expressions: use constructor symbol Concat. must have two arguments that are both list expressions. Filter elements of a list which meet a certain condition: use constructor symbol Filter. It must have three arguments: (a) a list expression denoting the list being filtered, (b) an identifier name (use the nonterminal Identifier), and (c) a conditional expression capturing the filtering criterion. We would use such an expression, for instance, as following: filter (x in my_list) where x>. This would create a new list with all elements x from my_list where x>0. Next, we add the following rule to CondExpr (conditional expressions): A condition expression to check if a list is empty: Use constructor IsEmptyList . Its argument must be a list expression that we check for emptiness. Finally, we add a special foreach loop statement over the elements of a list. foreach (x in list_expr) begin .. list of statements... end Add a statement to loop over the elements of a list use constructor ForEach. Its arguments must include (a) the identifier, (b) the list expression to be iterated over and (c) the body of the loop (list of statements). Write down the extra grammar rules that you would add to the overall mython grammar to create these functionalities. YOUR ANSWER HERE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started