MODULE roman; ! ! This module defines the subroutine that ! checks and evaluate a roman numeral. ! ! The integer result is: ! if positive, the resultant numerical value ! if negative, the absolute value is the column ! at which the parsing error was detected ! INCLUDE FILE 'comp_include:recovery_packet.scndef'; INCLUDE FILE 'roman.def'; PROCEDURE report_roman_error ( error_packet: recovery_packet ); roman_value = - ( error_packet.error_token_column - 1 ); END PROCEDURE; /* report_roman_error TOKEN rn_m { 'm' }; TOKEN rn_d { 'd' }; TOKEN rn_c { 'c' }; TOKEN rn_l { 'l' }; TOKEN rn_x { 'x' }; TOKEN rn_v { 'v' }; TOKEN rn_i { 'i' }; TOKEN rc_cm { 'cm' }; TOKEN rc_cd { 'cd' }; TOKEN rc_xc { 'xc' }; TOKEN rc_xl { 'xl' }; TOKEN rc_ix { 'ix' }; TOKEN rc_iv { 'iv' }; TOKEN sos { S'SOS' }; TOKEN eos { S'EOS' }; TOKEN eol { S'EOL' }; MACRO m SYNTAX { rn_m }; roman_value = roman_value + 1000; END MACRO; /* m MACRO d SYNTAX { rn_d }; roman_value = roman_value + 500; END MACRO; /* d MACRO c SYNTAX { rn_c }; roman_value = roman_value + 100; END MACRO; /* c MACRO l SYNTAX { rn_l }; roman_value = roman_value + 50; END MACRO; /* l MACRO x SYNTAX { rn_x }; roman_value = roman_value + 10; END MACRO; /* x MACRO v SYNTAX { rn_v }; roman_value = roman_value + 5; END MACRO; /* v MACRO i SYNTAX { rn_i }; roman_value = roman_value + 1; END MACRO; /* i MACRO cm SYNTAX { rc_cm }; roman_value = roman_value + 900; END MACRO; /* cm MACRO cd SYNTAX { rc_cd }; roman_value = roman_value + 400; END MACRO; /* cd MACRO xc SYNTAX { rc_xc }; roman_value = roman_value + 90; END MACRO; /* xc MACRO xl SYNTAX { rc_xl }; roman_value = roman_value + 40; END MACRO; /* xl MACRO ix SYNTAX { rc_ix }; roman_value = roman_value + 9; END MACRO; /* ix MACRO iv SYNTAX { rc_iv }; roman_value = roman_value + 4; END MACRO; /* iv MACRO c_s SYNTAX { c [ c [ c [ c ] ] ] }; END MACRO; /* c_s MACRO x_s SYNTAX { x [ x [ x [ x ] ] ] }; END MACRO; /* x_s MACRO i_s SYNTAX { i [ i [ i [ i ] ] ] }; END MACRO; /* i_s MACRO under_10 SYNTAX { v [ i_s ] | i_s | iv | ix }; END MACRO; /* under_10 MACRO under_100 SYNTAX { l [ x_s ] | x_s | xl | xc }; END MACRO; /* under_100 MACRO under_1000 SYNTAX { d [ c_s ] | c_s | cm | cd }; END MACRO; /* under_1000 MACRO roman_numeral TRIGGER { sos ERROR( report_roman_error ) : { [ m | m m ] [ under_1000 ] [ under_100 ] [ under_10 ] eol } eos }; ANSWER S'EOS'; END MACRO; /* roman_numeral PROCEDURE roman_evaluate ( rnp: STRING ) OF INTEGER; DECLARE rnp_lower: STRING; roman_value = 0; rnp_lower = LOWER(rnp) & S'EOL'; START SCAN INPUT STRING rnp_lower OUTPUT FILE 'nl:'; RETURN roman_value; END PROCEDURE; /* roman_evaluate END MODULE; /* roman