RosettaCodeData/Task/Roman-numerals-Decode/Vedit-macro-language/roman-numerals-decode.vedit
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

38 lines
1.3 KiB
Text

// Main program for testing the function
//
do {
Get_Input(10, "Enter a roman numeral: ", NOCR+STATLINE)
Call("Roman_to_Arabic")
Reg_Type(10) Message(" = ") Num_Type(#1)
} while(#1)
Return
// Convert Roman numeral into numeric value
// in: @10 = Roman numeral
// out: #1 = numeric value
//
:Roman_to_Arabic:
Buf_Switch(Buf_Free)
Ins_Text("M1000 D500 C100 L50 X10 V5 I1") Ins_Newline
Reg_Ins(10) Ins_Char(' ')
#1 = #2 = 0
Repeat(ALL) {
#3 = #2 // #3 = previous character
Goto_Line(2) // roman numeral to be converted
if (At_EOL) {
Break // all done
}
Reg_Copy_Block(11, CP, CP+1, DELETE) // next character in roman numeral
if (Search(@11, BEGIN+ADVANCE+NOERR)) { // find character from the table
#2 = Num_Eval(SUPPRESS) // corresponding numeric value
if (#2 > #3) { // larger than previous digit?
#1 -= #3 // substract previous digit
} else {
#1 += #3 // add previous digit
}
}
}
Reg_Empty(11)
Buf_Quit(OK)
Return