# Re: Parsing Roman numbers

## weberwu@inf.fu-berlin.de (Debora Weber-Wulff)Sun, 24 May 1992 14:10:33 GMT

From comp.compilers

Related articles
Parsing Roman numbers joe@erix.ericsson.se (1992-05-22)
Re: Parsing Roman numbers byron@archone.tamu.edu (1992-05-23)
Re: Parsing Roman numbers henry@zoo.toronto.edu (1992-05-24)
Re: Parsing Roman numbers weberwu@inf.fu-berlin.de (1992-05-24)
Re: Parsing Roman numbers Martin.Ward@durham.ac.uk (Martin Ward) (1992-05-26)
| List of all articles for this month |

 Newsgroups: comp.compilers From: weberwu@inf.fu-berlin.de (Debora Weber-Wulff) Keywords: parse Organization: Free University of Berlin References: 92-05-126 92-05-131 Date: Sun, 24 May 1992 14:10:33 GMT

Check out K. John Gough, "Syntax Analysis and Software Tools"
(Addison-Wesley). He gives an example of a FSA for R(1..9), the roman
numerals 1 to 9, including the alternative for 4. He shows the sparse
state transition table you get, and uses this as a motivation for
compaction. A recognizer for the language from page 33 follows:

procedure RDIGIT (var valid:Boolean):
const error = 10; (* state 10 is error state*)
var state : 0..10;
ch : char;

begin
state := 0;
while ch in ['I','V','X'] do begin
case state of
0: case ch of
'I': state := 1;
'V': state := 5;
'X': state := error;
end;
1: case ch of
'I': state := 2;
'V': state := 5;
'X': state := 9;
end;
2: if ch = 'I' then state := 3 else state := error;
5: if ch = 'I' then state := 6 else state := error;
6: if ch = 'I' then state := 7 else state := error;
7: if ch = 'I' then state := 8 else state := error;
3,4,8,9,10 state := error;
end; (* case *)
end (* while *);
valid := state in [1..9];
end;

Typos are mine.

--
Debora Weber-Wulff dww@inf.fu-berlin.de
Institut fuer Informatik +49 30 89691 124
Nestorstr. 8-9
D-W-1000 Berlin 31
--

Post a followup to this message