|
I write MI in lowercase. My scanner capitalizes where appropriate, skipping literals and comments. It converts C++ style comments to CL-style comments. Here's a before-and-after example. cmpbla(b) DayOfWeek, "Mc'Donald's" / eq(ReadAgain); -- jump if found CMPBLA(B) DAYOFWEEK, "Mc'Donald's" / EQ(READAGAIN); /* jump if found */ Here's a snip of scanner code. Put it in your QPRCRTPG front end. Point ?SCAN to your MI source string. Calculate LENGTH, and let it run! The first state is 1. When the scanner enters state 0, it capitalizes the current token. (If you want C++ style comments, add another table row for "dash"; add two more table columns for "the dash state" and "the dash-dash state"; and add executable code to handle "entering the dash-dash state" event. Overlay the dash-dash with slash-asterisk, and append asterisk-slash to the current source line.) Next, think how you'd write a general-purpose program that accepts language definitions and outputs program source like this. Then you're on your way to creating little languages for AS/400, for example, a menu-bar pull-down window language, a panel group driver language, an infix-to-postfix converter front end for QQQQUERY. That's stuff people will pay big money for! DCL MSPPTR ?SCAN; DCL DD SCANBYTE BAS(?SCAN) CHAR(1); DCL DD LENGTH AUTO BIN(4); DCL DD INPUT AUTO BIN(2) INIT(0); DCL DD INPUT2 DEF(INPUT) POS(2) CHAR(1); DCL DD STATE AUTO BIN(2) INIT(1); DCL DD NEXT(0:63) AUTO INIT( 1, 1, 2, 1, 4, 4, 6, 7, /* other */ 2, 2, 2, 1, 4, 4, 6, 7, /* < */ 1, 1, 2, 4, 5, 4, 6, 7, /* * */ 3, 3, 2, 1, 4, 1, 6, 7, /* / */ 1, 1, 1, 1, 4, 4, 6, 7, /* > */ 6, 6, 2, 1, 4, 4, 1, 7, /* ' */ 7, 7, 2, 1, 4, 4, 6, 1, /* " */ 0, 0, 2, 0, 4, 4, 6, 7); /* lower */ DCL DD GROUPS AUTO CHAR(256) INIT((256) X"01"); /* other */ DCL DD * DEF(GROUPS) POS(H"4D") CHAR( 1 ) INIT(( 1 ) X"02"); /* < */ DCL DD * DEF(GROUPS) POS(H"5D") CHAR( 1 ) INIT(( 1 ) X"03"); /* * */ DCL DD * DEF(GROUPS) POS(H"62") CHAR( 1 ) INIT(( 1 ) X"04"); /* / */ DCL DD * DEF(GROUPS) POS(H"6F") CHAR( 1 ) INIT(( 1 ) X"05"); /* > */ DCL DD * DEF(GROUPS) POS(H"7E") CHAR( 1 ) INIT(( 1 ) X"06"); /* ' */ DCL DD * DEF(GROUPS) POS(H"80") CHAR( 1 ) INIT(( 1 ) X"07"); /* " */ DCL DD * DEF(GROUPS) POS(H"82") CHAR( 9 ) INIT(( 9 ) X"08"); /* a-i */ DCL DD * DEF(GROUPS) POS(H"92") CHAR( 9 ) INIT(( 9 ) X"08"); /* j-r */ DCL DD * DEF(GROUPS) POS(H"A3") CHAR( 8 ) INIT(( 8 ) X"08"); /* s-z */ LOOP: XLATEWT INPUT2, SCANBYTE, GROUPS; CAI INPUT, STATE, INPUT, 8; CPYNV(B) STATE, NEXT(INPUT) / NZER(SKIP); OR(S) SCANBYTE, X"40"; SKIP: ADDSPP ?SCAN, ?SCAN, 1; SUBN(SB) LENGTH, 1 / POS(LOOP); +--- | This is the MI Programmers Mailing List! | To submit a new message, send your mail to MI400@midrange.com. | To subscribe to this list send email to MI400-SUB@midrange.com. | To unsubscribe from this list send email to MI400-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: dr2@cssas400.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.