[printable version of this document (pdf)]| [COMP 304B Home]
In this assignment you will use UML State Machines to specify whether to accept or reject a series of input characters from an input character stream. The specification will be derived by you from a Regular Expression specification. The automaton will not only accept/reject input, but will also determine pertinent properties (such as value) of the recognized token. For the spreadsheet application, we need to be able to recognize Number and CellRef tokens. You will encodecode both automata in the given Python framework and run the simple provided tests.
Your assignment solution should contain:
D [0-9] E [eE][+-]?({D})+ Number [({D}+{E}?) ({D}*'.'{D}+({E})?) ({D}+'.'{D}*({E})?)]Note how this specification is taken from the ANSI C grammar, Lex specification.
D and E are macros which are expanded literally wherever {D} and {E} occur. Wherever no ambiguity exists, characters such as 0 stand for themselves '0'. [] denotes or. * denotes 0 or more times repeated. + denotes 1 or more times repeated. ? denotes exactly 0 or 1 occurrences. Brackets () allow for grouping.
The automaton should set self.value and self.exp attributes to hold the mantissa and exponent respectively.
'$'?[a-zA-Z][a-zA-Z]?'$'?[1-9][0-9]?[0-9]?[0-9]?
The automaton should set self.row, self.rowIsAbsolute, self.column and self.columnIsAbsolute attributes to hold appropriate integer values.
You may use any drawing tool to produce the automaton.
Upload all files to WebCT and provide links to them from your index.html file.
The Regular Expression [10]*0 is recognized by the automaton
below.
The scanner is encoded in the class EvenBinaryScanner in
scanner_evenBinary.py.
This requires an input stream class CharacterStream
found in charstream.py.
The test script test_evenBinary.py
produces the following
output
when the __trace__ variable is set to False.
It produces the following
output
when the __trace__ variable is set to True.