PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/ojc-core/encodersl/encoder-coco/src/com/sun/encoder/coco/model/CocoLanguage.java

https://bitbucket.org/openesb/openesb-components
Java | 1092 lines | 693 code | 83 blank | 316 comment | 25 complexity | c0f726a2a39af8dcff7a0612173b0dfa MD5 | raw file
Possible License(s): AGPL-3.0
  1. /*
  2. * BEGIN_HEADER - DO NOT EDIT
  3. *
  4. * The contents of this file are subject to the terms
  5. * of the Common Development and Distribution License
  6. * (the "License"). You may not use this file except
  7. * in compliance with the License.
  8. *
  9. * You can obtain a copy of the license at
  10. * https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
  11. * See the License for the specific language governing
  12. * permissions and limitations under the License.
  13. *
  14. * When distributing Covered Code, include this CDDL
  15. * HEADER in each file and include the License file at
  16. * https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
  17. * If applicable add the following below this CDDL HEADER,
  18. * with the fields enclosed by brackets "[]" replaced with
  19. * your own identifying information: Portions Copyright
  20. * [year] [name of copyright owner]
  21. */
  22. /*
  23. * @(#)CocoLanguage.java
  24. *
  25. * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
  26. *
  27. * END_HEADER - DO NOT EDIT
  28. */
  29. package com.sun.encoder.coco.model;
  30. import java.util.Collections;
  31. import java.util.HashSet;
  32. import java.util.Set;
  33. import java.util.regex.Pattern;
  34. /**
  35. * Encapsulates information about the Cobol language, as it pertains to
  36. * Copybook contents.
  37. *
  38. * @author Noel Ang
  39. *
  40. * @version $Revision: 1.1 $
  41. */
  42. public class CocoLanguage {
  43. /**
  44. * Cobol SPACE character
  45. */
  46. public static final String SPACE = " ";
  47. /**
  48. * Cobol plus character
  49. */
  50. public static final String PLUS = "+";
  51. /**
  52. * Cobol hyphen character
  53. */
  54. public static final String HYPHEN = "-";
  55. /**
  56. * Cobol asterisk character
  57. */
  58. public static final String ASTERISK = "*";
  59. /**
  60. * Cobol slant character
  61. */
  62. public static final String SLANT = "/";
  63. /**
  64. * Cobol equal character
  65. */
  66. public static final String EQUAL = "=";
  67. /**
  68. * Cobol currency character
  69. */
  70. public static final String CURRENCY = "$";
  71. /**
  72. * Cobol comma character
  73. */
  74. public static final String COMMA = ",";
  75. /**
  76. * Cobol comma separator character
  77. */
  78. public static final String COMMA_S = ", ";
  79. /**
  80. * Cobol semicolon character
  81. */
  82. public static final String SEMICOLON = ";";
  83. /**
  84. * Cobol semicolon separator character
  85. */
  86. public static final String SEMICOLON_S = "; ";
  87. /**
  88. * Cobol colon character
  89. */
  90. public static final String COLON = ":";
  91. /**
  92. * Cobol period character
  93. */
  94. public static final String PERIOD = ".";
  95. /**
  96. * Cobol period separator character
  97. */
  98. public static final String PERIOD_S = ". ";
  99. /**
  100. * Cobol quotation character
  101. */
  102. public static final String QUOTATION = "\"";
  103. /**
  104. * Cobol quotation separator character
  105. */
  106. public static final String QUOTATION_S = "\" ";
  107. /**
  108. * Cobol left parenthesis character
  109. */
  110. public static final String LPARENS = "(";
  111. /**
  112. * Cobol right parenthesis character
  113. */
  114. public static final String RPARENS = ")";
  115. /**
  116. * Cobol greater-than character
  117. */
  118. public static final String GREATER = ">";
  119. /**
  120. * Cobol less-than character
  121. */
  122. public static final String LESS = "<";
  123. /**
  124. * Cobol apostrophe character
  125. */
  126. public static final String APOSTROPHE = "\'";
  127. /**
  128. * Cobol apostrophe separator character
  129. */
  130. public static final String APOSTROPHE_S = "\' ";
  131. /**
  132. * Cobol non-numeric literal opening
  133. */
  134. public static final String NONNUMERIC_LIT_OPEN = "X\"";
  135. /**
  136. * Cobol non-numeric literal opening
  137. */
  138. public static final String NONNUMERIC_LIT_OPEN_APOS = "X'";
  139. /**
  140. * Cobol non-numeric literal opening
  141. */
  142. public static final String NONNUMERIC_LIT_DBCSG_OPEN = "G\"";
  143. /**
  144. * Cobol non-numeric literal opening
  145. */
  146. public static final String NONNUMERIC_LIT_DBCSG_OPEN_APOS = "G'";
  147. /**
  148. * Cobol non-numeric literal opening
  149. */
  150. public static final String NONNUMERIC_LIT_DBCSN_OPEN = "N\"";
  151. /**
  152. * Cobol non-numeric literal opening
  153. */
  154. public static final String NONNUMERIC_LIT_DBCSN_OPEN_APOS = "N'";
  155. /**
  156. * Cobol null non-numeric literal opening
  157. */
  158. public static final String NONNUMERIC_NULL_LIT_OPEN = "Z\"";
  159. /**
  160. * Cobol null non-numeric literal opening
  161. */
  162. public static final String NONNUMERIC_NULL_LIT_OPEN_APOS = "Z'";
  163. /**
  164. * Cobol pseudo-text delimiter
  165. */
  166. public static final String PSEUDOTEXT_DELIM = "==";
  167. /**
  168. * Debugging line indicator
  169. */
  170. public static final String DEBUGGING_INDICATOR = "D";
  171. /**
  172. * Cobol figurative constant ZERO
  173. */
  174. public static final String ZERO_FIGCONST = "ZERO";
  175. /**
  176. * Cobol figurative constant ZERO
  177. */
  178. public static final String ZEROS_FIGCONST = "ZEROS";
  179. /**
  180. * Cobol figurative constant ZERO
  181. */
  182. public static final String ZEROES_FIGCONST = "ZEROES";
  183. /**
  184. * Cobol figurative constant SPACE
  185. */
  186. public static final String SPACE_FIGCONST = "SPACE";
  187. /**
  188. * Cobol figurative constant SPACES
  189. */
  190. public static final String SPACES_FIGCONST = "SPACES";
  191. /**
  192. * Cobol figurative constant HIGH-VALUE
  193. */
  194. public static final String HIGHVALUE_FIGCONST = "HIGH-VALUE";
  195. /**
  196. * Cobol figurative constant HIGH-VALUES
  197. */
  198. public static final String HIGHVALUES_FIGCONST = "HIGH-VALUES";
  199. /**
  200. * Cobol figurative constant LOW-VALUES
  201. */
  202. public static final String LOWVALUE_FIGCONST = "LOW-VALUE";
  203. /**
  204. * Cobol figurative constant LOW-VALUES
  205. */
  206. public static final String LOWVALUES_FIGCONST = "LOW-VALUES";
  207. /**
  208. * Cobol figurative constant QUOTE
  209. */
  210. public static final String QUOTE_FIGCONST = "QUOTE";
  211. /**
  212. * Cobol figurative constant QUOTES
  213. */
  214. public static final String QUOTES_FIGCONST = "QUOTES";
  215. /**
  216. * Cobol figurative constant ALL
  217. */
  218. public static final String ALL_FIGCONST = "ALL";
  219. /**
  220. * Cobol figurative constant NULL
  221. */
  222. public static final String NULL_FIGCONST = "NULL";
  223. /**
  224. * Cobol figurative constant NULLS
  225. */
  226. public static final String NULLS_FIGCONST = "NULLS";
  227. /**
  228. * Maximum valid length for a numeric literal
  229. */
  230. public static final int NUMLITERAL_MAX_LENGTH = 30;
  231. /**
  232. * Maximum valid length for a non-numeric literal
  233. *
  234. */
  235. public static final int NONNUMLITERAL_MAX_LENGTH = 160;
  236. /**
  237. * Maximum valid length for a Cobol word
  238. */
  239. public static final int WORD_MAX_LENGTH = 30;
  240. /**
  241. * Maximum valid length for a separator
  242. */
  243. public static final int SEPARATOR_MAX_LENGTH = 2;
  244. /**
  245. * Minimum legal level number (excluding special level numbers)
  246. */
  247. public static final int MIN_LEVEL_NUMBER = 1;
  248. /**
  249. * Maximum legal level number (excluding special level numbers)
  250. */
  251. public static final int MAX_LEVEL_NUMBER = 49;
  252. protected static Set mSpecialCharacterSet;
  253. protected static Set mSeparators;
  254. protected static Set mReservedWords;
  255. protected static Set mFigurativeConstants;
  256. protected static Set mClauseWords;
  257. static {
  258. mSpecialCharacterSet = buildSpecialCharacterSet();
  259. mSeparators = buildSeparatorSet();
  260. mReservedWords = buildReservedWordSet();
  261. mFigurativeConstants = buildFigurativeConstantSet();
  262. mClauseWords = buildClauseWordSet();
  263. }
  264. private static final Pattern cNumericLiteralPattern =
  265. Pattern.compile("[+-]?(?:(?:\\d+\\.\\d+[Ee][+-]\\d\\d)|(?:(?:\\d+\\.?\\d+)|(?:\\d+)))" ,
  266. Pattern.CASE_INSENSITIVE);
  267. private static final Pattern cNonumericLiteralStartPattern =
  268. Pattern.compile("[GNXZ]?[\"']", Pattern.CASE_INSENSITIVE);
  269. /**
  270. * Indicates whether a character is part of the Cobol character set.
  271. * @param ch the character in consideration
  272. * @return true if ch is part of the set, or else false
  273. */
  274. public static boolean isInCobolCharSet(char ch) {
  275. boolean isInSet = false;
  276. isInSet |= Character.isLetterOrDigit(ch);
  277. isInSet |= mSpecialCharacterSet.contains(String.valueOf(ch));
  278. return isInSet;
  279. }
  280. /**
  281. * Indicates whether a string renders a numeric literal.
  282. *
  283. * @param str the string in consideration
  284. * @return true if str is formatted as a numeric literal, or else false
  285. */
  286. public static boolean isNumericLiteral(String str) {
  287. return cNumericLiteralPattern.matcher(str).matches();
  288. }
  289. /**
  290. * Indicates whether a string renders the starting delimiter of a
  291. * nonnumeric literal.
  292. *
  293. * @param str the string in consideration
  294. * @return true if str is formatted as a numeric literal, or else false
  295. */
  296. public static boolean isNonnumericLiteralStart(String str) {
  297. return cNonumericLiteralStartPattern.matcher(str).matches();
  298. }
  299. /**
  300. * Indicates whether a string is a Cobol separator character-string.
  301. * @param str the string in consideration
  302. * @return true if str is a separator, or else false
  303. */
  304. public static boolean isSeparator(String str) {
  305. if (!isAllCaps(str)) {
  306. str = str.toUpperCase();
  307. }
  308. return mSeparators.contains(str);
  309. }
  310. /**
  311. * Indicates whether a character is a Cobol separator character-string.
  312. * @param ch the character in consideration
  313. * @return true if str is a separator, or else false
  314. */
  315. public static boolean isSeparator(char ch) {
  316. ch = Character.toUpperCase(ch);
  317. return mSeparators.contains(String.valueOf(ch))
  318. ||
  319. (ch == 0xe || ch == 0xf); // shift-out and shift-in DBCS characters
  320. }
  321. /**
  322. * Indicates whether a string is a Cobol separator character-string.
  323. * Convenience method.
  324. *
  325. * @param ch1 the first character of the string in consideration
  326. * @param ch2 the second character of the string in consideration
  327. * @return true if str is a separator, or else false
  328. * @see #isSeparator(java.lang.String)
  329. */
  330. public static boolean isSeparator(char ch1, char ch2) {
  331. ch1 = Character.toUpperCase(ch1);
  332. ch2 = Character.toUpperCase(ch2);
  333. char[] chr = new char[] { ch1, ch2 };
  334. String str = String.valueOf(chr);
  335. return mSeparators.contains(str);
  336. }
  337. /**
  338. * Indicates whether the byte is a Cobol separator.
  339. * Convenience method.
  340. *
  341. * @param byt Candidate separator
  342. * @see #isSeparator(java.lang.String)
  343. */
  344. public static boolean isSeparator(byte byt) {
  345. byt &= 0x7F;
  346. return (byt == 0xE || byt == 0xF || mSeparators.contains(String.valueOf(byt)));
  347. }
  348. /**
  349. * Indicates whether a string is a reserved word in Cobol.
  350. * @param str the string in consideration
  351. * @return true if str is a reserved word, or else false
  352. */
  353. public static boolean isReservedWord(String str) {
  354. if (!isAllCaps(str)) {
  355. str = str.toUpperCase();
  356. }
  357. return mReservedWords.contains(str);
  358. }
  359. /**
  360. * Indicates whether a string is a Cobol word. A Cobol word is any
  361. * word that is reserved, user-defined, or is a system name. It has length
  362. * and composition requirements as well. Consult the Cobol Language Reference
  363. * for details.
  364. *
  365. * <p>This implementation does not care about system names nor user-defined
  366. * names, so no checks are made against these types.</p>
  367. *
  368. * @param str the string in consideration
  369. *
  370. * @return true if str is a Cobol word, or else false
  371. */
  372. public static boolean isCobolWord(String str) {
  373. if (!isAllCaps(str)) {
  374. str = str.toUpperCase();
  375. }
  376. boolean isWord = false;
  377. if (str != null) {
  378. isWord = mReservedWords.contains(str);
  379. isWord &= (str.length() > 0) && (str.length() <= 30);
  380. isWord &= Character.isLetterOrDigit(str.charAt(0));
  381. isWord &= Character.isLetterOrDigit(str.charAt(str.length() - 1));
  382. if (isWord) {
  383. for (int i = 1; isWord && (i < str.length() - 1); i++) {
  384. isWord &= Character.isLetterOrDigit(str.charAt(i))
  385. || (str.charAt(i) == HYPHEN.charAt(0));
  386. }
  387. }
  388. }
  389. return isWord;
  390. }
  391. /**
  392. * Indicates whether the word is a starting word for an item clause.
  393. *
  394. * @param word The word in consideration
  395. *
  396. * @return <code>true</code> if the word marks the beginning of a clause
  397. */
  398. public static boolean isClauseWord(String word) {
  399. if (!isAllCaps(word)) {
  400. word = word.toUpperCase();
  401. }
  402. return mClauseWords.contains(word);
  403. }
  404. /**
  405. * Indicates whether a string is a figurative constant.
  406. *
  407. * @param str the string in consideration
  408. * @return true if str is a figurative constant, or else false
  409. */
  410. public static boolean isFigurativeConstant(String str) {
  411. if (!isAllCaps(str)) {
  412. str = str.toUpperCase();
  413. }
  414. return mFigurativeConstants.contains(str);
  415. }
  416. /**
  417. * Indicates whether the string symbol represents a currency symbol.
  418. *
  419. * @param str the string in consideration
  420. * @return true if str is a currency symbol, or else false
  421. */
  422. public static boolean isCurrencySymbol(String str) {
  423. return str.equals("$");
  424. }
  425. /**
  426. * Creates a set consisting of all Cobol figurative constants.
  427. * The set created is unmodifiable.
  428. *
  429. * @return the set of all Cobol figurative constants.
  430. */
  431. protected static Set buildFigurativeConstantSet() {
  432. Set set = new HashSet();
  433. set.add(ZERO_FIGCONST);
  434. set.add(ZEROS_FIGCONST);
  435. set.add(ZEROES_FIGCONST);
  436. set.add(HIGHVALUE_FIGCONST);
  437. set.add(HIGHVALUES_FIGCONST);
  438. set.add(SPACE_FIGCONST);
  439. set.add(SPACES_FIGCONST);
  440. set.add(LOWVALUE_FIGCONST);
  441. set.add(LOWVALUES_FIGCONST);
  442. set.add(QUOTE_FIGCONST);
  443. set.add(QUOTES_FIGCONST);
  444. set.add(ALL_FIGCONST);
  445. set.add(NULL_FIGCONST);
  446. set.add(NULLS_FIGCONST);
  447. return Collections.unmodifiableSet(set);
  448. }
  449. /**
  450. * Creates a set consisting of all Cobol separator character-strings.
  451. * The set created is unmodifiable.
  452. *
  453. * @return the set of all Cobol separator character-strings.
  454. */
  455. protected static Set buildSeparatorSet() {
  456. Set set = new HashSet();
  457. set.add(SPACE);
  458. set.add(PERIOD);
  459. set.add(PERIOD_S);
  460. set.add(COMMA);
  461. set.add(COMMA_S);
  462. set.add(COLON);
  463. set.add(SEMICOLON);
  464. set.add(SEMICOLON_S);
  465. set.add(LPARENS);
  466. set.add(RPARENS);
  467. set.add(QUOTATION);
  468. set.add(QUOTATION_S);
  469. set.add(APOSTROPHE);
  470. set.add(APOSTROPHE_S);
  471. set.add(NONNUMERIC_LIT_OPEN);
  472. set.add(NONNUMERIC_LIT_OPEN_APOS);
  473. set.add(NONNUMERIC_LIT_DBCSG_OPEN);
  474. set.add(NONNUMERIC_LIT_DBCSG_OPEN_APOS);
  475. set.add(NONNUMERIC_LIT_DBCSN_OPEN);
  476. set.add(NONNUMERIC_LIT_DBCSN_OPEN_APOS);
  477. set.add(NONNUMERIC_NULL_LIT_OPEN);
  478. set.add(NONNUMERIC_NULL_LIT_OPEN_APOS);
  479. set.add(PSEUDOTEXT_DELIM);
  480. return Collections.unmodifiableSet(set);
  481. }
  482. /**
  483. * Creates a set consisting of strings that represent all Cobol special
  484. * characters. The set created is unmodifiable.
  485. *
  486. * @return the set of all Cobol special characters, as strings
  487. */
  488. protected static Set buildSpecialCharacterSet() {
  489. Set set = new HashSet();
  490. set.add(SPACE);
  491. set.add(PLUS);
  492. set.add(HYPHEN);
  493. set.add(ASTERISK);
  494. set.add(SLANT);
  495. set.add(EQUAL);
  496. set.add(CURRENCY);
  497. set.add(COMMA);
  498. set.add(SEMICOLON);
  499. set.add(COLON);
  500. set.add(PERIOD);
  501. set.add(QUOTATION);
  502. set.add(LPARENS);
  503. set.add(RPARENS);
  504. set.add(GREATER);
  505. set.add(LESS);
  506. set.add(APOSTROPHE);
  507. return Collections.unmodifiableSet(set);
  508. }
  509. /**
  510. * Creates a set consisting of Cobol reserved words.
  511. * The set created is unmodifiable.
  512. *
  513. * @return the set of all Cobol reserved words
  514. */
  515. protected static Set buildReservedWordSet() {
  516. Set set = new HashSet();
  517. set.add("ACCEPT");
  518. set.add("ACCESS");
  519. set.add("ADD");
  520. set.add("ADDRESS");
  521. set.add("ADVANCING");
  522. set.add("AFTER");
  523. set.add("ALL");
  524. set.add("ALPHABET");
  525. set.add("ALPHABETIC");
  526. set.add("ALPHABETIC-LOWER");
  527. set.add("ALPHABETIC-UPPER");
  528. set.add("ALPHANUMERIC");
  529. set.add("ALPHANUMERIC-EDITED");
  530. set.add("ALSO");
  531. set.add("ALTER");
  532. set.add("ALTERNATE");
  533. set.add("AND");
  534. set.add("ANY");
  535. set.add("APPLY");
  536. set.add("ARE");
  537. set.add("AREA");
  538. set.add("AREAS");
  539. set.add("ASCENDING");
  540. set.add("ASSIGN");
  541. set.add("AT");
  542. set.add("AUTHOR");
  543. set.add("AUTOMATIC");
  544. set.add("BASIS");
  545. set.add("BEFORE");
  546. set.add("BEGINNING");
  547. set.add("BINARY");
  548. //set.add("BLANK");
  549. set.add("BLOCK");
  550. set.add("BOTTOM");
  551. set.add("BY");
  552. set.add("CALL");
  553. set.add("CANCEL");
  554. set.add("CBL");
  555. set.add("CD");
  556. set.add("CF");
  557. set.add("CH");
  558. set.add("CHARACTER");
  559. set.add("CHARACTERS");
  560. set.add("CLASS");
  561. set.add("CLASS-ID");
  562. set.add("CLOCK-UNITS");
  563. set.add("CLOSE");
  564. set.add("COBOL");
  565. set.add("CODE");
  566. set.add("CODE-SET");
  567. set.add("COLLATING");
  568. set.add("COLUMN");
  569. set.add("COM-REG");
  570. set.add("COMMA");
  571. set.add("COMMON");
  572. set.add("COMMUNICATION");
  573. set.add("COMP");
  574. set.add("COMP-1");
  575. set.add("COMP-2");
  576. set.add("COMP-3");
  577. set.add("COMP-4");
  578. set.add("COMP-5");
  579. set.add("COMPUTATIONAL");
  580. set.add("COMPUTATIONAL-1");
  581. set.add("COMPUTATIONAL-2");
  582. set.add("COMPUTATIONAL-3");
  583. set.add("COMPUTATIONAL-4");
  584. set.add("COMPUTATIONAL-5");
  585. set.add("COMPUTE");
  586. set.add("CONFIGURATION");
  587. set.add("CONTAINS");
  588. set.add("CONTENT");
  589. set.add("CONTINUE");
  590. set.add("CONTROL");
  591. set.add("CONTROLS");
  592. set.add("CONVERTING");
  593. set.add("COPY");
  594. set.add("CORR");
  595. set.add("CORRESPONDING");
  596. set.add("COUNT");
  597. set.add("CURRENCY");
  598. set.add("DATA");
  599. set.add("DATE");
  600. set.add("DATE-COMPILED");
  601. set.add("DATE-WRITTEN");
  602. set.add("DAY");
  603. set.add("DAY-OF-WEEK");
  604. set.add("DBCS");
  605. set.add("DE");
  606. set.add("DEBUG-CONTENTS");
  607. set.add("DEBUG-ITEM");
  608. set.add("DEBUG-LINE");
  609. set.add("DEBUG-NAME");
  610. set.add("DEBUG-SUB-1");
  611. set.add("DEBUG-SUB-2");
  612. set.add("DEBUG-SUB-3");
  613. set.add("DEBUGGING");
  614. set.add("DECIMAL-POINT");
  615. set.add("DECLARATIVES");
  616. set.add("DELETE");
  617. set.add("DELIMITED");
  618. set.add("DELIMITER");
  619. set.add("DEPENDING");
  620. set.add("DESCENDING");
  621. set.add("DESTINATION");
  622. set.add("DETAIL");
  623. set.add("DISPLAY");
  624. set.add("DISPLAY-1");
  625. set.add("DIVIDE");
  626. set.add("DIVISION");
  627. set.add("DOWN");
  628. set.add("DUPLICATES");
  629. set.add("DYNAMIC");
  630. set.add("EGCS");
  631. set.add("EGI");
  632. set.add("EJECT");
  633. set.add("ELSE");
  634. set.add("EMI");
  635. set.add("ENABLE");
  636. set.add("END");
  637. set.add("END-ADD");
  638. set.add("END-CALL");
  639. set.add("END-COMPUTE");
  640. set.add("END-DELETE");
  641. set.add("END-DIVIDE");
  642. set.add("END-EVALUATE");
  643. set.add("END-IF");
  644. set.add("END-INVOKE");
  645. set.add("END-MULTIPLY");
  646. set.add("END-OF-PAGE");
  647. set.add("END-PERFORM");
  648. set.add("END-READ");
  649. set.add("END-RECEIVE");
  650. set.add("END-RETURN");
  651. set.add("END-REWRITE");
  652. set.add("END-SEARCH");
  653. set.add("END-START");
  654. set.add("END-STRING");
  655. set.add("END-SUBTRACT");
  656. set.add("END-UNSTRING");
  657. set.add("END-WRITE");
  658. set.add("ENDING");
  659. set.add("ENTER");
  660. set.add("ENTRY");
  661. set.add("ENVIRONMENT");
  662. set.add("EOP");
  663. set.add("EQUAL");
  664. set.add("ERROR");
  665. set.add("ESI");
  666. set.add("EVALUATE");
  667. set.add("EVERY");
  668. set.add("EXCEPTION");
  669. set.add("EXIT");
  670. set.add("EXTEND");
  671. set.add("EXTERNAL");
  672. set.add("FALSE");
  673. set.add("FD");
  674. set.add("FILE");
  675. set.add("FILE-CONTROL");
  676. //set.add("FILLER");
  677. set.add("FINAL");
  678. set.add("FIRST");
  679. set.add("FOOTING");
  680. set.add("FOR");
  681. set.add("FORMAT");
  682. set.add("FROM");
  683. set.add("FUNCTION");
  684. set.add("GENERATE");
  685. set.add("GIVING");
  686. set.add("GLOBAL");
  687. set.add("GO");
  688. set.add("GOBACK");
  689. set.add("GREATER");
  690. set.add("GROUP");
  691. set.add("HEADING");
  692. set.add("HIGH-VALUE");
  693. set.add("HIGH-VALUES");
  694. set.add("I-O");
  695. set.add("I-O-CONTROL");
  696. set.add("ID");
  697. set.add("IDENTIFICATION");
  698. set.add("IF");
  699. set.add("IN");
  700. set.add("INDEX");
  701. set.add("INDEXED");
  702. set.add("INDICATE");
  703. set.add("INHERITS");
  704. set.add("INITIAL");
  705. set.add("INITIALIZE");
  706. set.add("INITIATE");
  707. set.add("INPUT");
  708. set.add("INPUT-OUTPUT");
  709. set.add("INSERT");
  710. set.add("INSPECT");
  711. set.add("INSTALLATION");
  712. set.add("INTO");
  713. set.add("INVALID");
  714. set.add("INVOKE");
  715. set.add("IS");
  716. set.add("JUST");
  717. set.add("JUSTIFIED");
  718. set.add("KANJI");
  719. set.add("KEY");
  720. set.add("LABEL");
  721. set.add("LAST");
  722. set.add("LEADING");
  723. set.add("LEFT");
  724. set.add("LENGTH");
  725. set.add("LESS");
  726. set.add("LIMIT");
  727. set.add("LIMITS");
  728. set.add("LINAGE");
  729. set.add("LINAGE-COUNTER");
  730. set.add("LINE");
  731. set.add("LINE-COUNTER");
  732. set.add("LINES");
  733. set.add("LINKAGE");
  734. set.add("LOCAL-STORAGE");
  735. set.add("LOCK");
  736. set.add("LOW-VALUE");
  737. set.add("LOW-VALUES");
  738. set.add("MEMORY");
  739. set.add("MERGE");
  740. set.add("MESSAGE");
  741. set.add("METACLASS");
  742. set.add("METHOD");
  743. set.add("METHOD-ID");
  744. set.add("MODE");
  745. set.add("MODULES");
  746. set.add("MORE-LABELS");
  747. set.add("MOVE");
  748. set.add("MULTIPLE");
  749. set.add("NATIVE");
  750. set.add("NEGATIVE");
  751. set.add("NEXT");
  752. set.add("NO");
  753. set.add("NOT");
  754. set.add("NULL");
  755. set.add("NULLS");
  756. set.add("NUMBER");
  757. set.add("NUMERIC");
  758. set.add("NUMERIC-EDITED");
  759. set.add("OBJECT");
  760. set.add("OBJECT-COMPUTER");
  761. set.add("OCCURS");
  762. set.add("OF");
  763. set.add("OFF");
  764. set.add("OMITTED");
  765. set.add("ON");
  766. set.add("OPEN");
  767. set.add("OPTIONAL");
  768. set.add("OR");
  769. set.add("ORDER");
  770. set.add("ORGANIZATION");
  771. set.add("OTHER");
  772. set.add("OUTPUT");
  773. set.add("OVERFLOW");
  774. set.add("OVERRIDE");
  775. set.add("PACKED-DECIMAL");
  776. set.add("PADDING");
  777. set.add("PAGE");
  778. set.add("PAGE-COUNTER");
  779. set.add("PASSWORD");
  780. set.add("PERFORM");
  781. set.add("PF");
  782. set.add("PH");
  783. set.add("PIC");
  784. set.add("PICTURE");
  785. set.add("PLUS");
  786. set.add("POINTER");
  787. set.add("POSITION");
  788. set.add("POSITIVE");
  789. set.add("PREVIOUS");
  790. set.add("PRINTING");
  791. set.add("PROCEDURE");
  792. set.add("PROCEDURE-POINTER");
  793. set.add("PROCEDURES");
  794. set.add("PROCEED");
  795. set.add("PROCESSING");
  796. set.add("PROGRAM");
  797. set.add("PROGRAM-ID");
  798. set.add("PURGE");
  799. set.add("QUEUE");
  800. set.add("QUOTE");
  801. set.add("QUOTES");
  802. set.add("RANDOM");
  803. set.add("RD");
  804. set.add("READ");
  805. set.add("READY");
  806. set.add("RECEIVE");
  807. set.add("RECORD");
  808. set.add("RECORDING");
  809. set.add("RECORDS");
  810. set.add("RECURSIVE");
  811. set.add("REDEFINES");
  812. set.add("REEL");
  813. set.add("REFERENCE");
  814. set.add("REFERENCES");
  815. set.add("RELATIVE");
  816. set.add("RELEASE");
  817. set.add("RELOAD");
  818. set.add("REMAINDER");
  819. set.add("REMOVAL");
  820. set.add("RENAMES");
  821. set.add("REPLACE");
  822. set.add("REPLACING");
  823. set.add("REPORT");
  824. set.add("REPORTING");
  825. set.add("REPORTS");
  826. set.add("REPOSITORY");
  827. set.add("RERUN");
  828. set.add("RESERVE");
  829. set.add("RESET");
  830. set.add("RETURN");
  831. set.add("RETURN-CODE");
  832. set.add("RETURNING");
  833. set.add("REVERSED");
  834. set.add("REWIND");
  835. set.add("REWRITE");
  836. set.add("RF");
  837. set.add("RH");
  838. set.add("RIGHT");
  839. set.add("ROUNDED");
  840. set.add("RUN");
  841. set.add("SAME");
  842. set.add("SD");
  843. set.add("SEARCH");
  844. set.add("SECTION");
  845. set.add("SECURITY");
  846. set.add("SEGMENT");
  847. set.add("SEGMENT-LIMIT");
  848. set.add("SELECT");
  849. set.add("SELF");
  850. set.add("SEND");
  851. set.add("SENTENCE");
  852. set.add("SEPARATE");
  853. set.add("SEQUENCE");
  854. set.add("SEQUENTIAL");
  855. set.add("SERVICE");
  856. set.add("SET");
  857. set.add("SHIFT-IN");
  858. set.add("SHIFT-OUT");
  859. set.add("SIGN");
  860. set.add("SIZE");
  861. set.add("SKIP1");
  862. set.add("SKIP2");
  863. set.add("SKIP3");
  864. set.add("SORT");
  865. set.add("SORT-CONTROL");
  866. set.add("SORT-CORE-SIZE");
  867. set.add("SORT-FILE-SIZE");
  868. set.add("SORT-MERGE");
  869. set.add("SORT-MESSAGE");
  870. set.add("SORT-MODE-SIZE");
  871. set.add("SORT-RETURN");
  872. set.add("SOURCE");
  873. set.add("SOURCE-COMPUTER");
  874. set.add("SPACE");
  875. set.add("SPACES");
  876. set.add("SPECIAL-NAMES");
  877. set.add("STANDARD");
  878. set.add("STANDARD-1");
  879. set.add("STANDARD-2");
  880. set.add("START");
  881. set.add("STATUS");
  882. set.add("STOP");
  883. set.add("STRING");
  884. set.add("SUB-QUEUE-1");
  885. set.add("SUB-QUEUE-2");
  886. set.add("SUB-QUEUE-3");
  887. set.add("SUBTRACT");
  888. set.add("SUM");
  889. set.add("SUPER");
  890. set.add("SUPPRESS");
  891. set.add("SYMBOLIC");
  892. set.add("SYNC");
  893. set.add("SYNCHRONIZED");
  894. set.add("TABLE");
  895. set.add("TALLY");
  896. set.add("TALLYING");
  897. set.add("TAPE");
  898. set.add("TERMINAL");
  899. set.add("TERMINATE");
  900. set.add("TEST");
  901. set.add("TEXT");
  902. set.add("THAN");
  903. set.add("THEN");
  904. set.add("THROUGH");
  905. set.add("THRU");
  906. set.add("TIME");
  907. set.add("TIMES");
  908. set.add("TITLE");
  909. set.add("TO");
  910. set.add("TOP");
  911. set.add("TRACE");
  912. set.add("TRAILING");
  913. set.add("TRUE");
  914. set.add("TYPE");
  915. set.add("UNIT");
  916. set.add("UNSTRING");
  917. set.add("UNTIL");
  918. set.add("UP");
  919. set.add("UPON");
  920. set.add("USAGE");
  921. set.add("USE");
  922. set.add("USING");
  923. set.add("VALUE");
  924. set.add("VALUES");
  925. set.add("VARYING");
  926. set.add("WHEN");
  927. set.add("WHEN-COMPILED");
  928. set.add("WITH");
  929. set.add("WORDS");
  930. set.add("WORKING-STORAGE");
  931. set.add("WRITE");
  932. set.add("WRITE-ONLY");
  933. set.add("ZERO");
  934. set.add("ZEROES");
  935. set.add("ZEROS");
  936. return Collections.unmodifiableSet(set);
  937. }
  938. /**
  939. * Creates a set consisting of Cobol clause starting words.
  940. * The set created is unmodifiable.
  941. *
  942. * @return the set of recognized Cobol clause words
  943. */
  944. protected static Set buildClauseWordSet() {
  945. Set set = new HashSet();
  946. set.add("BLANK");
  947. set.add("DATE");
  948. set.add("EXTERNAL");
  949. set.add("GLOBAL");
  950. set.add("JUSTIFIED");
  951. set.add("JUST");
  952. set.add("OCCURS");
  953. set.add("PIC");
  954. set.add("PICTURE");
  955. set.add("REDEFINES");
  956. set.add("RENAMES");
  957. set.add("SIGN");
  958. set.add("LEADING");
  959. set.add("TRAILING");
  960. set.add("SYNC");
  961. set.add("SYNCHRONIZED");
  962. set.add("USAGE");
  963. set.add("BINARY");
  964. set.add("COMP");
  965. set.add("COMP-1");
  966. set.add("COMP-2");
  967. set.add("COMP-3");
  968. set.add("COMP-4");
  969. set.add("COMP-5");
  970. set.add("COMPUTATIONAL");
  971. set.add("COMPUTATIONAL-1");
  972. set.add("COMPUTATIONAL-2");
  973. set.add("COMPUTATIONAL-3");
  974. set.add("COMPUTATIONAL-4");
  975. set.add("COMPUTATIONAL-5");
  976. set.add("DISPLAY");
  977. set.add("DISPLAY-1");
  978. set.add("INDEX");
  979. set.add("PACKED-DECIMAL");
  980. set.add("POINTER");
  981. set.add("PROCEDURE-POINTER");
  982. set.add("OBJECT");
  983. set.add("NATIVE");
  984. set.add("VALUE");
  985. return set;
  986. }
  987. /**
  988. * Indicate whether all alphabets in a string are in their upper case.
  989. * A string without any alphabets will evaluate to true
  990. *
  991. * @param str the string in consideration
  992. *
  993. * @return true if all alphabets in str are in their upper case, or if there
  994. * are no alphabets in str, or str is null; otherwise returns false
  995. */
  996. private static boolean isAllCaps(String str) {
  997. boolean isCaps = true;
  998. if (str != null) {
  999. for (int i = 0; isCaps && (i < str.length()); i++) {
  1000. char ch = str.charAt(i);
  1001. if (Character.isLetterOrDigit(ch)) {
  1002. isCaps &= Character.isUpperCase(ch);
  1003. }
  1004. }
  1005. }
  1006. return isCaps;
  1007. }
  1008. }
  1009. /* EOF $RCSfile: CocoLanguage.java,v $ */