Next is grammar to represent syntax directed translation from number in format 1xxx into roman numerals.
number = OneThousand digit3 digit2 digit1 | nzdigit3 digit2 digit1 | nzdigit2 digit1 | nzdigit1
OneThousand -> 1 {print('M')}
digit3 -> 0 digit3 -> nzdigit3
nzdigit3 -> 1 print('C') nzdigit3 -> 2 print('CC') nzdigit3 -> 3
print('CCC') nzdigit3 -> 4 print('CCCC') nzdigit3 -> 5 print('D')
nzdigit3 -> 6 print('DC') nzdigit3 -> 7 print('DCC') nzdigit3 -> 8
print('DCCC') nzdigit3 -> 9 print('DCCCc')
In similar manner write definition for digits in 2 and 1 position and you will have needed translation.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…