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