Assignment — C Messages CS 265 Advanced Programming Techniques Overview Write a Cprogramto verify messages. A Finite State Machine would suffice, but a parser would be fine. To Do We have developed a...


Assignment — C Messages


CS 265 Advanced Programming Techniques


Overview


Write a Cprogramto verify messages. A Finite State Machine would suffice, but a parser would be fine.


To Do


We have developed a protocol for reading messages from a device. There are different length messages. Each message has rules, described below. Messages are separated by a newline. Your job is to verify that the stream is valid, that it contains only valid messages.


Each message is followed by a description, some examples, and aDeterministic Finite State Automaton(DFA) which recognises the message. Before input is read, you are in state 1. We transition states on each character read. If, at the end of input, we are in anaccepting state(double circle), then the message is valid.



foo:

Starts with anEfollowed by a string of digits0 1or2followed by anF. E.g.:E201022011101FDFA for foo

eep:

Starts with aP, followed by arbitrary number ofBC(including none). E.g.:P
PBCBCBCDFA for eep

op:

Starts with aQ. Followed by a string of6and7, where the number of7s must be odd.Q7
Q66666676666
Q76767DFA for op

ork:

Starts with anM. Followed by 2 decimal digits, then afooor aneepM84E2010201F
M27PBCDFA for ork


Input


You will read input from the filename provided as the first argument on the comand line. If you can not open it for reading, print a meaningful message, and quit. If no filename is provided, you will readstdin.Note,stdinis of typeFILE*, and can be read exactly like a file. SeeLabs/C/inputLines.cfor an example.


Output


Print out the message, followed by a space, thenOKif the message is valid,FAILotherwise. One per line.


Hints


You maybe find these helpful. If you do not, that is okay. They are not directives.



  • Read each line, parse the string, or

  • Usefgetc(), parse the input directly

  • Make a function for each message


Style


We've covered style. Use judicious (not excessive) whitespace, proper file header coments, function header comments, other helpful (but not effusive) comments. Apply principles you've learned, to make your code legible.


What to Submit


Submit just the source code,msg.c.



  • Do not submit a .doc file, a .zip file, or a .pdf file. These formats are not correct for this assignment and will not be accepted.

  • Make sure you develop and test your script on tux. If your script does not run on tux, it will not be considered correct.

May 29, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here