Homework 0
CS536-S24 Intro to PLs and Compilers

Question 1 | Question 2


Question 1

Draw a deterministic finite state machine that accepts the language of file paths.

A file path consists of optional directory names and one file name, separated by "/". The requirements for a valid file path are:

Label the edges of your FSM with words slash, dot, letter, and digit.

Examples of valid file paths:

/P1.java
/a/very/long/directory/.file
/foo/I.have.many.many.dots
/bar/NoDot

Examples of invalid file paths:

P1.java
/bad/file..name
/another/bad/filename.

Question 2

Write a regular expression for a UsernameTag. A UsernameTag has the following format : UserName#Number
and must meet the following requirements:

Examples of valid UsernameTags:

hello-world#45
life4compiler#0102

Examples of invalid UsernameTags:

not-a-user-tag#
also-not-a-user-tag#number123
invalid--usertag#319
32invalid-#987

You may use hyphen to represent "-", digit to represent any digit, and letter to represent any letter.


Last Updated: 2/1/2024     © 2024 CS 536