Write a regular expression denoting the set of all passwords

Assignment Help Programming Languages
Reference no: EM132241869

Programming Assignment -

This is a programming assignment in F#, with some additional non-programming questions. You can do it alone or in a team two people. In the latter case, you are responsible for contacting other students and form a team.

Download the accompanying F# source file hw.fsx and enter your solutions in it where indicated. When you are done, submit it as instructed on Piazza.

In the following problems do not use any mutable variables (i.e., variables declared with let mutable) or any mutable predefined types such as references, mutable records, arrays, and so on. Define your functions recursively as needed and take advantage of the match operator.

You do not need, and should not use, any F# library functions except for the usual integer and Boolean operators, the list operators :: , [ ] , @, List.length and the conversion function string. However, you can use your own auxiliary functions if you prefer.

1. Processing arithmetic expressions

For this assignment we will consider a language of expressions over integers similar to those seen in class and the previous homework. This language contains C-style Boolean operators that treat 0 as false and any non-zero number as true. The abstract syntax of the language is provided by the following F# types:

type operUna = Neg | Not

type operBin = Add | Mul | Sub | Gt | Eq | And

type expr =

| Cst of int

| OpUna of operUna * expr

| OpBin of operBin * expr * expr

| IfElse of expr * expr * expr

Types operUna and operBin define the operators used in the expression language, where Neg is integer negation, Not is Boolean negation, Add is integer addition, Mul is integer multiplication, Sub is integer subtraction, Gt is integer > comparison, Eq is integer equality, and And is Boolean conjunction. Neg and Not are unary operators, all the others are binary.

In type expr, constructor Cst constructs expressions consisting of an integer constant, OpUna constructs the expression obtained by applying a unary operator to another expression, and OpBin constructs the expression obtained by applying a binary operator to two other expressions. Finally, IfElse constructs conditional expressions as in Homework 1: an expression IfElse(e, e1, e2) evaluates to the value of e2 if e evaluates to 0, and evaluates to the value of e1 otherwise.

We start with a set of warm up problem involving the processing of expressions.

1. Using pattern matching, define a recursive function drop : int -> 'a list -> 'a list that takes a non-negative integer n and a list l and drops the first n elements from l, that is, returns a list containing, in the same order, all the elements of l but the first n. The function should raise an error, with failwith, if n is greater than the length of the l.

2. Using pattern matching, define a recursive function size : expr -> int that returns the size of its input expression defined as the number of constructors from type expr in the expression.

3. Using pattern matching, define a recursive function subexpressions : expr -> expr list that takes an expression e and returns a list consisting of all the subexpressions of e, excluding e itself. The subexpressions can appear in the list in any order you choose. However, if some subexpression occurs multiple times in e it should occur the same number of times in the output list.

2. Compiling expressions to stack machine code -

We will consider a stack machine like the one seen in class to evaluate expressions in the language of Part 1. This time, the stack machine has operations encoded by the following F# type:

type sInstr = SCst of int | SAdd | SSub | SMul | SNeg | SGt | SIfze of int | SJump of int

The machine instructions SCst, SAdd, SSub, SMul, and SNeg have the same behavior as the corresponding instructions discussed in class. The new instructions have the following behavior:

  • SGt replaces the two topmost elements in the stack with 1 if the element below the top element is strictly greater than the top element; and with 0 otherwise.
  • SIfze n, where n is a non-negative integer, is a goto instruction that causes the machine to skip the next n instructions if the top of the stack is 0, and to skip no instructions otherwise. In both cases, it pops the top element from the stack.
  • SJump n, where n is a non-negative integer, is a goto instruction that causes the machine to skip the next n instructions unconditionally, leaving the stack unchanged.

Write the following functions for compilation to and execution on the stack machine.

1. Using pattern matching, define a recursive function scomp : expr -> sInstr list that compiles expressions to stack machine programs similarly to the function rcomp seen in class. The source language of expressions has operators that do not map directly to machine operations. Part of your job is to figure out, on paper first, how to encode each source language operator in terms of the available machine operations.

For this problem, you may find it convenient to use the library function List.length that takes a list and returns its length (i.e., the number of elements in it).

2. Using pattern matching, define a recursive function seval : sInstr list -> int list -> int that executes machine programs similarly to the function reval seen in class. The first argument is the list of instructions to execute and the second argument is the stack. For this problem, you may find it convenient to use the function drop defined in a previous problem.

Note: For testing purposes, a machine interpreter is already provided in hw.fsx by the function run that takes a list of machine instructions and executes them with seval, starting with the empty stack.

3. Using pattern matching, define a recursive function byteCode : sInstr list -> string that takes a list of stack machine instructions and compiles it into a byte code program, a string consisting of numbers separated by a single space. Use byte codes 0 to 7, respectively, for SCst, SAdd, SSub, SMul, SNeg, SGt, SIfze, and SJump, in that order.

Make sure not to have any spurious spaces in the output string|for instance, at the beginning or at the end.

4. Using pattern matching, define a recursive function beval : int list -> int list -> int that takes as input a byte code program (as a list of integers) and a stack (also as a list of integers), and executes that program on the given stack. The function should raise suitable errors if the input program is ill formed in one way or another.

Your implementation should be such that, for all expressions e, (beval (parse (byteCode (scomp e))) []) returns the same result as (seval (scomp e) []), where parse : string -> int list is a function (provided in hw3.fsx) that converts an input byte code program to the list of numbers in it.

3. Regular Expressions -

For this part, write your answers in an F# comment. For compactness, if you need to use a certain subexpression more than once, you are allowed to give it a name and use that name instead. For instance, instead of writing

