CSC 240

Theory of Computation

Lab 06 - Finite Automata

There is a new, all-purpose programming language called CavaML++, designed to let you combine the best parts of C++, Java, and HTML.

In this assignment, you will design and code a finate automata to determine if a given string in that language is a valid comment or not.

Comments in CavaML++ begin with the character sequence --{* and end with the sequence *}--.

The following are valid comments in CavaML++:

--{* This is a comment, it should be ignored. *}--

--{* In CavaML++, comments start with --{*. *}--

--{**-{*-*}-**}--

--{**}--

These are not valid comments:

--{* Missing a closing tag.

--{* In CavaML++, comments start with --{* and end with *}-- *}--

--{**--{*--*}--**}--

--{}--

Assignment

Design a DFA that can accept valid CavaML++ comments and reject invalid ones. Then, implement that DFA in C++.

Your program should prompt the user for a string, then use the DFA to determine if it is a valid CavaML++ comment or not. If it is a valid comment, it should print out: Valid Comment. Otherwise, it should print out Invalid Comment.

Example program runs:

Enter a string: --{* In CavaML++, comments start with --{*. *}--
Valid Comment.

Enter a string: --{* Missing a closing tag.
Invalid Comment.

Make sure your program works for each of the test cases listed above.

While there are many techniques one could use to determine if a string is a valid CavaML comment, you must use a finite automata in order to receive credit.

Grading

Out of 100 Points:

Submission

To submit your assignment, zip your C++ file(s) and upload them to mySVU.