home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / viscobv7.zip / vac22os2 / ibmcobol / macros / bas.ppr < prev    next >
Text File  |  1998-02-24  |  13KB  |  671 lines

  1.  *I
  2.  *Parser Profile for BASIC Compiler/2
  3.  *v2.11
  4.  *lines beginning with a space are ignored
  5.  * (c) Copyright IBM Corporation 1993
  6.  * By: Tom Flemming, February 1989
  7.  
  8. formsize
  9. size 0
  10.  
  11. lists
  12.  *first list all the things we will define to allow parser to reserve space
  13.  
  14. states inter goto mcomment data qdata endcheck cmdline string meta comment cstring spill default
  15.  *the last state listed is the default state at start of new element
  16.  
  17. symbols goto next ll label rsubs underscore data din cn any rcommand rfunction number punctuation quote comment squote variable meta all qin other int qcomment virgule special def
  18.  *symbols to be recognized
  19.  
  20.  
  21. classes space label code comment meta error
  22.  *the order if this list is important. The last item is scanned
  23.  *first. Particularly so for exclusive classes
  24.  
  25. states
  26.  
  27.  *now define all the parser states
  28.  *state names are signif. to 2 chars only, as are symbol names.
  29.  
  30.  *the default state at start of line.
  31.  
  32. state default
  33. fonts special S def S rcommand R rsubs F goto R comment I data R label L
  34. changes rsubs cmdline rcommand cmdline label inter goto goto data data comment mcomment special cmdline def cmdline
  35. unknown cmdline
  36. end
  37.  
  38.  *changes tell us where to go when certain symbols appear-
  39.  *here a label symbol tells us to enter the cmdline state
  40.  *unknown cmdline tells us to enter that state when an unknown symbol appears
  41. state inter
  42. fonts special S def S
  43. changes special cmdline def cmdline
  44. unknown cmdline
  45. end
  46.  
  47. state cmdline
  48. fonts rfunction F rcommand R goto R number N punctuation P quote Q comment I qcomment I data R variable V other E
  49.  *in parsing we work from left to right until we successfully match a symbol
  50. changes quote string comment mcomment qcomment mcomment data data goto goto
  51.  *states and symbols may have the same names.
  52. unknown spill
  53.  *an unknown would be an underscore at end of line. unknowns
  54.  *are not parsed so the spill handler gets a look to see what it is.
  55. end
  56.  *all state definitions must end with 'end'
  57.  
  58. state string
  59. fonts quote Q qin Q
  60.  *fall out on success
  61.  *close quotes.
  62. changes quote cmdline
  63.  *close quotes means back to the command line.
  64. end
  65.  
  66. state mcomment
  67.  *when we find REM, ', we need to decide if it's going to be metacommand or comment
  68. fonts meta M
  69. changes meta meta
  70. unknown comment
  71. end
  72.  
  73. state meta
  74. fonts meta M squote Q int N
  75.  *we can have metacommands, or expressions integer& single-quoted
  76. changes squote cstring
  77. unknown comment
  78.  *if we find a non-meta bit, it's a comment.
  79. end
  80.  
  81. state comment
  82. fonts all C
  83.  *comment on to the end
  84. end
  85.  
  86. state cstring
  87. fonts squote Q any Q
  88. changes squote meta
  89. end
  90.  
  91. state spill
  92.  *if an underscore is found we come here
  93. fonts underscore E any P
  94. changes underscore endcheck
  95. end
  96.  
  97. state endcheck
  98. fonts
  99. unknown cmdline
  100. endl E P
  101. return cmdline
  102. end
  103.  *the return command tells the parser to go to cmdline state at the next line
  104.  
  105. state data
  106.  *in data statements, anything goes except a colon, unless it's in quotes.
  107. fonts quotes Q cn P din D
  108. changes quotes qdata cn cmdline
  109. end
  110.  
  111. state qdata
  112. fonts quote Q qin Q
  113. changes quote data
  114. end
  115.  
  116. state goto
  117.  *recognizes Linenumbers, Labels, commas,  and NEXT (for RESUME NEXT)
  118. fonts next R ll G virgule P
  119. changes next cmdline
  120. unknown cmdline
  121. end
  122.  
  123. symbols
  124.  
  125.  *now we define the symbol classes mapped to fonts in the font commands above
  126.  *first a linenumber or label
  127. symbol label
  128. form
  129. {[$,'.']}({'  '})':'
  130. #
  131.  
  132. symbol ll
  133. form
  134. {[$,'.']}
  135.  
  136. symbol next
  137. alphalist upper single $('.')
  138. NEXT
  139.  
  140. symbol int
  141. form
  142. #
  143.  
  144. symbol underscore
  145. form
  146. '_'
  147.  
  148.  *form is followed by lines of form parser definitions in special parser code
  149.  *Parser code:
  150.  *the following symbols represent items in the string being parsed:
  151.  *symbol:            represents:
  152.          $             a word of alphanumeric characters, any case.
  153.          &             a word of alphabetic chars, any case.
  154.          <             a word of lower case.
  155.          >             a word of upper case.
  156.          #             a word of digits.
  157.          A             single capital
  158.          a             single miniscule
  159.          .             any character
  160.          0             a single digit
  161.          !             a word consisting of any characters except \0 or \n,
  162.                        but including spaces; ie the rest of the line.
  163.          ~'x'          any character except x.
  164.          /'xy'         a word of any characters, delimited by x or y, or the
  165.                        end of a line.
  166.  
  167.  *literals are presented in '' with the escape sequence for ' being ''.
  168.  *case-folded literals are specified by the start sequence (space)> in
  169.   single quotes, then the literal in upper-case. Eg:
  170.   ' >REM' gives a literal of REM ignoring case.
  171.   Thus a space at the beginning of a '' sequence is ignored; to start with
  172.   a space use two spaces; to start with ' >' use '  >'.
  173.  
  174.  *Logic: the parser works down the line seeing if it matches the form.
  175.          as soon as it fails, it drops out and tries with the next line
  176.          until there are no more lines. Then it returns a fail.
  177.          If it succeeds on any line (ie gets to the end) it returns a
  178.          success, ignoring further lines. So ordering is important to ensure
  179.          the maximum length is parsed (eg '3.2' might succeed as '3')
  180.  *NOTE:  special symbols /'xy' and ! always succeed, so care must be taken
  181.          when using them to order symbols containing them in the fonts list
  182.          of a state in such a way as to avoid unconditional looping.
  183.  
  184.          The following symbols act as logical operators:
  185.     (<form>,<form>,....)
  186.          This is 'optional'. The () must contain at least one form.
  187.          The parser keeps trying forms until one works, then skips to the
  188.          end of the bracket, omitting the others. If none works, it carries
  189.          on anyway.
  190.     [<form>,<form>,....]
  191.          This is 'choose 1'. As before but if none works, it fails the whole
  192.          line.
  193.     {<form>}
  194.          This is 'repeat at least once'. <form> is tried once. If it fails,
  195.          the whole line fails. If it succeeds, then the parser keeps trying
  196.          <form> until it does fail, then carries on with the rest of the line.
  197.  *So, complex maps can be built, Eg:
  198.  
  199.          ['A','B','C']('+','-')#
  200.          will succeed when the string is one of the letters A,B,C followed
  201.          by an optional + or - (but not both) and a compulsory word of at
  202.          least one and maybe more digits.
  203.  
  204.  *Brackets can be nested, Eg:
  205.          #(['E','D']('+','-')#)
  206.          provides for an integer with double precision exponent.
  207.          There must be a number, and if there is anymore it must start
  208.          with 'E' or 'D', but not both, followed by optional sign mark
  209.          and compulsory exponent.
  210.          Note that this will parse '3' as well as '3E-24' since follow-on
  211.          exponent is optional.
  212.  
  213.  * or,   [A,a]({[$,#]})
  214.          allows a name which starts with a letter, of any case, followed by
  215.          an optional string of as many letters and full-stops as you like.
  216.          Z would succeed, as would Za. and s.hello.john, but .Z would fail.
  217.  
  218.  ** Note:However, the parser does not backtrack. If a line fails on which
  219.  **      some options have already been processed, it does not go back and
  220.  **      try the other options again, it goes on to the next line.
  221.  
  222.  *No breaks for comments are allowed in form lists or other lists- they are
  223.          taken as end of list markers.
  224.  
  225. symbol any
  226. form
  227. .
  228.  *any character
  229.  
  230. symbol all
  231. form
  232. !
  233.  
  234. symbol other
  235. form
  236. ~'_'
  237.  
  238. symbol din
  239. form
  240. /'":'
  241.  
  242. symbol data
  243. alphalist upper single $('.')
  244. DATA
  245.  
  246. symbol cn
  247. form
  248. ':'
  249.  
  250. symbol virgule
  251. form
  252. ','
  253.  
  254.  *symbols can also be defined in terms of lists of strings The parser compares
  255.  *the string it has with the strings in the list, and if it finds a match, that
  256.  *symbol is returned as found. There are two sorts of list:
  257.  
  258.  *alphalist: for words (generally). A parser form is provided at the top of
  259.              the list, which the parser uses to extract a notional 'word'
  260.              from the text. It then searches for a match to this word in the
  261.              list. The word must be identical- excess characters will fail.
  262.  
  263.  *sizelist:  for symbols, embedded words. The parser goes through the list
  264.              comparing each entry with its own length of characters from the
  265.              text. This allows tokens without identifiable separators to be
  266.              checked. Precedence is given to longer entries.
  267.  
  268.  * an alphalist must be listed in full ascii order, low to high
  269.  * a sizelist is arranged in ascii order of first characters, then in
  270.    size order, longest to shortest, ie azz comes before ab comes before b.
  271.  
  272.  *both types of lists must be have a size specifier, 'large' or 'small',
  273.  *to indicate the amount of memory to be reserved. 'large' lists can have up
  274.  *to 200 entries, 'small' ones up to 50.
  275.  *alphalists can also have size 'single', and only 1 entry.
  276.  
  277.  *preceding the size specifier is an optional case specifier, upper, which
  278.  *causes all characters to be compared with list entries to be put into
  279.  *upper case before comparisons.
  280.  
  281.  *any size of alphalist, and small sizelists, can be Hashed, for speed.
  282.  *Hashing is specified by giving two characters, the lowest and the
  283.  *highest ASCII values of the first characters of the words in the list,
  284.  *before the case specifier, or size specifier if there is no case.
  285.  
  286.  *the list declarator ('alpha-' or 'sizelist') is followed by the size
  287.   specifier, then in the case of an alphalist, the parser form.
  288. symbol goto
  289. alphalist upper small $('.')
  290. GOSUB
  291. GOTO
  292. RESTORE
  293. RESUME
  294. RETURN
  295.  
  296. symbol special
  297. alphalist upper small $('.')
  298. DECLARE
  299. FUNCTION
  300. SUB
  301.  
  302. symbol def
  303. form
  304. ' >DEF FN'
  305.  
  306. symbol rcommand
  307. alphalist AW upper large $('.')
  308. ABSOLUTE
  309. ACCESS
  310. ALIAS
  311. ANY
  312. APPEND
  313. AS
  314. BASE
  315. BEEP
  316. BINARY
  317. BLOAD
  318. BSAVE
  319. BYVAL
  320. CALL
  321. CALLS
  322. CASE
  323. CDECL
  324. CHAIN
  325. CHDIR
  326. CIRCLE
  327. CLEAR
  328. CLOSE
  329. CLS
  330. COLOR
  331. COM
  332. COMMON
  333. CONTATN
  334. DECLARE
  335. DEF
  336. DEFDBL
  337. DEFINT
  338. DEFLNG
  339. DEFSNG
  340. DEFSTR
  341. DIM
  342. DO
  343. DOUBLE
  344. DRAW
  345. ELSE
  346. ELSEIF
  347. END
  348. ENDIF
  349. ENVIRON
  350. ERASE
  351. ERROR
  352. EXIT
  353. FIELD
  354. FILES
  355. FOR
  356. FUNCTION
  357. GET
  358. IF
  359. INPUT
  360. INTEGER
  361. IOCTL
  362. IS
  363. KEY
  364. KILL
  365. LEN
  366. LET
  367. LINE
  368. LIST
  369. LOCATE
  370. LOCK
  371. LONG
  372. LOOP
  373. LPRINT
  374. LSET
  375. MKDIR
  376. NAME
  377. NEXT
  378. OFF
  379. ON
  380. OPEN
  381. OPTION
  382. OUT
  383. OUTPUT
  384. PAINT
  385. PEN
  386. PLAY
  387. POKE
  388. PRESET
  389. PRINT
  390. PSET
  391. PUT
  392. RANDOM
  393. RANDOMIZE
  394. READ
  395. REDIM
  396. RESET
  397. RMDIR
  398. RSET
  399. RUN
  400. SCREEN
  401. SEEK
  402. SEG
  403. SELECT
  404. SHARED
  405. SHELL
  406. SIGNAL
  407. SINGLE
  408. SOUND
  409. STATIC
  410. STEP
  411. STOP
  412. STRIG
  413. STRING
  414. SUB
  415. SWAP
  416. SYSTEM
  417. THEN
  418. TO
  419. TROFF
  420. TRON
  421. TYPE
  422. UNLOCK
  423. UNTIL
  424. USING
  425. VIEW
  426. WAIT
  427. WEND
  428. WHILE
  429. WIDTH
  430. WINDOW
  431. WRITE
  432.  
  433. symbol rfunction
  434. alphalist AX upper large $('$')('(')('.')
  435. ABS(
  436. AND
  437. ASC(
  438. ATN(
  439. CDBL(
  440. CHR$(
  441. CINT(
  442. CLNG(
  443. COMMAND$
  444. COS(
  445. CSNG(
  446. CSRLIN
  447. CVD(
  448. CVDMBF(
  449. CVI(
  450. CVL(
  451. CVS(
  452. CVSMBF(
  453. DATE$
  454. ENVIRON$(
  455. EOF(
  456. EQV
  457. ERDEV
  458. ERDEV$
  459. ERL
  460. ERR
  461. EXP(
  462. FILEATTR(
  463. FIX(
  464. FRE(
  465. FREEFILE
  466. HEX$(
  467. IMP
  468. INKEY$
  469. INP(
  470. INPUT$(
  471. INSTR(
  472. INT(
  473. IOCTL$(
  474. LBOUND(
  475. LCASE$(
  476. LEFT$(
  477. LEN(
  478. LOC(
  479. LOF(
  480. LOG(
  481. LPOS(
  482. LTRIM$(
  483. MID$(
  484. MKD$(
  485. MKDMBF$(
  486. MKI$(
  487. MKL$(
  488. MKS$(
  489. MKSMBF$(
  490. MOD
  491. NOT
  492. OCT$(
  493. OR
  494. PEEK(
  495. PEN(
  496. PMAP(
  497. POINT(
  498. POS(
  499. RIGHT$(
  500. RND
  501. RND(
  502. RTRIM$(
  503. SADD(
  504. SCREEN(
  505. SETMEM(
  506. SGN(
  507. SHELL(
  508. SIN(
  509. SPACE$(
  510. SPC(
  511. SQR(
  512. STICK(
  513. STR$(
  514. STRIG(
  515. STRING$(
  516. TAB(
  517. TAN(
  518. TIME$
  519. TIMER
  520. UBOUND(
  521. UCASE$(
  522. USR
  523. VAL(
  524. VARPTR(
  525. VARPTR$(
  526. VARSEG(
  527. XOR
  528.  
  529. symbol rsubs
  530.  *subset of functions with only alphanum chars
  531. alphalist AX upper small $('.')
  532. AND
  533. CSRLIN
  534. EQV
  535. ERDEV
  536. ERL
  537. ERR
  538. FREEFILE
  539. IMP
  540. MOD
  541. NOT
  542. OR
  543. RND
  544. TIMER
  545. USR
  546. XOR
  547.  
  548. symbol number
  549. form
  550. [#('.'#),'.'#](['E','e','D','d']('-','+')#,'!','#','&','%')
  551. '&'('o','O')#('&','%')
  552. '&'['H','h']$('&','%')
  553.  *floating point, mantissa, exponent, single/double precision
  554.  *then octal
  555.  *then hex
  556.  
  557. symbol punctuation
  558. sizelist !^ small
  559. !
  560. #
  561. $
  562. %
  563. (
  564. )
  565. *
  566. +
  567. ,
  568. -
  569. .
  570. /
  571. :
  572. ;
  573. <=
  574. <>
  575. <
  576. =
  577. =<
  578. =>
  579. ><
  580. >=
  581. >
  582. \
  583. ^
  584.  
  585. symbol quote
  586. form
  587. '"'({'  '})
  588.  
  589. symbol qin
  590. form
  591. /'""'
  592.  
  593. symbol qcomment
  594. form
  595. ''''
  596.  
  597. symbol comment
  598. alphalist upper single $('.')
  599. REM
  600.  
  601. symbol meta
  602. alphalist upper small '$'$(':','+','-')
  603. $DYNAMIC
  604. $INCLUDE:
  605. $LINESIZE:
  606. $LIST+
  607. $LIST-
  608. $MODULE:
  609. $OCODE+
  610. $OCODE-
  611. $PAGE
  612. $PAGEIF:
  613. $PAGESIZE:
  614. $SKIP:
  615. $STATIC
  616. $SUBTITLE:
  617. $TITLE:
  618.  
  619. symbol squote
  620. form
  621. ''''
  622.  
  623. symbol variable
  624. form
  625. [A,a]({[$,'.']})('%','&','#','!','$')
  626.  
  627.  *now define how we will allocate classes...
  628. classes
  629.  
  630.  *classes have a name, the lpex classname, followed by a list of needed fonts
  631.  *and a list of proscribed fonts in the element to make it a member of the
  632.  *class. The need list can have several possibilitties separated by ||
  633.  * if the class is specified as 'exclude', it will only be given when no
  634.  * other class has been already.
  635. class space exclude
  636. needed
  637. not
  638.  
  639. class code
  640. needed F || R || V || N || P || Q
  641. not
  642.  
  643. class comment
  644. needed I
  645. not
  646.   *not a comment if it's a metacommand
  647.  
  648. class meta
  649. needed M
  650. not
  651.  
  652. class error
  653. needed E
  654. not
  655.  
  656. class label
  657. needed L || S
  658. not
  659.  
  660.  *there is an automatic class of open# for each state which is has a return
  661.  *state specified.
  662.  *an element is given this class if its final state is this state. # is the
  663.  *first two letters of the statename of the return state.
  664.  *There is also an automatic font of _ for spaces.
  665.  
  666. end
  667.  *end the lot
  668.  *nothing except comments may come after the final 'end'
  669.  
  670.  
  671.