(0 + 1)11(0 + 1)*

you are allowed to write something like

B11B* where B = 0 + 1

You must use exclusively the regular expression operators ", *, + and juxtaposition for sequential concatenation.

1. Write a regular expression that generates all and only the words over the alphabet 0, 1 that contain at most two occurrences of 0.

2. Many programming languages use the exponential notation for large floating point constants.

For instance, 6:022E23 or 6:022e23 which both stand for 6:022 x 1023, and 1:6e 35 which stands for 1.6 x 1035. The notation consists of a numeral followed by a period (:), followed by one or more digits, followed by E or e, followed possibly by -, followed by a numeral.

Write a regular expression that captures all numbers in exponential notation.

3. Consider the following set of requirements for passwords:

(a) They can contain only letters and digits.

(b) They must contain at least one letter and one digit.

Write a regular expression denoting the set of all passwords that satisfy these requirements. For brevity, use L and D, to denote, respectively, an arbitrary letter and an arbitrary digit.

Attachment:- Assignment Files.rar

Reference no: EM132241869

Questions Cloud

What is meant by the blurring of the sectors : What is meant by the “blurring” of the sectors? In what ways does this occur?
Define the concepts of organizational environment : Define the concepts of organizational environment and the environmental domain.
How you would go about implementing a health information : Discuss how you would go about implementing a health information technology (HIT) strategic plan for data security, privacy, and quality management
Developing was put online as fully functional beta version : Hannah’s project crossed a major milestone: The Web site she and her team are developing was put online as a fully functional beta version of the site.
Write a regular expression denoting the set of all passwords : This is a programming assignment in F#, Write a regular expression denoting the set of all passwords that satisfy these requirements
Revise your memo for mechanical accuracy and effective use : Did you observe your presentation with an objective eye and impartially notice your strengths and weaknesses rather than being overly critical or defensive?
What was exact amount paid in liquidated damages : What was the exact amount paid in liquidated damages by Tacoma Narrows Contractors for the construction delays on the third Tacoma National Bridge?
Team members have been members of various other projects : Nancy’s new team members have been members of various other projects at the data-processing company that they all work for.
Evaluate operational performance and market trends : Compare and Contrast the use of data analytics in a data-driven society without the use of a proper IT software program to collect business intelligence.

Reviews

len2241869

2/24/2019 10:41:45 PM

This is a programming assignment in F#, with some additional non-programming questions. You can do it alone or in a team two people. In the latter case, you are responsible for contacting other students and form a team. Download the accompanying F# source file hw.fsx and enter your solutions in it where indicated. When you are done, submit it as instructed on Piazza. Each of your answers must be free of static errors. You may receive no credit for problems whose code contains syntax or type errors. Pay close attention to the specification of each problem and the restrictions imposed on its solution. Solutions ignoring the restrictions may receive only partial credit or no credit at all.

len2241869

2/24/2019 10:41:38 PM

In the following problems do not use any mutable variables (i.e., variables declared with let mutable) or any mutable predefined types such as references, mutable records, arrays, and so on. Define your functions recursively as needed and take advantage of the match operator. You do not need, and should not use, any F# library functions except for the usual integer and Boolean operators, the list operators and the conversion function string. However, you can use your own auxiliary functions if you prefer.

len2241869

2/24/2019 10:41:32 PM

Do not worry about the efficiency of your solution. Strive instead for cleanness and simplicity. Unnecessarily complicated code may not receive full credit. Do the assigned readings before starting attempting this assignment. If you do not, you might find the assignment exceedingly hard. Be sure to review the syllabus for details about this course's cheating policy.

Write a Review

Programming Languages Questions & Answers

  Use the formula to determine the total amount of payment

If the loan was $20,000 over 15 years at 12 percent the repayment would be $240.08

  Design a superclass called shape that contains one function

Area of Shapes: Design a superclass called Shape that contains one function-getArea(). The getArea() function in the Shape class will simply return 0, you will derive from it in your subclasses mentioned below.

  Explaining the situation in program

Which of the following best explains the situation after Line 1 has been executed?

  Prepare an array of peoples first names

Create an array of people's first names. Using a loop, read the names from a text (txt) file, and store each one into the array. The array should allow for a maximum of 100 entries.

  Progarm to calculate unit price for products sold

Manager of Super Supermarket would like to be able to calculate unit price for products sold there. To do this, program must input name and price of the item and its weight in pounds and ounces.

  Write a script named lab6s2 that writes the current time

Write a script named lab6s2 that writes the current time and date, lists logged-in users, and prints the system's uptime to a log file. The time should be printed with the format of "03:55 am" as opposed to military time.

  Smallest number using class-friend function and overloading

C++program which can neither be two integers or two floating point number and output smallest number using class, friend function and overloading.

  Design a website by using php and mysql to order pizza

Your task for this project is to design a website by using PHP and Mysqlto order pizza - A website with a complete catalog of pizzas with possible add-on options and customers should be able to prepare and customize an order as per their preference..

  Write a program to find the largest of five numbers

Replace each phrase containing "Until" with an equivalent phrase containing "While", and vice versa. For instance, the phrase (Until sum = 100) would be replaced by (While sum 100).

  Show the graphics simulation of drinks machine

When a coin is clicked on with the mouse it is placed into the slot, it then operates the coin sensor IP0. This should operate OP0 (coin hold solenoid), which will hold the coin in place. At this point either a drink is selected or the coin rejected.

  Write a program that computes the salaries for employees

Write a program that computes the salaries for a collection of employees of different types. This program consists of four classes.

  Write methods which display variables assigned values

write methods which display variables assigned values and operators results

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd