home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3183 < prev    next >
Encoding:
Internet Message Format  |  1991-04-11  |  38.8 KB

  1. From: bob@reed.UUCP (Bob Ankeney)
  2. Newsgroups: alt.sources
  3. Subject: PL/M to C converter Part 03/03
  4. Message-ID: <16305@reed.UUCP>
  5. Date: 9 Apr 91 17:02:47 GMT
  6.  
  7.  
  8. #!/bin/sh
  9. # this is part 3 of a multipart archive
  10. # do not concatenate these parts, unpack them in order with /bin/sh
  11. # file parse.c continued
  12. #
  13. CurArch=3
  14. if test ! -r s2_seq_.tmp
  15. then echo "Please unpack part 1 first!"
  16.      exit 1; fi
  17. ( read Scheck
  18.   if test "$Scheck" != $CurArch
  19.   then echo "Please unpack part $Scheck next!"
  20.        exit 1;
  21.   else exit 0; fi
  22. ) < s2_seq_.tmp || exit 1
  23. sed 's/^X//' << 'SHAR_EOF' >> parse.c
  24. X        out_string = temp_out_string;
  25. X
  26. X            /* Check for '=' */
  27. X        if ((token_class != OPERATOR) ||
  28. X            (token.token_type != EQUAL)) {
  29. X            parse_error("Missing '='");
  30. X            pop_context();
  31. X            return;
  32. X        }
  33. X            /* Send <ident> '=' <expr> */
  34. X        out_str(var_string);
  35. X        out_token(&token);
  36. X        token_class = parse_expression(&token);
  37. X        if ((token_class != RESERVED) ||
  38. X            (token.token_type != TO)) {
  39. X            parse_error("Missing TO");
  40. X            pop_context();
  41. X            return;
  42. X        }
  43. X
  44. X            /* Send <ident> <= <limit> */
  45. X        out_str("; ");
  46. X        out_str(var_string);
  47. X        out_str(" <=");
  48. X        token_class = parse_expression(&token);
  49. X        out_str("; ");
  50. X
  51. X            /* Parse increment */
  52. X        if ((token_class == RESERVED) &&
  53. X            (token.token_type == BY)) {
  54. X
  55. X                /* Send <ident> += <step> */
  56. X            out_str(var_string);
  57. X            out_str(" +=");
  58. X            token_class = parse_expression(&token);
  59. X        } else {
  60. X                /* Send <ident>++ */
  61. X            out_str(var_string);
  62. X            out_str("++");
  63. X        }
  64. X
  65. X        out_str(") {");        /* } for dumb vi */
  66. X        out_white_space(&token);
  67. X
  68. X        if (token_class != END_OF_LINE) {
  69. X            parse_error("BY or ';' expected");
  70. X            pop_context();
  71. X            return;
  72. X        }
  73. X
  74. X        parse_to_end();
  75. X        break;
  76. X
  77. X    case RESERVED :
  78. X        switch (token.token_type) {
  79. X
  80. X        case CASE :
  81. X                /* DO CASE <expr>; */
  82. X            out_str("switch (");
  83. X            if (parse_expression(&token) != END_OF_LINE) {
  84. X                parse_error("';' expected");
  85. X                pop_context();
  86. X                return;
  87. X            }
  88. X            out_white_space(&token);
  89. X            out_str(") {");        /* } for dumb vi */
  90. X
  91. X            case_line = 0;
  92. X            while (1) {
  93. X                    /* Place case statement in out_string */
  94. X                temp_out_string1 = out_string;
  95. X                case_output[0] = '\0';
  96. X                out_string = case_output;
  97. X    
  98. X                (void) sprintf(case_statement, "case %d :",
  99. X                    case_line++);
  100. X                token_class = parse_new_statement();
  101. X                if (token_class == END_OF_FILE) {
  102. X                    parse_error("Premature end-of-file");
  103. X                    exit(1);
  104. X                }
  105. X                if (token_class == END) {
  106. X                    out_string = temp_out_string1;
  107. X                    out_str(case_output);
  108. X                    break;
  109. X                }
  110. X                out_string = temp_out_string1;
  111. X                out_white_space(first_token);
  112. X                out_str(case_statement);
  113. X                out_str(case_output);
  114. X                out_white_space(first_token);
  115. X                out_str("break;\n");
  116. X            }
  117. X            break;
  118. X
  119. X        case WHILE :
  120. X                /* DO WHILE <expr>; */
  121. X            out_str("while (");
  122. X            if (parse_expression(&token) != END_OF_LINE) {
  123. X                parse_error("';' expected");
  124. X                pop_context();
  125. X                return;
  126. X            }
  127. X            out_white_space(&token);
  128. X            out_str(") {");        /* } for dumb vi */
  129. X
  130. X            parse_to_end();
  131. X            break;
  132. X
  133. X        default:
  134. X            parse_error("Illegal DO clause");
  135. X            pop_context();
  136. X            return;
  137. X        }
  138. X        break;
  139. X    }
  140. X
  141. X        /* End of context */
  142. X    pop_context();
  143. X}
  144. X
  145. X/*
  146. X *    END statement
  147. X *    Handles END [ <identifier> ] ;
  148. X */
  149. Xparse_end(first_token)
  150. XTOKEN    *first_token;
  151. X{
  152. X    TOKEN    token;
  153. X    int    token_class;
  154. X
  155. X    out_white_space(first_token);        /* { for dumb vi */
  156. X    out_char('}');
  157. X
  158. X        /* Check for END <procedure name>; */
  159. X    token_class = get_token(&token);
  160. X    if (token_class == IDENTIFIER) {
  161. X            /* END foo; where foo is a procedure */
  162. X        out_white_space(&token);
  163. X        out_str("/* ");
  164. X        out_token_name(&token);
  165. X        out_str(" */");
  166. X        token_class = get_token(&token);
  167. X    }
  168. X
  169. X    if (token_class == END_OF_LINE)
  170. X        out_white_space(&token);
  171. X    else
  172. X        parse_error("';' expected");
  173. X}
  174. X
  175. X/*
  176. X *    IF statement
  177. X */
  178. Xparse_if(first_token)
  179. XTOKEN    *first_token;
  180. X{
  181. X    TOKEN    token;
  182. X
  183. X    out_white_space(first_token);
  184. X    out_str("if (");
  185. X
  186. X    if ((parse_expression(&token) != RESERVED) ||
  187. X        (token.token_type != THEN))
  188. X            parse_error("Missing THEN in IF statement");
  189. X    else {
  190. X        out_pre_line(&token);
  191. X        out_char(')');
  192. X        out_white_space(&token);
  193. X    }
  194. X}
  195. X
  196. X/*
  197. X *    THEN statement
  198. X */
  199. Xparse_then()
  200. X{
  201. X    parse_error("Illegal use of THEN");
  202. X}
  203. X
  204. X/*
  205. X *    ELSE statement
  206. X */
  207. Xparse_else(first_token)
  208. XTOKEN    *first_token;
  209. X{
  210. X    out_white_space(first_token);
  211. X    out_str("else");
  212. X}
  213. X
  214. X/*
  215. X *    GOTO statement
  216. X */
  217. Xparse_goto(first_token)
  218. XTOKEN    *first_token;
  219. X{
  220. X    TOKEN    token;
  221. X
  222. X    out_white_space(first_token);
  223. X    out_str("goto");
  224. X
  225. X    if (get_token(&token) != IDENTIFIER)
  226. X        parse_error("Illegal GOTO label");
  227. X    else {
  228. X        out_token(&token);
  229. X        check_eol();
  230. X    }
  231. X}
  232. X
  233. X/*
  234. X *    GO TO statement
  235. X */
  236. Xparse_go(first_token)
  237. XTOKEN    *first_token;
  238. X{
  239. X    TOKEN    token;
  240. X
  241. X    if ((get_token(&token) != RESERVED) || (token.token_type != TO))
  242. X        parse_error("Illegal GO TO");
  243. X    else
  244. X        parse_goto(first_token);
  245. X}
  246. X
  247. X/*
  248. X *    CALL statement
  249. X *    Handles CALL <procedure name> [ ( <parameter list> ) ] ;
  250. X */
  251. Xparse_call(first_token)
  252. XTOKEN    *first_token;
  253. X{
  254. X    TOKEN        token;
  255. X    int        token_class;
  256. X    DECL_MEMBER    *id_type;
  257. X    DECL_ID        *id_id;
  258. X    char        *new_func, *tmp_out_string;
  259. X    char        func_name[MAX_TOKEN_LENGTH];
  260. X
  261. X        /* Get procedure name */
  262. X    token_class = get_token(&token);
  263. X    if (token_class != IDENTIFIER) {
  264. X        parse_error("Illegal procedure name");
  265. X        return;
  266. X    }
  267. X
  268. X    out_white_space(first_token);
  269. X
  270. X        /* Check for function conversion */
  271. X    if (check_cvt_id(&token, &cvt_functions[0], &new_func)) {
  272. X        out_str(new_func);
  273. X        token_class = get_token(&token);
  274. X    } else
  275. X
  276. X    if (find_symbol(&token, &id_type, &id_id) &&
  277. X        (id_type->type->token_type != PROCEDURE)) {
  278. X
  279. X            /* Skip white space */
  280. X        token.white_space_start = token.white_space_end;
  281. X
  282. X            /* Check for call to pointer */
  283. X        func_name[0] = '\0';
  284. X        tmp_out_string = out_string;
  285. X        out_string = func_name;
  286. X        token_class = parse_variable(&token, &id_type, &id_id);
  287. X        out_string = tmp_out_string;
  288. X
  289. X        if ((id_type->type->token_type == POINTER) ||
  290. X#ifdef OFFSET
  291. X            (id_type->type->token_type == OFFSET) ||
  292. X#endif
  293. X            (id_type->type->token_type == WORD)) {
  294. X                /* Yes - use pointer reference */
  295. X            out_str("(*");
  296. X            out_str(func_name);
  297. X            out_char(')');
  298. X        } else {
  299. X            parse_error("Illegal procedure reference");
  300. X            return;
  301. X        }
  302. X    } else {
  303. X        out_token_name(&token);
  304. X        token_class = get_token(&token);
  305. X    }
  306. X
  307. X        /* Get parameter list (if any) */
  308. X    if (token_class == LEFT_PAREN) {
  309. X        out_token(&token);
  310. X
  311. X        do {
  312. X            token_class = parse_expression(&token);
  313. X            out_token(&token);
  314. X        } while (token_class == COMMA);
  315. X
  316. X        if (token_class == RIGHT_PAREN)
  317. X                /* Get end of line */
  318. X            check_eol();
  319. X        else
  320. X            parse_error("Illegal parameter list seperator");
  321. X    } else
  322. X
  323. X    if (token_class == END_OF_LINE) {
  324. X            /* No parameter list */
  325. X        out_str("()");
  326. X        out_token(&token);
  327. X    } else
  328. X        parse_error("';' expected");
  329. X}
  330. X
  331. X/*
  332. X *    RETURN statement
  333. X *    Handles RETURN [ <expression> ] ;
  334. X */
  335. Xparse_return(first_token)
  336. XTOKEN    *first_token;
  337. X{
  338. X    TOKEN    token;
  339. X    int    token_class;
  340. X
  341. X    out_white_space(first_token);
  342. X    out_str("return");
  343. X
  344. X    token_class = parse_expression(&token);
  345. X    if (token_class != END_OF_LINE)
  346. X        parse_error("';' expected");
  347. X    else
  348. X        out_token(&token);
  349. X}
  350. X
  351. X/*
  352. X *    Parse statement starting with an identifier.
  353. X *    Possibilities include:
  354. X *        Assignment
  355. X *        Procedure statement
  356. X */
  357. Xparse_identifier(first_token)
  358. XTOKEN    *first_token;
  359. X{
  360. X    TOKEN        token, next_token;
  361. X    TOKEN        param_token, attrib_token, type_token;
  362. X    int        token_class, next_token_class;
  363. X    DECL        *decl_list, *extra_decl_list;
  364. X    PARAM_LIST    *param_list, *param_ptr;
  365. X    DECL_MEMBER    *decl_ptr;
  366. X    DECL_ID        *decl_id;
  367. X    BOOLEAN        extern_proc, got_type, interrupt_proc;
  368. X    char        *tmp_text_ptr;
  369. X
  370. X        /* Check for label or procedure */
  371. X    tmp_text_ptr = text_ptr;
  372. X    token_class = get_token(&token);
  373. X
  374. X    if (token_class == LABEL) {
  375. X            /* Determine if label or procedure definition */
  376. X        next_token_class = get_token(&next_token);
  377. X        if ((next_token_class == RESERVED) &&
  378. X            (next_token.token_type == PROCEDURE)) {
  379. X/*
  380. X *    Procedure - Check for parameter list
  381. X */
  382. X            param_list = NULL;
  383. X            token_class = get_token(¶m_token);
  384. X            if (token_class == LEFT_PAREN) {
  385. X                    /* Yes - get parameter list */
  386. X                get_param_list(¶m_list);
  387. X
  388. X                    /* Get token after parameter list */
  389. X                token_class = get_token(&attrib_token);
  390. X            } else
  391. X                    /* No param list - save as attribute */
  392. X                token_copy(¶m_token, &attrib_token);
  393. X
  394. X            out_white_space(first_token);
  395. X            extern_proc = FALSE;
  396. X            interrupt_proc = FALSE;
  397. X
  398. X            got_type = (token_class == RESERVED) &&
  399. X                (attrib_token.token_type >= BYTE) &&
  400. X                (attrib_token.token_type <= SELECTOR);
  401. X            if (got_type) {
  402. X/*
  403. X *    Process [ <type> ]
  404. X */
  405. X                token_copy(&attrib_token, &type_token);
  406. X                token_class = get_token(&attrib_token);
  407. X            }
  408. X
  409. X            while (token_class == RESERVED) {
  410. X                if (attrib_token.token_type == INTERRUPT) {
  411. X/*
  412. X *    Process [ <interrupt> ]
  413. X */
  414. X                interrupt_proc = TRUE;
  415. X                token_class = get_token(&attrib_token);
  416. X                if (token_class == NUMERIC)
  417. X                        /* Interrupt number */
  418. X                    token_class = get_token(&attrib_token);
  419. X                } else
  420. X
  421. X/*
  422. X *    Process [ EXTERNAL |  { [ PUBLIC ] [ REENTRANT ] } ]
  423. X */
  424. X                if (attrib_token.token_type == EXTERNAL) {
  425. X                out_str("extern");
  426. X                out_must_white(&attrib_token);
  427. X                extern_proc = TRUE;
  428. X
  429. X                token_class = get_token(&attrib_token);
  430. X                } else
  431. X
  432. X                if ((attrib_token.token_type == PUBLIC) ||
  433. X                    (attrib_token.token_type == REENTRANT)) {
  434. X                do {
  435. X                    if (attrib_token.token_type == PUBLIC) {
  436. X                        /* Ignore for now */
  437. X                        token_class = get_token(&attrib_token);
  438. X                    } else
  439. X
  440. X                    if (attrib_token.token_type == REENTRANT) {
  441. X                        /* Ignore for now */
  442. X                        token_class = get_token(&attrib_token);
  443. X                    } else
  444. X                        break;
  445. X                } while (token_class == RESERVED);
  446. X                } else
  447. X                break;
  448. X            }
  449. X
  450. X            if (token_class != END_OF_LINE) {
  451. X                parse_error("';' expected");
  452. X                return;
  453. X            }
  454. X
  455. X            if (interrupt_proc && !extern_proc)
  456. X                parse_warning("INTERRUPT procedure declared");
  457. X
  458. X                /* Create declaration for procedure */
  459. X            get_element_ptr(&decl_ptr);
  460. X            get_var_ptr(&decl_ptr->name_list);
  461. X                /* Type = PROCEDURE */
  462. X            get_token_ptr(&decl_ptr->type);
  463. X            token_copy(&next_token, decl_ptr->type);
  464. X                /* Name = procedure name */
  465. X            get_token_ptr(&decl_ptr->name_list->name);
  466. X            token_copy(first_token, decl_ptr->name_list->name);
  467. X                /* Flag if parameter list */
  468. X            if (param_list)
  469. X                decl_ptr->initialization = DATA;
  470. X                /* Add it to context */
  471. X            add_to_context(decl_ptr);
  472. X
  473. X            if (got_type) {
  474. X                    /* Output procedure type */
  475. X                out_token_name(&type_token);
  476. X                out_must_white(&type_token);
  477. X            }
  478. X
  479. X                /* Output procedure name */
  480. X            out_token_name(first_token);
  481. X
  482. X            if (extern_proc) {
  483. X                out_str("()");
  484. X
  485. X                if (param_list)
  486. X                    /* Parse parameter declarations */
  487. X                parse_param_list(param_list, &decl_list,
  488. X                    &extra_decl_list);
  489. X
  490. X                out_char(';');
  491. X                    /* Eat closing 'END [<proc name>];' */
  492. X                token_class = get_token(&token);
  493. X                if ((token_class != RESERVED) ||
  494. X                (token.token_type != END)) {
  495. X                parse_error("END expected");
  496. X                return;
  497. X                }
  498. X
  499. X                out_white_space(&token);
  500. X                token_class = get_token(&token);
  501. X                if (token_class == IDENTIFIER) {
  502. X                token_class = get_token(&token);
  503. X                }
  504. X
  505. X                if (token_class != END_OF_LINE) {
  506. X                parse_error("';' expected");
  507. X                }
  508. X
  509. X                return;
  510. X            } else
  511. X
  512. X            if (param_list) {
  513. X                out_token(¶m_token);
  514. X                    /* Output parameter list */
  515. X                param_ptr = param_list;
  516. X                while (param_ptr) {
  517. X                    out_token(¶m_ptr->param);
  518. X                    param_ptr = param_ptr->next_param;
  519. X                    if (param_ptr)
  520. X                        out_char(',');
  521. X                }
  522. X                out_char(')');
  523. X
  524. X                    /* Parse parameter declarations */
  525. X                parse_param_list(param_list, &decl_list,
  526. X                    &extra_decl_list);
  527. X
  528. X                    /* Output declarations */
  529. X                if (decl_list) {
  530. X                    out_decl(decl_list);
  531. X                    /* Add declarations to context */
  532. X                    add_decl_to_context(decl_list);
  533. X                }
  534. X
  535. X                out_str("\n{");        /* } for dumb vi */
  536. X
  537. X                if (extra_decl_list) {
  538. X                    out_decl(extra_decl_list);
  539. X                    /* Add declarations to context */
  540. X                    add_decl_to_context(extra_decl_list);
  541. X                }
  542. X
  543. X                    /* Discard declarations */
  544. X                free_decl(decl_list);
  545. X                free_decl(extra_decl_list);
  546. X            } else
  547. X                    /* No parameter list */
  548. X                out_str("()\n{");    /* } for dumb vi */
  549. X
  550. X                /* Create new context */
  551. X            new_context(PROCEDURE, first_token);
  552. X                /* Parse statements to END */
  553. X            parse_to_end();
  554. X                /* Pop procedure context */
  555. X            pop_context();
  556. X        } else {
  557. X/*
  558. X *    Label - add label name
  559. X */
  560. X            out_token(first_token);
  561. X                /* Add colon */
  562. X            out_token(&token);
  563. X
  564. X                /* Is this a defined label or a module? */
  565. X            if (find_symbol(first_token, &decl_ptr, &decl_id)) {
  566. X                if (decl_ptr->type->token_class == LABEL) {
  567. X                        /* Label - new context */
  568. X                    new_context(MODULE, first_token);
  569. X                    parse_statement(&next_token);
  570. X                    pop_context();
  571. X                } else {
  572. X                    parse_error("Illegal label name");
  573. X                    return;
  574. X                }
  575. X            } else
  576. X                parse_statement(&next_token);
  577. X        }
  578. X        return;
  579. X    }
  580. X
  581. X        /* Assignment statement */
  582. X    text_ptr = tmp_text_ptr;
  583. X    token_copy(first_token, &token);
  584. X    token_class = parse_variable(&token, &decl_ptr, &decl_id);
  585. X
  586. X        /* Check for multiple assignments */
  587. X    while (token_class == COMMA) {
  588. X            /* Print ' =' instead of ',' */
  589. X        out_str(" =");
  590. X        out_white_space(&token);
  591. X            /* Get identifier part of next assignment variable */
  592. X        token_class = get_token(&token);
  593. X        if (token_class != IDENTIFIER) {
  594. X            parse_error("Illegal assignment");
  595. X            return;
  596. X        }
  597. X
  598. X            /* Parse remainder of variable (if any) */
  599. X        token_class = parse_variable(&token, &decl_ptr, &decl_id);
  600. X    }
  601. X
  602. X    if (token_class == OPERATOR) {
  603. X        if (token.token_type != EQUAL) {
  604. X            parse_error("Illegal use of identifier");
  605. X            return;
  606. X        }
  607. X
  608. X        out_token(&token);
  609. X
  610. X            /* Check for POINTER assignment */
  611. X        if (decl_ptr->type->token_type == POINTER) {
  612. X                /* Yes - cast it */
  613. X            out_str(" (");
  614. X            out_str(TYPE_POINTER);
  615. X            out_str(" *) ");
  616. X        }
  617. X
  618. X        if (parse_expression(&token) != END_OF_LINE)
  619. X            parse_error("';' expected");
  620. X        else
  621. X            out_token(&token);
  622. X        return;
  623. X    } else
  624. X
  625. X    if (token_class != LABEL) {
  626. X        parse_error("Illegal use of identifier");
  627. X        return;
  628. X    }
  629. X
  630. X}
  631. X
  632. X/*
  633. X *    Statement started with ':'
  634. X */
  635. Xparse_label()
  636. X{
  637. X    parse_error("Illegal label");
  638. X}
  639. X
  640. X/*
  641. X *    End of line (Null statement)
  642. X */
  643. Xparse_eol(first_token)
  644. XTOKEN    *first_token;
  645. X{
  646. X    out_white_space(first_token);
  647. X    out_char(';');
  648. X}
  649. X
  650. X/*
  651. X *    ENABLE or DISABLE statement
  652. X */
  653. Xparse_int_ctl(first_token)
  654. XTOKEN    *first_token;
  655. X{
  656. X    TOKEN    token;
  657. X    int    token_class;
  658. X
  659. X    out_token(first_token);
  660. X    out_str("()");
  661. X
  662. X    token_class = get_token(&token);
  663. X    if (token_class != END_OF_LINE) {
  664. X        parse_error("';' expected");
  665. X        return;
  666. X    }
  667. X    out_token(&token);
  668. X}
  669. X
  670. X/*
  671. X *    OUTPUT, OUTWORD or OUTHWORD statement of form:
  672. X *        OUTPUT(port) = expr;
  673. X */
  674. Xparse_outport()
  675. X{
  676. X    TOKEN    token;
  677. X    int    token_class;
  678. X
  679. X    if (get_token(&token) != LEFT_PAREN) {
  680. X        parse_error("'(' expected");
  681. X        return;
  682. X    }
  683. X    out_token(&token);
  684. X
  685. X        /* Get port number */
  686. X    if (parse_expression(&token) != RIGHT_PAREN) {
  687. X        parse_error("'(' expected");
  688. X        return;
  689. X    }
  690. X    out_char(',');
  691. X
  692. X    token_class = get_token(&token);
  693. X    if ((token_class != OPERATOR) || (token.token_type != EQUAL)) {
  694. X        parse_error("'=' expected");
  695. X        return;
  696. X    }
  697. X
  698. X        /* Get expression */
  699. X    if (parse_expression(&token) != END_OF_LINE) {
  700. X        parse_error("'(' expected");
  701. X        return;
  702. X    }
  703. X    out_char(')');
  704. X    out_token(&token);
  705. X}
  706. X
  707. X/*
  708. X *    OUTPUT statement
  709. X */
  710. Xparse_output(first_token)
  711. XTOKEN    *first_token;
  712. X{
  713. X    out_white_space(first_token);
  714. X    out_str(FUNC_OUTPUT);
  715. X    parse_outport();
  716. X}
  717. X
  718. X/*
  719. X *    OUTWORD statement
  720. X */
  721. Xparse_outword(first_token)
  722. XTOKEN    *first_token;
  723. X{
  724. X    out_white_space(first_token);
  725. X    out_str(FUNC_OUTWORD);
  726. X    parse_outport();
  727. X}
  728. X
  729. X/*
  730. X *    OUTHWORD statement
  731. X */
  732. Xparse_outhword(first_token)
  733. XTOKEN    *first_token;
  734. X{
  735. X    out_white_space(first_token);
  736. X    out_str(FUNC_OUTHWORD);
  737. X    parse_outport();
  738. X}
  739. X
  740. X
  741. SHAR_EOF
  742. chmod 0660 parse.c || echo "restore of parse.c fails"
  743. sed 's/^X//' << 'SHAR_EOF' > struct.h &&
  744. X/*
  745. X *    Format of a token returned by get_token().
  746. X */
  747. Xtypedef struct TOKEN {
  748. X        /* Class of token (see below) */
  749. X    int    token_class;
  750. X        /* Type of token (see below) */
  751. X    int    token_type;
  752. X        /* Converted token name (when applicable) */
  753. X    char    token_name[MAX_TOKEN_LENGTH];
  754. X        /* Pointer to start of token in text_buffer */
  755. X    char    *token_start;
  756. X        /* Number of characters token_start points to */
  757. X    int    token_length;
  758. X        /* Pointer to start of white space in text_buffer */
  759. X    char    *white_space_start;
  760. X        /* Pointer to char after end of white space in text_buffer */
  761. X    char    *white_space_end;
  762. X#ifdef LINKED_TOKENS
  763. X        /* Pointer for use in linked list */
  764. X    struct    TOKEN    *next_token;
  765. X#endif
  766. X} TOKEN;
  767. X
  768. X/*
  769. X *    Format of a procedure parameter list
  770. X */
  771. Xtypedef struct PARAM_LIST {
  772. X        /* Parameter name */
  773. X    TOKEN    param;
  774. X        /* Pointer for use in linked list */
  775. X    struct PARAM_LIST *next_param;
  776. X} PARAM_LIST;
  777. X
  778. X/*
  779. X *    Format of a variable in a DECLARE statement.
  780. X */
  781. Xtypedef struct DECL_ID {
  782. X        /* Variable name */
  783. X    TOKEN    *name;
  784. X        /* BASED identifier token */
  785. X    TOKEN    *based_name;
  786. X        /* If declared AT in another module */
  787. X    BOOLEAN    is_ext_at;
  788. X        /* Pointer for use in linked list */
  789. X    struct DECL_ID *next_var;
  790. X} DECL_ID;
  791. X
  792. X/*
  793. X *    Format of an element in a DECLARE statement.
  794. X */
  795. Xtypedef struct DECL_MEMBER {
  796. X        /* Linked list of identifiers of designated type */
  797. X    DECL_ID    *name_list;
  798. X        /* LITERALLY string */
  799. X    char    *literal;
  800. X#ifdef PARSE_LITERALS
  801. X        /* Parsed LITERAL token */
  802. X    TOKEN    *literal_token;
  803. X#endif
  804. X        /* Array bound token */
  805. X    TOKEN    *array_bound;
  806. X        /* Type of variable (INTEGER, WORD, LABEL, LITERALLY, etc.) */
  807. X    TOKEN    *type;
  808. X        /* Attributes (NONE, EXTERNAL or PUBLIC) */
  809. X    int    attributes;
  810. X        /* Initialization attribute (NONE, INITIAL or DATA) */
  811. X        /* If PROCEDURE, DATA if has parameters */
  812. X    int    initialization;
  813. X        /* Pointer to linked list of structure elements */
  814. X    struct DECL_MEMBER *struct_list;
  815. X        /* Pointer to parsed AT expression */
  816. X    char    *at_ptr;
  817. X        /* Pointer in text_buffer to start of INITIAL/DATA values */
  818. X    char    *init_ptr;
  819. X        /* Pointer for use in linked list */
  820. X    struct DECL_MEMBER *next_member;
  821. X} DECL_MEMBER;
  822. X
  823. X/*
  824. X *    Format of a DECLARE statement.
  825. X */
  826. Xtypedef struct DECL {
  827. X        /* DECLARE token */
  828. X    TOKEN        *decl_token;
  829. X        /* Linked list of DECL_MEMBERs */
  830. X    DECL_MEMBER    *decl_list;
  831. X        /* Pointer for use in linked list */
  832. X    struct    DECL    *next_decl;
  833. X} DECL;
  834. X
  835. X/*
  836. X *    Format of a context element
  837. X */
  838. Xtypedef struct CONTEXT {
  839. X        /* Type of context (MODULE, PROCEDURE or DO) */
  840. X    int    context_type;
  841. X        /* Name of module or procedure */
  842. X    TOKEN    *context_name;
  843. X        /* Pointer to linked list of declaration members */
  844. X    DECL_MEMBER    *decl_head;
  845. X        /* Pointer for use in linked list */
  846. X    struct CONTEXT    *next_context;
  847. X} CONTEXT;
  848. X
  849. X
  850. X/*
  851. X *    Format of a PL/M identifier equivalent
  852. X */
  853. Xtypedef struct {
  854. X    char    *id_name, *new_id;
  855. X} CVT_ID;
  856. X
  857. X
  858. X/*
  859. X *    Format of a PL/M reserved word
  860. X */
  861. Xtypedef struct {
  862. X    char    *name;
  863. X    int    token;
  864. X} RESERVED_WORD;
  865. X
  866. X/*
  867. X *    Format of a PL/M reserved operator
  868. X */
  869. Xtypedef struct {
  870. X    char    *operator;
  871. X    char    *cvt_operator;
  872. X    int    name;
  873. X} RESERVED_OPERATOR;
  874. X
  875. SHAR_EOF
  876. chmod 0660 struct.h || echo "restore of struct.h fails"
  877. sed 's/^X//' << 'SHAR_EOF' > test.c.out &&
  878. X
  879. X
  880. Xextern farp();
  881. X
  882. X
  883. Xslug()
  884. X{
  885. X    void *ptr;
  886. X    short i;
  887. X    short **iptr = (short **) &ptr;
  888. X    float j;
  889. X    float k;
  890. X    float l;
  891. X    WORD mqaFOO;
  892. X    DWORD fooBAR;
  893. X
  894. X    ptr = (void *)  &i;
  895. X    (**iptr) = 72;
  896. X    iptfil();
  897. X    setinterrput(0, farp);
  898. X    signal(abs(i), (short) (i));
  899. X    j = (float) ((short) (i));
  900. X
  901. X} /* slug */
  902. X    
  903. X
  904. SHAR_EOF
  905. chmod 0660 test.c.out || echo "restore of test.c.out fails"
  906. sed 's/^X//' << 'SHAR_EOF' > test.plm &&
  907. XFOO:    DO;
  908. X
  909. XFARP: PROCEDURE EXTERNAL;
  910. XEND;
  911. X
  912. XSLUG :PROCEDURE;
  913. X    DECLARE PTR POINTER;
  914. X    DECLARE I INTEGER;
  915. X    DECLARE IPTR BASED PTR INTEGER;
  916. X    DECLARE J REAL;
  917. X    declare k real;
  918. X    declare l REAL;
  919. X    declare mqaFOO WORD;
  920. X    declare FOObar DWORD;
  921. X
  922. X    PTR = @I;
  923. X    IPTR = 72;
  924. X    CALL IPTFIL;
  925. X    CALL SET$INTERRPUT(0, FARP);
  926. X    CALL SET$INTERRUPT(IABS(I), FIX(I));
  927. X    J = FLOAT(FIX(I));
  928. X
  929. XEND SLUG;
  930. X    END FOO;
  931. X
  932. SHAR_EOF
  933. chmod 0660 test.plm || echo "restore of test.plm fails"
  934. sed 's/^X//' << 'SHAR_EOF' > tkn_defs.h &&
  935. X/*
  936. X *    Reserved word list
  937. X */
  938. XRESERVED_WORD reserved_words[] = {
  939. X
  940. X        /* Statements */
  941. X    "DECLARE",    DECLARE,
  942. X    "DO",        DO,
  943. X    "END",        END,
  944. X    "IF",        IF,
  945. X    "THEN",        THEN,
  946. X    "ELSE",        ELSE,
  947. X    "GOTO",        GOTO,
  948. X    "GO",        GO,
  949. X    "CALL",        CALL,
  950. X    "RETURN",    RETURN,
  951. X    "DISABLE",    DISABLE,
  952. X    "ENABLE",    ENABLE,
  953. X    "OUTPUT",    OUTPUT,
  954. X    "OUTWORD",    OUTWORD,
  955. X    "OUTHWORD",    OUTHWORD,
  956. X
  957. X        /* Operators */
  958. X    "AND",        AND,
  959. X    "OR",        OR,
  960. X    "XOR",        XOR,
  961. X    "NOT",        NOT,
  962. X    "MOD",        MOD,
  963. X    "PLUS",        PLUS,
  964. X    "MINUS",    MINUS,
  965. X
  966. X        /* DO options */
  967. X    "CASE",        CASE,
  968. X    "WHILE",    WHILE,
  969. X    "TO",        TO,
  970. X    "BY",        BY,
  971. X
  972. X        /* DECLARE types */
  973. X    "BYTE",        BYTE,
  974. X    "WORD",        WORD,
  975. X    "DWORD",    DWORD,
  976. X    "INTEGER",    INTEGER,
  977. X    "REAL",        REAL,
  978. X    "SELECTOR",    SELECTOR,
  979. X    "ADDRESS",    ADDRESS,
  980. X    "STRUCTURE",    STRUCTURE,
  981. X    "LABEL",    LABEL,
  982. X    "POINTER",    POINTER,
  983. X    "BASED",    BASED,
  984. X    "LITERALLY",    LITERALLY,
  985. X
  986. X        /* DECLARE options */
  987. X    "DATA",        DATA,
  988. X    "EXTERNAL",    EXTERNAL,
  989. X    "INITIAL",    INITIAL,
  990. X    "PUBLIC",    PUBLIC,
  991. X    "AT",        AT,
  992. X
  993. X        /* Misc reserved words */
  994. X    "PROCEDURE",    PROCEDURE,
  995. X    "REENTRANT",    REENTRANT,
  996. X    "INTERRUPT",    INTERRUPT,
  997. X
  998. X        /* End of list */
  999. X    "",        END_OF_FILE
  1000. X};
  1001. X
  1002. X
  1003. X/*
  1004. X *    Operator list
  1005. X */
  1006. XRESERVED_OPERATOR reserved_operators[] = {
  1007. X    "+",    "+",    PLUS,
  1008. X    "-",    "-",    MINUS,
  1009. X    "*",    "*",    TIMES,
  1010. X    "/",    "/",    DIVIDE,
  1011. X    "<>",    "!=",    NOT_EQUAL,
  1012. X    "<=",    "<=",    LESS_EQUAL,
  1013. X    ">=",    ">=",    GREATER_EQUAL,
  1014. X    "<",    "<",    LESS,
  1015. X    ">",    ">",    GREATER,
  1016. X    "=",    "=",    EQUAL,
  1017. X    ":=",    "=",    EQUATE,
  1018. X    "@",    "&",    AT_OP,
  1019. X    "",    "",    END_OF_FILE
  1020. X};
  1021. X
  1022. X/*
  1023. X *    Control directives list
  1024. X */
  1025. XRESERVED_WORD control_directives[] = {
  1026. X#ifdef    USE_ALL_CONTROLS
  1027. X    "CODE",        C_CODE,
  1028. X    "CO",        C_CODE,
  1029. X    "NOCODE",    C_NOCODE,
  1030. X    "NOCO",        C_NOCODE,
  1031. X    "COND",        C_COND,
  1032. X    "NOCOND",    C_NOCOND,
  1033. X    "DEBUG",    C_DEBUG,
  1034. X    "DB",        C_DEBUG,
  1035. X    "NODEBUG",    C_NODEBUG,
  1036. X    "NODB",        C_NODEBUG,
  1037. X    "EJECT",    C_EJECT,
  1038. X    "EJ",        C_EJECT,
  1039. X#endif
  1040. X    "IF",        C_IF,
  1041. X    "ELSEIF",    C_ELSEIF,
  1042. X    "ELSE",        C_ELSE,
  1043. X    "ENDIF",    C_ENDIF,
  1044. X    "INCLUDE",    C_INCLUDE,
  1045. X    "IC",        C_INCLUDE,
  1046. X#ifdef    USE_ALL_CONTROLS
  1047. X    "INTERFACE",    C_INTERFACE,
  1048. X    "ITF",        C_INTERFACE,
  1049. X    "LEFTMARGIN",    C_LEFTMARGIN,
  1050. X    "LM",        C_LEFTMARGIN,
  1051. X    "LIST",        C_LIST,
  1052. X    "LI",        C_LIST,
  1053. X    "NOLIST",    C_NOLIST,
  1054. X    "NOLI",        C_NOLIST,
  1055. X    "OBJECT",    C_OBJECT,
  1056. X    "OJ",        C_OBJECT,
  1057. X    "NOOBJECT",    C_NOOBJECT,
  1058. X    "NOOJ",        C_NOOBJECT,
  1059. X    "OPTIMIZE",    C_OPTIMIZE,
  1060. X    "OT",        C_OPTIMIZE,
  1061. X    "OVERFLOW",    C_OVERFLOW,
  1062. X    "OV",        C_OVERFLOW,
  1063. X    "NOOVERFLOW",    C_NOOVERFLOW,
  1064. X    "NOOV",        C_NOOVERFLOW,
  1065. X    "PAGELENGTH",    C_PAGELENGTH,
  1066. X    "PL",        C_PAGELENGTH,
  1067. X    "PAGEWIDTH",    C_PAGEWIDTH,
  1068. X    "PW",        C_PAGEWIDTH,
  1069. X    "PAGING",    C_PAGING,
  1070. X    "PI",        C_PAGING,
  1071. X    "NOPAGING",    C_NOPAGING,
  1072. X    "NOPI",        C_NOPAGING,
  1073. X    "PRINT",    C_PRINT,
  1074. X    "PR",        C_PRINT,
  1075. X    "NOPRINT",    C_NOPRINT,
  1076. X    "NOPR",        C_NOPRINT,
  1077. X    "RAM",        C_RAM,
  1078. X    "ROM",        C_ROM,
  1079. X    "SAVE",        C_SAVE,
  1080. X    "SA",        C_SAVE,
  1081. X    "RESTORE",    C_RESTORE,
  1082. X    "RS",        C_RESTORE,
  1083. X#endif
  1084. X    "SET",        C_SET,
  1085. X    "RESET",    C_RESET,
  1086. X#ifdef    USE_ALL_CONTROLS
  1087. X    "SMALL",    C_SMALL,
  1088. X    "SM",        C_SMALL,
  1089. X    "COMPACT",    C_COMPACT,
  1090. X    "CP",        C_COMPACT,
  1091. X    "MEDIUM",    C_MEDIUM,
  1092. X    "MD",        C_MEDIUM,
  1093. X    "LARGE",    C_LARGE,
  1094. X    "LA",        C_LARGE,
  1095. X    "SUBTITLE",    C_SUBTITLE,
  1096. X    "ST",        C_SUBTITLE,
  1097. X    "SYMBOLS",    C_SYMBOLS,
  1098. X    "SB",        C_SYMBOLS,
  1099. X    "NOSYMBOLS",    C_NOSYMBOLS,
  1100. X    "NOSB",        C_NOSYMBOLS,
  1101. X    "TITLE",    C_TITLE,
  1102. X    "TT",        C_TITLE,
  1103. X    "TYPE",        C_TYPE,
  1104. X    "TY",        C_TYPE,
  1105. X    "NOTYPE",    C_NOTYPE,
  1106. X    "NOTY",        C_NOTYPE,
  1107. X    "XREF",        C_XREF,
  1108. X    "XR",        C_XREF,
  1109. X    "NOXREF",    C_NOXREF,
  1110. X    "NOXR",        C_NOXREF,
  1111. X    "INTVECTOR",    C_INTVECTOR,
  1112. X    "IV",        C_INTVECTOR,
  1113. X    "NOINTVECTOR",    C_NOINTVECTOR,
  1114. X    "NOIV",        C_NOINTVECTOR,
  1115. X    "MOD86",    C_MOD86,
  1116. X    "MOD186",    C_MOD186,
  1117. X    "WORD16",    C_WORD16,
  1118. X    "W16",        C_WORD16,
  1119. X    "WORD32",    C_WORD32,
  1120. X    "W32",        C_WORD32,
  1121. X#endif
  1122. X        /* End of list */
  1123. X    "",        END_OF_FILE
  1124. X};
  1125. X
  1126. SHAR_EOF
  1127. chmod 0660 tkn_defs.h || echo "restore of tkn_defs.h fails"
  1128. sed 's/^X//' << 'SHAR_EOF' > tkn_ext.h &&
  1129. X
  1130. X/*
  1131. X *    Reserved word list
  1132. X */
  1133. Xextern    RESERVED_WORD reserved_words[];
  1134. X
  1135. X/*
  1136. X *    Operator list
  1137. X */
  1138. Xextern    RESERVED_OPERATOR reserved_operators[];
  1139. X
  1140. X/*
  1141. X *    Control directives list
  1142. X */
  1143. Xextern    RESERVED_WORD control_directives[];
  1144. SHAR_EOF
  1145. chmod 0660 tkn_ext.h || echo "restore of tkn_ext.h fails"
  1146. sed 's/^X//' << 'SHAR_EOF' > token.c &&
  1147. X#include <stdio.h>
  1148. X#include <string.h>
  1149. X#include "misc.h"
  1150. X#include "defs.h"
  1151. X#include "cvt.h"
  1152. X#include "struct.h"
  1153. X#include "tokens.h"
  1154. X#include "tkn_ext.h"
  1155. X
  1156. XBOOLEAN        parsing_literal;
  1157. XTOKEN        literal_token, eof_token;
  1158. Xchar        *lit_text_ptr;
  1159. X
  1160. Xextern    char    *text_buffer, *text_ptr;
  1161. Xextern    int    line_count;
  1162. Xextern    char    *line_ptr;
  1163. Xextern    char    current_file_name[];
  1164. X
  1165. X/*
  1166. X *    get_token() -    Fetch a token from the buffer and return type,
  1167. X *            pointer and associated white space.
  1168. X */
  1169. Xget_token(token)
  1170. XTOKEN    *token;
  1171. X{
  1172. X    RESERVED_WORD    *word_ptr;
  1173. X    RESERVED_OPERATOR    *op_ptr;
  1174. X    char        token_ch, last_token;
  1175. X    char        *token_name_ptr;
  1176. X    char        *op_name;
  1177. X    BOOLEAN        got_fraction;
  1178. X    BOOLEAN        cvt_case;
  1179. X    char        id[MAX_TOKEN_LENGTH], *id_ptr;
  1180. X    DECL_MEMBER        *decl_ptr;
  1181. X    DECL_ID        *decl_id;
  1182. X    int            token_class;
  1183. X    char        *cvt_ptr;
  1184. X    TOKEN        *token_ptr;
  1185. X
  1186. X    /* Point to start of white space (if any) */
  1187. X    token->white_space_start = text_ptr;
  1188. X    token->white_space_end = text_ptr;
  1189. X
  1190. X    /* Get first character */
  1191. X    token_ch = *text_ptr++;
  1192. X
  1193. X    /* Check for white space */
  1194. X    while ((token_ch == SPACE) || (token_ch == TAB) || (token_ch == CR) ||
  1195. X       (token_ch == LF) || (token_ch == '$') ||
  1196. X      ((token_ch == '/') && (*text_ptr == '*'))) {
  1197. X
  1198. X      if (token_ch == '$') {
  1199. X            /* Check for a control directive */
  1200. X        if ((text_ptr - 1 == text_buffer) ||
  1201. X                (*(text_ptr - 2) == '\n')) {
  1202. X            out_pre_white(token);
  1203. X            parse_control();
  1204. X
  1205. X                /* Reset start of white space */
  1206. X            token->white_space_start = text_ptr;
  1207. X            token->white_space_end = text_ptr;
  1208. X        } else {
  1209. X            parse_error("Illegal character");
  1210. X            return ERROR;
  1211. X        }
  1212. X      } else {
  1213. X
  1214. X    *(token->white_space_end++) = token_ch;
  1215. X
  1216. X    if (token_ch == LF) {
  1217. X            /* Increment input line count */
  1218. X        line_count++;
  1219. X            /* Point to start of line */
  1220. X        line_ptr = text_ptr;
  1221. X    } else
  1222. X
  1223. X    if (token_ch == '/') {
  1224. X            /* Comment - search to end */
  1225. X            /* Add '*' of comment */
  1226. X        token_ch = *(token->white_space_end++) = *text_ptr++;
  1227. X
  1228. X        do {
  1229. X            last_token = token_ch;
  1230. X            token_ch = *(token->white_space_end++) = *text_ptr++;
  1231. X            if (token_ch == LF) {
  1232. X                    /* Increment input line count */
  1233. X                line_count++;
  1234. X                    /* Point to start of line */
  1235. X                line_ptr = text_ptr;
  1236. X            }
  1237. X        } while ((token_ch != '/') || (last_token != '*'));
  1238. X    }
  1239. X      }
  1240. X
  1241. X      token_ch = *text_ptr++;
  1242. X    }
  1243. X
  1244. X
  1245. X    /* Point to start of current token */
  1246. X    token->token_start = text_ptr - 1;
  1247. X    /* Point to start of converted token */
  1248. X    token_name_ptr = token->token_name;
  1249. X
  1250. X    if (is_a_char(token_ch)) {
  1251. X        /* Process identifier */
  1252. X#ifdef CONVERT_CASE
  1253. X            /* Convert identifiers starting with an   */
  1254. X            /* upper-case character to opposite case. */
  1255. X        cvt_case = is_a_uc_char(token_ch);
  1256. X#else
  1257. X        cvt_case = FALSE;
  1258. X#endif
  1259. X    while (TRUE) {
  1260. X        if (is_a_char(token_ch)) {
  1261. X            if (cvt_case) {
  1262. X            if (is_a_uc_char(token_ch))
  1263. X                    /* Convert to lower-case character */
  1264. X                *token_name_ptr++ = token_ch + ' ';
  1265. X            else
  1266. X
  1267. X                    /* Convert to upper-case character */
  1268. X                *token_name_ptr++ = token_ch - ' ';
  1269. X            } else
  1270. X            *token_name_ptr++ = token_ch;
  1271. X        } else
  1272. X
  1273. X        if (is_a_digit(token_ch))
  1274. X            *token_name_ptr++ = token_ch;
  1275. X        else
  1276. X
  1277. X        if (token_ch == '_')
  1278. X            *token_name_ptr++ = token_ch;
  1279. X        else
  1280. X
  1281. X        if (token_ch == '$')
  1282. X#ifdef CONVERT_DOLLAR
  1283. X            *token_name_ptr++ = CONVERT_DOLLAR;
  1284. X#else
  1285. X            ;
  1286. X#endif
  1287. X        else
  1288. X            break;
  1289. X
  1290. X        token_ch = *text_ptr++;
  1291. X    }
  1292. X
  1293. X
  1294. X        /* Mark end of token */
  1295. X    text_ptr--;
  1296. X    token->token_length = text_ptr - token->token_start;
  1297. X    *token_name_ptr = '\0';
  1298. X
  1299. X        /* Get a copy of identifier */
  1300. X    (void) strcpy(id, token->token_name);
  1301. X        /* If lower-case, convert to upper case for comparison */
  1302. X    if (is_a_lc_char(*id)) {
  1303. X        for (id_ptr = id; *id_ptr; id_ptr++)
  1304. X            if (is_a_lc_char(*id_ptr))
  1305. X                *id_ptr -= ' ';
  1306. X    }
  1307. X
  1308. X        /* Check for reserved word */
  1309. X    for (word_ptr = &reserved_words[0]; word_ptr->token != END_OF_FILE;
  1310. X            word_ptr++)
  1311. X    {
  1312. X        if (!strcmp(word_ptr->name, id)) {
  1313. X
  1314. X            token->token_type = word_ptr->token;
  1315. X
  1316. X                /* Check for reserved operator */
  1317. X                switch (token->token_type) {
  1318. X
  1319. X                case AND :
  1320. X                op_name = AND_OP;
  1321. X                break;
  1322. X
  1323. X                case OR :
  1324. X                op_name = OR_OP;
  1325. X                break;
  1326. X
  1327. X                case NOT :
  1328. X                op_name = NOT_OP;
  1329. X                break;
  1330. X
  1331. X                case XOR :
  1332. X                op_name = "^";
  1333. X                break;
  1334. X
  1335. X                case MOD :
  1336. X                op_name = "%";
  1337. X                break;
  1338. X
  1339. X                case PLUS :
  1340. X                parse_error("Cannot convert PLUS operator");
  1341. X                token->token_class = token->token_type = ERROR;
  1342. X                return ERROR;
  1343. X
  1344. X                case MINUS :
  1345. X                parse_error("Cannot convert MINUS operator");
  1346. X                token->token_class = token->token_type = ERROR;
  1347. X                return ERROR;
  1348. X
  1349. X                default :
  1350. X                    /* Must not be an operator! */
  1351. X                token->token_class = RESERVED;
  1352. X                return RESERVED;
  1353. X                }
  1354. X
  1355. X                /* Switch to appropriate operator */
  1356. X            (void) strcpy(token->token_name, op_name);
  1357. X            token->token_class = OPERATOR;
  1358. X            return OPERATOR;
  1359. X        }
  1360. X    }
  1361. X
  1362. X        /* Not a reserved word - must be an identifier */
  1363. X    token->token_class = token->token_type = IDENTIFIER;
  1364. X
  1365. X        /* Check for a literal */
  1366. X    if (!parsing_literal && find_symbol(token, &decl_ptr, &decl_id) &&
  1367. X                (decl_ptr->type->token_type == LITERALLY)) {
  1368. X#ifdef CONVERT_CASE
  1369. X            /* Convert case of literal */
  1370. X        for (cvt_ptr = token->token_name; *cvt_ptr;
  1371. X                cvt_ptr++) {
  1372. X            if (is_a_uc_char(*cvt_ptr))
  1373. X                *cvt_ptr += 32;
  1374. X            else
  1375. X            if (is_a_lc_char(*cvt_ptr))
  1376. X                *cvt_ptr -= 32;
  1377. X        }
  1378. X#endif
  1379. X#ifdef PARSE_LITERALS
  1380. X            /* Yes - Has literal been parsed? */
  1381. X        if (decl_ptr->literal_token) {
  1382. X                /* Yes - return parsed literal token */
  1383. X                /* with token_name set to literal name */
  1384. X            token_ptr = decl_ptr->literal_token;
  1385. X            token->token_class = token_ptr->token_class;
  1386. X            token->token_type = token_ptr->token_type;
  1387. X            return token->token_class;
  1388. X        }
  1389. X#endif
  1390. X            /* Is literal a single token? */
  1391. X        lit_text_ptr = text_ptr;
  1392. X        text_ptr = decl_ptr->literal;
  1393. X        token_class = get_token(&literal_token);
  1394. X        if (get_token(&eof_token) == END_OF_FILE) {
  1395. X                /* Yes - return single token with */
  1396. X                /* token_name set to literal name */
  1397. X            token->token_class = token_class;
  1398. X            token->token_type = literal_token.token_type;
  1399. X            text_ptr = lit_text_ptr;
  1400. X            parsing_literal = FALSE;
  1401. X            return token->token_class;
  1402. X        }
  1403. X
  1404. X            /* No - parse complex literal and replace */
  1405. X            /* Use of literal declaration */
  1406. X        parsing_literal = TRUE;
  1407. X        text_ptr = lit_text_ptr;
  1408. X        parse_warning("Literal expanded");
  1409. X        text_ptr = decl_ptr->literal;
  1410. X        return get_token(token);
  1411. X    }
  1412. X
  1413. X    return IDENTIFIER;
  1414. X    } else
  1415. X
  1416. X    if (is_a_digit(token_ch)) {
  1417. X        /* Process number */
  1418. X        /* Flag not a floating point number */
  1419. X    got_fraction = FALSE;
  1420. X
  1421. X    while (TRUE) {
  1422. X        if (is_a_digit(token_ch))
  1423. X            *token_name_ptr++ = token_ch;
  1424. X        else
  1425. X
  1426. X        if (token_ch == '.') {
  1427. X            got_fraction = TRUE;
  1428. X            *token_name_ptr++ = token_ch;
  1429. X        } else
  1430. X
  1431. X        if ((token_ch == 'E') && got_fraction) {
  1432. X                /* Process exponent */
  1433. X            *token_name_ptr++ = token_ch;
  1434. X                /* Signed exponent? */
  1435. X            if ((*text_ptr != '+') && (*text_ptr != '-')) {
  1436. X                    /* No - default to + exponent */
  1437. X                *token_name_ptr++ = '+';
  1438. X            } else {
  1439. X                    /* Yes - add sign */
  1440. X                token_ch = *text_ptr++;
  1441. X                *token_name_ptr++ = token_ch;
  1442. X            }
  1443. X        } else
  1444. X
  1445. X            /* Assume it's a hex char or constant designator */
  1446. X        if (is_a_char(token_ch))
  1447. X            *token_name_ptr++ = token_ch;
  1448. X        else
  1449. X
  1450. X        if (token_ch != '$')
  1451. X            break;
  1452. X
  1453. X        token_ch = *text_ptr++;
  1454. X    }
  1455. X
  1456. X        /* Point to last character in constant */
  1457. X    token_name_ptr--;
  1458. X    token_ch = *token_name_ptr;
  1459. X
  1460. X    if (got_fraction) {
  1461. X            /* Floating point - add suffix */
  1462. X        *++token_name_ptr = 'F';
  1463. X            /* Mark end of token */
  1464. X        *++token_name_ptr = '\0';
  1465. X    } else
  1466. X
  1467. X    if (token_ch == 'B') {
  1468. X        parse_error("Binary constant");
  1469. X        token->token_class = token->token_type = ERROR;
  1470. X        return ERROR;
  1471. X    } else
  1472. X
  1473. X    if ((token_ch == 'O') || (token_ch == 'Q')) {
  1474. X            /* Octal constant */
  1475. X            /* Mark end of token */
  1476. X        *token_name_ptr++ = '\0';
  1477. X            /* Move constant up 1 character */
  1478. X        while (token_name_ptr != token->token_name) {
  1479. X            *token_name_ptr = *(token_name_ptr - 1);
  1480. X            token_name_ptr--;
  1481. X        }
  1482. X
  1483. X            /* Make a C octal constant */
  1484. X        *token_name_ptr = '0';
  1485. X    } else
  1486. X
  1487. X    if (token_ch == 'H') {
  1488. X            /* Hex constant */
  1489. X            /* Mark end of token */
  1490. X        *token_name_ptr++ = '\0';
  1491. X        token_name_ptr++;
  1492. X            /* Move constant up 2 characters */
  1493. X        while (token_name_ptr != (token->token_name + 1)) {
  1494. X            *token_name_ptr = *(token_name_ptr - 2);
  1495. X            token_name_ptr--;
  1496. X        }
  1497. X
  1498. X            /* Make a C hex constant */
  1499. X        *token_name_ptr-- = 'x';
  1500. X        *token_name_ptr = '0';
  1501. X    } else
  1502. X
  1503. X    if (token_ch == 'D')
  1504. X            /* Decimal constant - ignore 'D' */
  1505. X        *token_name_ptr = '\0';
  1506. X    else
  1507. X            /* Regular constant */
  1508. X        *++token_name_ptr = '\0';
  1509. X
  1510. X        /* Mark end of token */
  1511. X    text_ptr--;
  1512. X    token->token_length = text_ptr - token->token_start;
  1513. X
  1514. X    token->token_class = token->token_type = NUMERIC;
  1515. X    return NUMERIC;
  1516. X    } else {
  1517. X
  1518. X        /* Check for operator */
  1519. X    for (op_ptr = &reserved_operators[0]; op_ptr->name != END_OF_FILE;
  1520. X                op_ptr++) {
  1521. X        token->token_length = strlen(op_ptr->operator);
  1522. X        if (!strncmp(text_ptr - 1, op_ptr->operator,
  1523. X            token->token_length)) {
  1524. X                /* Found operator */
  1525. X                /* Save converted type */
  1526. X            (void) strcpy(token->token_name, op_ptr->cvt_operator);
  1527. X            token->token_type = op_ptr->name;
  1528. X                /* Point past operator */
  1529. X            text_ptr += token->token_length - 1;
  1530. X                
  1531. X            token->token_class = OPERATOR;
  1532. X            return OPERATOR;
  1533. X        }
  1534. X    }
  1535. X
  1536. X        /* Assume single character token */
  1537. X    *token_name_ptr++ = token_ch;
  1538. X    *token_name_ptr = '\0';
  1539. X        /* Mark end of token so far */
  1540. X    token->token_length = 1;
  1541. X
  1542. X
  1543. X    switch (token_ch) {
  1544. X
  1545. X    case ';' :
  1546. X        token->token_class = token->token_type = END_OF_LINE;
  1547. X        return END_OF_LINE;
  1548. X
  1549. X    case ':' :
  1550. X        token->token_class = token->token_type = LABEL;
  1551. X        return LABEL;
  1552. X
  1553. X    case ',' :
  1554. X        token->token_class = token->token_type = COMMA;
  1555. X        return COMMA;
  1556. X
  1557. X    case '.' :
  1558. X        token->token_class = token->token_type = PERIOD;
  1559. X        return PERIOD;
  1560. X
  1561. X    case '(' :
  1562. X        token->token_class = token->token_type = LEFT_PAREN;
  1563. X        return LEFT_PAREN;
  1564. X
  1565. X    case ')' :
  1566. X        token->token_class = token->token_type = RIGHT_PAREN;
  1567. X        return RIGHT_PAREN;
  1568. X
  1569. X    case '\'' :
  1570. X            /* String constant */
  1571. X        token_name_ptr--;
  1572. X        while (1) {
  1573. X            if (*text_ptr == '\'') {
  1574. X                if ((*(text_ptr + 1) == '\''))
  1575. X                    text_ptr++;
  1576. X                else
  1577. X                    break;
  1578. X            }
  1579. X            *token_name_ptr++ = *text_ptr++;
  1580. X        }
  1581. X
  1582. X        text_ptr++;
  1583. X        *token_name_ptr++ = '\0';
  1584. X        token->token_length = strlen(token->token_name);
  1585. X
  1586. X        token->token_class = token->token_type = STRING;
  1587. X        return STRING;
  1588. X
  1589. X    case 0:
  1590. X        if (parsing_literal) {
  1591. X                /* Done parsing literal -  */
  1592. X                /* Switch back to text_ptr */
  1593. X            parsing_literal = FALSE;
  1594. X            text_ptr = lit_text_ptr;
  1595. X            return get_token(token);
  1596. X        }
  1597. X        token->token_class = token->token_type = END_OF_FILE;
  1598. X        return END_OF_FILE;
  1599. X
  1600. X    default:
  1601. X        parse_error("Illegal character");
  1602. X            /* Eat the evidence */
  1603. X        token->token_name[0] = '\0';
  1604. X        token->token_class = token->token_type = ERROR;
  1605. X        return ERROR;
  1606. X    }
  1607. X    }
  1608. X}
  1609. X
  1610. X/*
  1611. X *    Copy source token to destination token
  1612. X */
  1613. Xtoken_copy(src, dest)
  1614. XTOKEN    *src, *dest;
  1615. X{
  1616. X    dest->token_class = src->token_class;
  1617. X    dest->token_type = src->token_type;
  1618. X    (void) strcpy(dest->token_name, src->token_name);
  1619. X    dest->token_start = src->token_start;
  1620. X    dest->token_length = src->token_length;
  1621. X    dest->white_space_start = src->white_space_start;
  1622. X    dest->white_space_end = src->white_space_end;
  1623. X}
  1624. X
  1625. SHAR_EOF
  1626. chmod 0660 token.c || echo "restore of token.c fails"
  1627. sed 's/^X//' << 'SHAR_EOF' > tokens.h &&
  1628. X/**************************
  1629. X *    Token classes
  1630. X *************************/
  1631. X#define END_OF_FILE    0
  1632. X#define RESERVED    1
  1633. X#define IDENTIFIER    2
  1634. X#define NUMERIC        3
  1635. X#define OPERATOR    4
  1636. X#define STRING        5
  1637. X#define LABEL        6
  1638. X#define END_OF_LINE    7
  1639. X#define COMMA        8
  1640. X#define PERIOD        9
  1641. X#define LEFT_PAREN    10
  1642. X#define RIGHT_PAREN    11
  1643. X#define SUBSCRIPT    12
  1644. X#define MODULE        13
  1645. X#define ERROR        19
  1646. X
  1647. X
  1648. X/**************************
  1649. X *    Token types
  1650. X *************************/
  1651. X/*
  1652. X *    Operators
  1653. X */
  1654. X#define PLUS        20    /* +    */
  1655. X#define MINUS        21    /* -    */
  1656. X#define TIMES        22    /* *    */
  1657. X#define DIVIDE        23    /* /    */
  1658. X#define NOT_EQUAL    24    /* <>    */
  1659. X#define LESS_EQUAL    25    /* <=    */
  1660. X#define GREATER_EQUAL    26    /* >=    */
  1661. X#define LESS        27    /* <    */
  1662. X#define GREATER        28    /* >    */
  1663. X#define EQUAL        29    /* =    */
  1664. X#define EQUATE        30    /* :=    */
  1665. X#define COLON        31    /* :    */
  1666. X#define AT_OP        32    /* @    */
  1667. X
  1668. X/*
  1669. X *    Reserved word values
  1670. X */
  1671. X    /* Statements */
  1672. X#define DECLARE        40
  1673. X#define DO        41
  1674. X#define END        42
  1675. X#define IF        43
  1676. X#define THEN        44
  1677. X#define ELSE        45
  1678. X#define GOTO        46
  1679. X#define GO        47
  1680. X#define CALL        48
  1681. X#define RETURN        49
  1682. X#define DISABLE        50
  1683. X#define ENABLE        51
  1684. X#define OUTPUT        52
  1685. X#define OUTWORD        53
  1686. X#define OUTHWORD    54
  1687. X
  1688. X    /* Operators */
  1689. X#define AND        60
  1690. X#define OR        61
  1691. X#define XOR        62
  1692. X#define NOT        63
  1693. X#define MOD        64
  1694. X
  1695. X    /* DO options */
  1696. X#define CASE        70
  1697. X#define WHILE        71
  1698. X#define TO        72
  1699. X#define BY        73
  1700. X
  1701. X    /* DECLARE types */
  1702. X#define BYTE        80
  1703. X#define WORD        81
  1704. X#define DWORD        82
  1705. X#define INTEGER        83
  1706. X#define REAL        84
  1707. X#define ADDRESS        85
  1708. X#define SELECTOR    86
  1709. X#define POINTER        87
  1710. X#define STRUCTURE    88
  1711. X
  1712. X    /* DECLARE options */
  1713. X#define BASED        90
  1714. X#define LITERALLY    91
  1715. X#define DATA        92
  1716. X#define EXTERNAL    93
  1717. X#define INITIAL        94
  1718. X#define PUBLIC        95
  1719. X#define AT        96
  1720. X
  1721. X    /* Misc reserved words */
  1722. X#define PROCEDURE    101
  1723. X#define REENTRANT    102
  1724. X#define INTERRUPT    103
  1725. X
  1726. X    /* Control Directives */
  1727. X#define C_CODE        200
  1728. X#define C_NOCODE    201
  1729. X#define C_COND        202
  1730. X#define C_NOCOND    203
  1731. X#define C_DEBUG        204
  1732. X#define C_NODEBUG    205
  1733. X#define C_EJECT        206
  1734. X#define C_IF        207
  1735. X#define C_ELSEIF    208
  1736. X#define C_ELSE        209
  1737. X#define C_ENDIF        210
  1738. X#define C_INCLUDE    211
  1739. X#define C_INTERFACE    212
  1740. X#define C_LEFTMARGIN    213
  1741. X#define C_LIST        214
  1742. X#define C_NOLIST    215
  1743. X#define C_OBJECT    216
  1744. X#define C_NOOBJECT    217
  1745. X#define C_OPTIMIZE    218
  1746. X#define C_OVERFLOW    219
  1747. X#define C_NOOVERFLOW    220
  1748. X#define C_PAGELENGTH    221
  1749. X#define C_PAGEWIDTH    222
  1750. X#define C_PAGING    223
  1751. X#define C_NOPAGING    224
  1752. X#define C_PRINT        225
  1753. X#define C_NOPRINT    226
  1754. X#define C_RAM        227
  1755. X#define C_ROM        228
  1756. X#define C_SAVE        229
  1757. X#define C_RESTORE    230
  1758. X#define C_SET        231
  1759. X#define C_RESET        232
  1760. X#define C_SMALL        233
  1761. X#define C_COMPACT    234
  1762. X#define C_MEDIUM    235
  1763. X#define C_LARGE        236
  1764. X#define C_SUBTITLE    237
  1765. X#define C_SYMBOLS    238
  1766. X#define C_NOSYMBOLS    239
  1767. X#define C_TITLE        240
  1768. X#define C_TYPE        241
  1769. X#define C_NOTYPE    242
  1770. X#define C_XREF        243
  1771. X#define C_NOXREF    244
  1772. X#define C_INTVECTOR    245
  1773. X#define C_NOINTVECTOR    246
  1774. X#define C_MOD86        247
  1775. X#define C_MOD186    248
  1776. X#define C_WORD16    249
  1777. X#define C_WORD32    250
  1778. X
  1779. SHAR_EOF
  1780. chmod 0660 tokens.h || echo "restore of tokens.h fails"
  1781. sed 's/^X//' << 'SHAR_EOF' > typedefs.c &&
  1782. Xtypedef unsigned char BYTE;
  1783. Xtypedef unsigned short WORD;
  1784. Xtypedef unsigned int DWORD;
  1785. Xtypedef short INTEGER;
  1786. Xtypedef float REAL;
  1787. X
  1788. SHAR_EOF
  1789. chmod 0660 typedefs.c || echo "restore of typedefs.c fails"
  1790. sed 's/^X//' << 'SHAR_EOF' > version.c &&
  1791. Xchar    version[] = "Version 1.02 (Alpha)";
  1792. SHAR_EOF
  1793. chmod 0644 version.c || echo "restore of version.c fails"
  1794. rm -f s2_seq_.tmp
  1795. echo "You have unpacked the last part"
  1796. exit 0
  1797.