All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javacc-7.0.4.grammars.Cobol.jj Maven / Gradle / Ivy

The newest version!
/**
 * This is an experimental COBOL-85 grammar for JavaCC.
 * 

References used for this grammar :

    *
  1. Ralf Lämmel & Chris Verhoef : VS COBOL II grammar Version 1.0.3 *
  2. Fujitsu Cobol compiler reference *
  3. Compaq-HP Non-stop Cobol reference * *

    This grammar is released under the GNU Library Public License (LGPL). *

    Bernard Pinon, august 2002
    *

    Thierry Blind, september 2009
    * @see http://www.gnu.org/licenses/lgpl.html * @see http://www.cwi.nl/ * @see http://www.wins.uva.nl/ * @author Thierry Blind (initial work from Bernard Pinon) * *

    History:

      *
    • 9-aug-2002 [BP] make changes to comply with JTB :
        *
      1. Changed Integer() to IntegerConstant() to avoid conflicts with java.lang.Integer *
      2. Removed Java code to make the grammar bare bone *
      3. Fixed Identification Division entries *
      *
    • 8-aug-2002 [BP] fixed several bugs :
        *
      1. INSTALLATION section *
      2. wrong spelling in keywords *
      3. DOT missing in FD/SD entries *
      4. wrong regular expressions for levels *
      5. possibility to have repeated string literals, e.g. "AA" "BB" -> "AABB" *
      6. optimized data division by placing the most common clauses first *
      7. DOT missing in exit statement *
      8. confusion between Identifier and QualifiedDataName (to be checked) *
      9. fixed NumericConstant to use Integer instead of INTEGER *
      10. Correcting AdvancingPhrase so LINE is optional *
      11. Fixed problems with abbreviated conditions *
      12. Fixed Add statement *
      *
    • 01-sept-2009 :
        *
      1. corrected picture values and enhanced linkage section *
      2. corrected relational operators, arithmetic expressions and conditions *
      3. corrected perform, evaluate and call clauses *
      4. corrected cobol word, litteral, identifier, comment declarations *
      5. created Iterables*() variants for some clauses *
      6. added function support from cobol 2000 *
      7. added LOOKAHEAD() instructions, with reorderings, to remove parser ambiguities *
      8. ... and many many corrections, new clauses and new tokens relative to cobol 85 and (some from) cobol 2000 *
      *
    */ /** * Cobol is not case sensitive. It is not LL(1) neither... */ options { IGNORE_CASE = true; //FORCE_LA_CHECK = true; LOOKAHEAD = 3; //DEBUG_PARSER = true; //DEBUG_LOOKAHEAD = true; STATIC = false; } /** * The parser class. */ PARSER_BEGIN(CobolParser) package convex.step2.parser; public class CobolParser { } PARSER_END(CobolParser) //////////////////////////////////////////////////////////////////////////////// // Lexical structure //////////////////////////////////////////////////////////////////////////////// SPECIAL_TOKEN : { < EOL: "\n" > | < SPACECHAR: ( " " | "\t" | "\f" | ";" | "\r" )+ > } SPECIAL_TOKEN : { < COMMENT: ( "*>" | "|" ) (~["\n","\r"])* > | < PREPROC_COMMENT: "*|" (~["\n","\r"])* > | < SPACE_SEPARATOR : ( | )+ > | < COMMA_SEPARATOR : "," > } TOKEN : { // TODO : Could be simplified by ? < DOT : > } //////////////////////////////////////////////////////////////////////////////// // RESERVED WORDS. Looks like an excerpt of the dictionary of data processing. // It is very hard to find significative identifiers in COBOL that are not // reserved... //////////////////////////////////////////////////////////////////////////////// TOKEN : { /* A */ < ACCEPT: "accept" > | < ACCESS: "access" > | < ADD: "add" > | < ADDRESS: "address" > // extension to support pointers | < ADVANCING: "advancing" > | < AFTER: "after" > | < ALL: "all" > | < ALPHABET: "alphabet" > | < ALPHABETIC: "alphabetic" > | < ALPHABETIC_LOWER: "alphabetic-lower" > | < ALPHABETIC_UPPER: "alphabetic-upper" > | < ALPHANUMERIC: "alphanumeric" > | < ALPHANUMERIC_EDITED: "alphanumeric-edited" > | < ALSO: "also" > | < ALTER: "alter" > | < ALTERNATE: "alternate" > | < AND: "and" > | < ANY: "any" > | < APPROXIMATE: "approximate" > // tandem extension | < ARE: "are" > | < AREA: "area" > | < AREAS: "areas" > | < ASCENDING: "ascending" > | < ASSIGN: "assign" > | < AT: "at" > | < AUTHOR: "author" > /* B */ | < BEFORE: "before" > | < BEGINNING: "beginning" > // extension | < BINARY: "binary" > | < BLANK: "blank" > | < BLOCK: "block" > | < BOTTOM: "bottom" > | < BY: "by" > /* C */ | < CALL: "call" > | < CALL_CONVENTION: "call-convention" > | < CANCEL: "cancel" > | < CD: "cd" > | < CF: "cf" > | < CH: "ch" > | < CHARACTER: "character" > | < CHARACTERS: "characters" > | < CLASS: "class" > | < CLOCK_UNITS: "clock-units" > | < CLOSE: "close" > //| < COBOL: "cobol" > | < CODE: "code" > | < CODE_SET: "code-set" > | < COLLATING: "collating" > | < COLUMN: "column" > | < COMMA: "comma" > | < COMMON: "common" > | < COMMUNICATION: "communication" > | < COMP: "comp" > | < COMP_1: "comp-1" > // extension in many dialects | < COMP_2: "comp-2" > // extension in many dialects | < COMP_3: "comp-3" > // extension in many dialects | < COMP_4: "comp-4" > // extension in many dialects | < COMPUTATIONAL: "computational" > | < COMPUTATIONAL_1: "computational-1" > // extension | < COMPUTATIONAL_2: "computational-2" > // extension | < COMPUTATIONAL_3: "computational-3" > // extension | < COMPUTATIONAL_4: "computational-4" > // extension | < COMPUTE: "compute" > | < CONFIGURATION: "configuration" > | < CONTAINS: "contains" > | < CONTENT: "content" > | < CONTINUE: "continue" > | < CONTROL: "control" > | < CONTROLS: "controls" > | < CONVERTING: "converting" > | < COPY: "copy" > | < CORR: "corr" > | < CORRESPONDING: "corresponding" > | < COUNT: "count" > | < CURRENCY: "currency" > /* D */ | < DATA: "data" > | < DATE: "date" > | < DATE_COMPILED: "date-compiled" > | < DATE_WRITTEN: "date-written" > | < DAY: "day" > | < DAY_OF_WEEK: "day-of-week" > | < DBCS: "dbcs" > // extension to support double bytes characters | < DE: "de" > | < DEBUG_CONTENTS: "debug-contents" > | < DEBUG_ITEM: "debug-item" > | < DEBUG_LINE: "debug-line" > | < DEBUG_NAME: "debug-name" > | < DEBUG_SUB_1: "debug-sub-1" > | < DEBUG_SUB_2: "debug-sub-2" > | < DEBUG_SUB_3: "debug-sub-3" > | < DEBUGGING: "debugging" > | < DECIMAL_POINT: "decimal-point" > | < DECLARATIVES: "declaratives" > | < DELETE: "delete" > | < DELIMITED: "delimited" > | < DELIMITER: "delimiter" > | < DEPENDING: "depending" > | < DESCENDING: "descending" > | < DESCRIPTOR: "descriptor" > | < DESTINATION: "destination" > | < DETAIL: "detail" > | < DISABLE: "disable" > | < DISPLAY: "display" > | < DISPLAY_1: "display-1" > // extension | < DIVIDE: "divide" > | < DIVISION: "division" > | < DOWN: "down" > | < DUPLICATES: "duplicates" > | < DYNAMIC: "dynamic" > /* E */ | < EGCS: "egcs" > // extension | < EGI: "egi" > | < ELSE: "else" > | < EMI: "emi" > | < ENABLE: "enable" > | < END: "end" > | < END_ADD: "end-add" > | < END_CALL: "end-call" > | < END_COMPUTE: "end-compute" > | < END_DELETE: "end-delete" > | < END_DIVIDE: "end-divide" > | < END_EVALUATE: "end-evaluate" > | < END_IF: "end-if" > | < END_MULTIPLY: "end-multiply" > | < END_OF_PAGE: "end-of-page" > | < END_PERFORM: "end-perform" > | < END_READ: "end-read" > | < END_RECEIVE: "end-receive" > | < END_RETURN: "end-return" > | < END_REWRITE: "end-rewrite" > | < END_SEARCH: "end-search" > | < END_START: "end-start" > | < END_STRING: "end-string" > | < END_SUBTRACT: "end-subtract" > | < END_UNSTRING: "end-unstring" > | < END_WRITE: "end-write" > | < ENDING: "endinf" > | < ENTER: "enter" > // not present in all COBOLs, use CALL instead | < ENTRY: "entry" > | < ENVIRONMENT: "environment" > | < EOP: "eop" > | < EQUAL: "equal" > | < ERROR: "error" > | < ESI: "esi" > | < EVALUATE: "evaluate" > | < EVERY: "every" > | < EXCEPTION: "exception" > /* | < EXCLUSIVE: "exclusive" > tandem extension */ | < EXIT: "exit" > | < EXTEND: "extend" > | < EXTERNAL: "external" > /* F */ | < FALSE: "false" > | < FD: "fd" > | < FILE: "file" > | < FILE_CONTROL: "file-control" > | < FILLER: "filler" > | < FINAL: "final" > | < FIRST: "first" > | < FOOTING: "footing" > | < FOR: "for" > | < FROM: "from" > | < FUNCTION: "function" > /* G */ | < GENERATE: "generate" > | < GOBACK: "goback" > // extension | < GENERIC: "generic" > // tandem extension | < GIVING: "giving" > | < GLOBAL: "global" > | < GO: "go" > | < GREATER: "greater" > | < GROUP: "group" > /* H */ | < HEADING: "heading" > | < HIGH_VALUE: "high-value" > | < HIGH_VALUES: "high-values" > /* I */ | < I_O: "i-o" > | < I_O_CONTROL: "i-o-control" > | < ID: "id" > // extension, synonym for IDENTIFICATION | < IDENTIFICATION: "identification" > | < IDENTIFIED: "identified" > | < IF: "if" > | < IMPLICIT: "implicit" > | < IN: "in" > | < INDEX: "index" > | < INDEXED: "indexed" > | < INDICATE: "indicate" > | < INITIAL: "initial" > | < INITIALIZE: "initialize" > | < INITIATE: "initiate" > | < INPUT: "input" > | < INPUT_OUTPUT: "input-output" > | < INSPECT: "inspect" > | < INSTALLATION: "installation" > | < INTO: "into" > | < INVALID: "invalid" > | < IS: "is" > /* J */ | < JUST: "just" > | < JUSTIFIED: "justified" > | < JUSTIFY: "justify" > /* K */ | < KANJI: "kanji" > // extension to support Kanji characters (japanese) | < KEY: "key" > /* L */ | < LABEL: "label" > | < LAST: "last" > | < LEADING: "leading" > | < LEFT: "left" > | < LENGTH: "length" > | < LESS: "less" > | < LIMIT: "limit" > | < LIMITS: "limits" > | < LINAGE: "linage" > | < LINAGE_COUNTER: "linage_counter" > | < LINE: "line" > | < LINES: "lines" > | < LINE_COUNTER: "line-counter" > | < LINKAGE: "linkage" > | < LOCK: "lock" > | < LOCKFILE: "lockfile" > // tandem extension | < LOW_VALUE: "low-value" > | < LOW_VALUES: "low-values" > /* M */ | < MEMORY: "memory" > | < MERGE: "merge" > | < MESSAGE: "message" > | < MODE: "mode" > | < MODULES: "modules" > | < MORE_LABELS: "more-labels" > // IBM extension | < MOVE: "move" > | < MULTIPLE: "multiple" > | < MULTIPLY: "multiply" > /* N */ | < NATIVE: "native" > | < NEGATIVE: "negative" > | < NEXT: "next" > | < NO: "no" > | < NOT: "not" > | < NULL: "null" > // tandem & IBM extension | < NULLS: "nulls" > // tandem & IBM extension | < NUMBER: "number" > | < NUMERIC: "numeric" > | < NUMERIC_EDITED: "numeric-edited" > /* O */ | < OBJECT_COMPUTER: "object-computer" > | < OCCURS: "occurs" > | < OF: "of" > | < OFF: "off" > | < OMITTED: "omitted" > | < ON: "on" > | < OPEN: "open" > | < OPTIONAL: "optional" > | < OR: "or" > | < ORDER: "order" > | < ORGANIZATION: "organization" > | < OTHER: "other" > | < OUTPUT: "output" > | < OVERFLOW: "overflow" > /* P */ | < PACKED_DECIMAL: "packed-decimal" > | < PADDING: "padding" > | < PAGE: "page" > | < PAGE_COUNTER: "page-counter" > | < PASSWORD: "password" > | < PERFORM: "perform" > | < PF: "pf" > | < PH: "ph" > | < PIC: "pic" > | < PICTURE: "picture" > | < PLUS: "plus" > | < POINTER: "pointer" > | < POSITION: "position" > | < POSITIVE: "positive" > | < PRINTING: "printing" > | < PROCEDURE: "procedure" > | < PROCEDURES: "procedures" > | < PROCEDURE_POINTER: "procedure-pointer" > | < PROCEED: "proceed" > | < PROGRAM: "program" > | < PROGRAM_ID: "program-id" > | < PROGRAM_STATUS: "program-status" > // tandem extension | < PROMPT: "prompt" > // tandem extension | < PROTECTED: "protected" > // tandem extension | < PURGE: "purge" > /* Q */ | < QUEUE: "queue" > | < QUOTE: "quote" > | < QUOTES: "quotes" > /* R */ | < RANDOM: "random" > | < RD: "rd" > | < READ: "read" > | < RECEIVE: "receive" > | < RECEIVE_CONTROL: "receive-control" > // tandem extension | < RECORD: "record" > | < RECORDING: "recording" > // probably IBM extension | < RECORDS: "records" > | < REDEFINES: "redefines" > | < REEL: "reel" > | < REFERENCE: "reference" > | < REFERENCES: "references" > | < RELATIVE: "relative" > | < RELEASE: "release" > | < REMAINDER: "remainder" > | < REMOVAL: "removal" > | < RENAMES: "renames" > | < REPLACE: "replace" > | < REPLACING: "replacing" > | < REPLY: "reply" > // tandem extension | < REPORT: "report" > | < REPORTING: "reporting" > | < REPORTS: "reports" > | < RERUN: "rerun" > | < RESERVE: "reserve" > | < RESET: "reset" > | < RETURN: "return" > // IBM extension - does not do what expected ;-) | < RETURN_CODE: "return-code" > // special register IBM | < RETURNED: "returned" > | < RETURNING: "returning" > | < REVERSED: "reversed" > | < REWIND: "rewind" > | < REWRITE: "rewrite" > | < RF: "rf" > | < RH: "rh" > | < RIGHT: "right" > | < ROUNDED: "rounded" > | < RUN: "run" > /* S */ | < SAME: "same" > | < SD: "sd" > | < SEARCH: "search" > | < SECTION: "section" > | < SECURITY: "security" > | < SEGMENT: "segment" > | < SEGMENT_LIMIT: "segment-limit" > | < SELECT: "select" > | < SEND: "send" > | < SENTENCE: "sentence" > | < SEPARATE: "separate" > | < SEQUENCE: "sequence" > | < SEQUENTIAL: "sequential" > | < SET: "set" > | < SHARED: "shared" > // tandem extension, should be in C2000 | < SHIFT_IN: "shift-in" > // IBM special register | < SHIFT_OUT: "shift-out" > // IBM special register | < SIGN: "sign" > | < SIZE: "size" > | < SORT: "sort" > | < SORT_CONTROL: "sort-control" > // IBM special register | < SORT_CORE_SIZE: "sort-core-size" > // IBM special register | < SORT_FILE_SIZE: "sort-file-size" > // IBM special register | < SORT_MERGE: "sort-merge" > | < SORT_MESSAGE: "sort-message" > // IBM special register | < SORT_MODE_SIZE: "sort-mode-size" > // IBM special register | < SORT_RETURN: "sort-return" > // IBM special register | < SOURCE: "source" > | < SOURCE_COMPUTER: "source-computer" > | < SPACE: "space" > | < SPACES: "spaces" > | < SPECIAL_NAMES: "special-names" > | < STANDARD: "standard" > | < STANDARD_1: "standard-1" > | < STANDARD_2: "standard-2" > | < START: "start" > | < STATUS: "status" > | < STDCALL: "stdcall" > | < STOP: "stop" > | < STRING: "string" > | < SUB_QUEUE_1: "sub-queue-1" > | < SUB_QUEUE_2: "sub-queue-2" > | < SUB_QUEUE_3: "sub-queue-3" > | < SUBTRACT: "subtract" > | < SUM: "sum" > | < SUPPRESS: "suppress" > | < SYMBOLIC: "symbolic" > | < SYNC: "sync" > | < SYNCHRONIZED: "synchronized" > /* T */ | < TABLE: "table" > | < TALLY: "tally" > // IBM special register | < TALLYING: "tallying" > | < TAPE: "tape" > | < TERMINAL: "terminal" > | < TERMINATE: "terminate" > | < TEST: "test" > | < TEXT: "text" > | < THAN: "than" > | < THEN: "then" > | < THROUGH: "through" > | < THRU: "thru" > | < TIME: "time" > | < TIMES: "times" > | < TO: "to" > | < TOP: "top" > | < TRAILING: "trailing" > | < TRUE: "true" > | < TYPE: "type" > /* U */ | < UNIT: "unit" > | < UNLOCK: "unlock" > // tandem extension | < UNLOCKFILE: "unlockfile" > // tandem again | < UNLOCKRECORD: "unlockrecord" > // guess what | < UNSTRING: "unstring" > | < UNTIL: "until" > | < UP: "up" > | < UPON: "upon" > | < USAGE: "usage" > | < USE: "use" > | < USING: "using" > /* V */ | < VALUE: "value" > | < VALUES: "values" > | < VARYING: "varying" > /* W */ | < WHEN: "when" > | < WHEN_COMPILED: "when-compiled" > // IBM special register | < WITH: "with" > | < WORDS: "words" > | < WORKING_STORAGE: "working-storage" > | < WRITE: "write" > /* Z */ | < ZERO: "zero" > | < ZEROS: "zeros" > | < ZEROES: "zeroes" > /* Newly added */ | < ALPHANUMERIC_HASHTABLE: "alphanumeric-hashtable" > | < BINARY_BYTE: "binary-byte" > | < BINARY_DOUBLE: "binary-double" > | < BINARY_LONG: "binary-long" > | < BINARY_M: "binary-m" > | < BINARY_REV: "binary-rev" > | < BINARY_SHORT: "binary-short" > | < BIT: "bit" > | < COMPONENT: "component" > | < COMPUTATIONAL_2_A: "computational-2-a" > | < COMPUTATIONAL_1_A: "computational-1-a" > | < COMPUTATIONAL_1_E: "computational-1-e" > | < COMPUTATIONAL_1_M: "computational-1-m" > | < COMPUTATIONAL_1_MVS: "computational-1-mvs" > | < COMPUTATIONAL_1_REV: "computational-1-rev" > | < COMPUTATIONAL_2_E: "computational-2-e" > | < COMPUTATIONAL_2_M: "computational-2-m" > | < COMPUTATIONAL_2_MVS: "computational-2-mvs" > | < COMPUTATIONAL_2_REV: "computational-2-rev" > | < COMPUTATIONAL_3_A: "computational-3-a" > | < COMPUTATIONAL_3_M: "computational-3-m" > | < COMPUTATIONAL_4_M: "computational-4-m" > | < COMPUTATIONAL_5: "computational-5" > | < COMPUTATIONAL_5_M: "computational-5-m" > | < COMPUTATIONAL_6: "computational-6" > | < COMPUTATIONAL_A: "computational-a" > | < COMPUTATIONAL_B: "computational-b" > | < COMPUTATIONAL_D: "computational-d" > | < COMPUTATIONAL_M: "computational-m" > | < COMPUTATIONAL_N: "computational-n" > | < COMPUTATIONAL_P: "computational-p" > | < COMPUTATIONAL_S: "computational-s" > | < COMPUTATIONAL_X: "computational-x" > | < COMPUTATIONAL_X_REV: "computational-x-rev" > | < COMP_1_A: "comp-1-a" > | < COMP_1_E: "comp-1-e" > | < COMP_1_M: "comp-1-m" > | < COMP_1_MVS: "comp-1-mvs" > | < COMP_1_REV: "comp-1-rev" > | < COMP_2_A: "comp-2-a" > | < COMP_2_E: "comp-2-e" > | < COMP_2_M: "comp-2-m" > | < COMP_2_MVS: "comp-2-mvs" > | < COMP_2_REV: "comp-2-rev" > | < COMP_3_A: "comp-3-a" > | < COMP_3_M: "comp-3-m" > | < COMP_4_M: "comp-4-m" > | < COMP_5: "comp-5" > | < COMP_5_M: "comp-5-m" > | < COMP_6: "comp-6" > | < COMP_A: "comp-a" > | < COMP_B: "comp-b" > | < COMP_D: "comp-d" > | < COMP_M: "comp-m" > | < COMP_N: "comp-n" > | < COMP_P: "comp-p" > | < COMP_S: "comp-s" > | < COMP_X: "comp-x" > | < COMP_X_REV: "comp-x-rev" > | < DEFAULT_FONT: "default-font" > | < DISPLAY_WS: "display-ws" > | < DOUBLE: "double" > | < EXTERNAL_FORM: "external-form" > | < FIXED_FONT: "fixed-font" > | < FLOAT: "float" > | < FLOAT_LONG: "float-long" > | < FLOAT_SHORT: "float-short" > | < FONT: "font" > | < HANDLE: "handle" > | < JBOOLEAN: "jboolean" > | < JBYTE: "jbyte" > | < JCHAR: "jchar" > | < JDOUBLE: "jdouble" > | < JFLOAT: "jfloat" > | < JINT: "jint" > | < JLONG: "jlong" > | < JPACKED_DECIMAL: "jpacked-decimal" > | < JSHORT: "jshort" > | < JSTRING: "jstring" > | < LARGE_FONT: "large-font" > | < MEDIUM_FONT: "medium-font" > | < NATIONAL: "national" > | < NUMERIC_HASHTABLE: "numeric-hashtable" > | < OBJECT: "object" > | < OBJECT_HASHTABLE: "object-hashtable" > | < PACKED_DECIMAL_A: "packed-decimal-a" > | < PACKED_DECIMAL_E: "packed-decimal-e" > | < PACKED_DECIMAL_H: "packed-decimal-h" > | < PACKED_DECIMAL_I: "packed-decimal-i" > | < PACKED_DECIMAL_M: "packed-decimal-m" > | < SIGNED_INT: "signed-int" > | < SIGNED_LONG: "signed-long" > | < SIGNED_SHORT: "signed-short" > | < SMALL_FONT: "small-font" > | < SQLIND: "sqlind" > | < THREAD: "thread" > | < TRADITIONAL_FONT: "traditional-font" > | < UNSIGNED_INT: "unsigned-int" > | < UNSIGNED_LONG: "unsigned-long" > | < UNSIGNED_SHORT: "unsigned-short" > | < WINDOW: "window" > } TOKEN : { < LEVEL_66: "66" > | < LEVEL_77: "77" > | < LEVEL_88: "88" > | < LEVEL_NUMBER: ( (("0")? ["1"-"9"]) | (["1"-"4"]["0"-"9"]) | "78" ) > | < INTEGER: (["0"-"9"])+ > | < MINUSCHAR: "-" > // a.k.a. dash | < LPARENCHAR: "(" > | < RPARENCHAR: ")" > | < COLONCHAR: ":" > | < DOTCHAR: "." > | < COMMACHAR: "," > | < DOUBLEDQUOTECHAR: "\"\"" > | < QUOTECHAR: "\"" > | < DOUBLEDAPOSTROPHE: "''" > | < APOSTROPHE: "'" > | < PLUSCHAR: "+" > | < ASTERISKCHAR: "*" > | < POWEROF: "**" > | < SLASHCHAR: "/" > | < DOLLARCHAR: "$" > | < LESSTHANOREQUAL: "<=" > | < LESSTHANCHAR: "<" > | < MORETHANOREQUAL: ">=" > | < MORETHANCHAR: ">" > | < EQUALCHAR: "=" > | < NOTEQUAL: "<>" > | < HEXNUMBER: ["h","x"] ( ( ( ["0"-"9","a"-"f"] )+ ) | ( ( ["0"-"9","a"-"f"] )+ ) ) > | < QUOTEDSTRING: ( (~["\""] | )* | (~["'"] | )* ) > // NB : COBOL_WORD can be defined as an INTEGER (or a LEVEL_66* or a LEVEL_NUMBER) too ! | < COBOL_WORD: (["a"-"z","0"-"9"])+ ( ( | "_" )+ (["a"-"z","0"-"9"])+ )* > | < OTHER_CHARS: ~[] > } // Contains at least one alphabetic, max. 30 char void CobolWord() : {} { } void QuotedText() : {} { ( IterableQuotedText() )+ } void IterableQuotedText() : {} { | | } void IntegerConstant() : {} { | | | | } void NumericConstant() : {} { [ | ] ( ( | ) IntegerConstant() | IntegerConstant() [ ( | ) IntegerConstant() ] ) } void LevelNumber() : {} { } void FigurativeConstant() : {} { | | | | | | | | | | | | } void NonNumericConstant() : {} { ( QuotedText() | ) } void IterableNonNumericConstant() : {} { ( IterableQuotedText() | ) } void Literal() : {} { [ ] ( NonNumericConstant() | NumericConstant() /* | */ | FigurativeConstant() ) } void IterableLiteral() : {} { [ ] ( IterableNonNumericConstant() | NumericConstant() /* | */ | FigurativeConstant() ) } //////////////////////////////////////////////////////////////////////////////// // LOGICAL EXPRESSIONS (e.g. in IF statements) // one of the nice feature of COBOL is to allow for abbeviated conditions // such as : if X less than 100 and more than 10 then ... //////////////////////////////////////////////////////////////////////////////// void IterableCondition() : {} { // TODO : This step was created because of the ambiguite of the rule ClassCondition() inside of RelationCondition() : // CobolWord() CobolWord() === ArithmeticExpression() ClassCondition() LOOKAHEAD(ArithmeticExpression()) ArithmeticExpression() | Condition() } void Condition() : {} { CombinableCondition() ( ( | ) ( LOOKAHEAD(CombinableCondition()) CombinableCondition() | AbbreviationRest() ) )* } void CombinableCondition() : {} { [ ] SimpleCondition() } void SimpleCondition() : {} { LOOKAHEAD(RelationCondition()) RelationCondition() | LOOKAHEAD(ArithmeticExpression()) ArithmeticExpression() | Condition() } void ClassCondition() : {} { [ ] [ ] ( | | | | ClassName() | | ) } void RelationCondition() : {} { ArithmeticExpression() ( LOOKAHEAD(AbbreviationRest()) AbbreviationRest() | LOOKAHEAD(SignCondition()) SignCondition() | ClassCondition() ) } void SignCondition() : {} { [ ] [ ] ( | | | | ) } void RelationalOperator() : {} { [ ] [ ] ( [ ] [ [ ] ] | | [ ] [ [ ] ] | | [ ] | | | | ) } void AbbreviationLeaf() : {} { LOOKAHEAD(ArithmeticExpression()) ArithmeticExpression() // TODO : Is there another abbreviation rule ? | AbbreviationLeaf() ( AbbreviationLeaf() )+ } void AbbreviationRest() : {} { RelationalOperator() AbbreviationLeaf() } //////////////////////////////////////////////////////////////////////////////// // VARIOUS TYPES OF IDENTIFIERS //////////////////////////////////////////////////////////////////////////////// void ProcedureName() : {} { ( ParagraphName() [ ( | ) SectionName() ] | SectionName() // Useless here ... ) } void Subscript() : {} { ( ArithmeticExpression() )+ } void FunctionClause() : {} { FunctionName() [ LOOKAHEAD(Subscript()) Subscript() ] [ LeftmostCharacterPosition() [ Length() ] ] } void Identifier() : {} { ( QualifiedDataName() ( LOOKAHEAD(Subscript()) Subscript() )* [ LeftmostCharacterPosition() [ Length() ] ] | [ ( | ) FileName() ] | ) } void QualifiedDataName() : {} { ( DataName() ( ( | ) DataName() )* [ ( | ) FileName() ] // Useless part here ... | SpecialRegister() // Useless here ... ) } void Length() : {} { ArithmeticExpression() } void LeftmostCharacterPosition() : {} { ArithmeticExpression() } void Mode() : {} { CobolWord() } void AlphabetName() : {} { CobolWord() } void ClassName() : {} { CobolWord() } void ConditionName() : {} { CobolWord() } void DataName() : {} { CobolWord() } void FileName() : {} { CobolWord() } void IndexName() : {} { CobolWord() } void MnemonicName() : {} { CobolWord() } void RecordName() : {} { Identifier() } void RoutineName() : {} { CobolWord() } void SymbolicCharacter() : {} { CobolWord() } void LibraryName() : {} { CobolWord() } void ProgramName() : {} { CobolWord() } void SectionName() : {} { // We force IntegerConstant() recognization here ... IntegerConstant() | CobolWord() } void ParagraphName() : {} { // We force IntegerConstant() recognization here ... IntegerConstant() | CobolWord() } void SystemName() : {} { CobolWord() } void ComputerName() : {} { SystemName() } void LanguageName() : {} { SystemName() } void EnvironmentName() : {} { SystemName() } void AssignmentName() : {} { SystemName() } void BasisName() : {} { ProgramName() } void FunctionName() : {} { ( CobolWord() | // To avoid conflicts with token having same name ... | | | ) } void SpecialRegister() : {} { (
    DataName() | | Identifier() | | | | | | | | | | | ) } void CdName() : {} { CobolWord() } void ConventionName() : {} { CobolWord() } void HandleComponent() : {} { CobolWord() } void ImplicitTitle() : {} { QuotedText() } void LevelName66() : {} { DataName() } void LevelName77() : {} { DataName() } void LevelName88() : {} { ConditionName() } void LevelName() : {} { [ DataName() | | | ] } //////////////////////////////////////////////////////////////////////////////// // ARITHMETIC //////////////////////////////////////////////////////////////////////////////// void ArithmeticExpression() : {} { TimesDiv() ( ( | ) TimesDiv() )* } void TimesDiv() : {} { Power() ( ( | ) Power() )* } void Power() : {} { [ ( | ) ] Basis() ( Basis() )* } void Basis() : {} { // IMPORTANT : From more complex to most specific : // TODO : Dirty hack : is a valid value ? ( FunctionClause() | Identifier() | Literal() | | ArithmeticExpression() ) } void CommentLine() : {} { ( ( NonDotChars() | Literal() )+ [ ] )+ } //////////////////////////////////////////////////////////////////////////////// // COMPILATION UNIT. //////////////////////////////////////////////////////////////////////////////// void CompilationUnit() : {} { ProgramUnit() ( NestedProgramUnit() EndProgramStatement() )* [ EndProgramStatement() ( CompilationUnit() )* ] } void ProgramUnit() : {} { IdentificationDivision() [ EnvironmentDivision() ] [ DataDivision() ] [ ProcedureDivision() ] } void NestedProgramUnit() : {} { NestedIdentificationDivision() [ EnvironmentDivision() ] [ DataDivision() ] [ ProcedureDivision() ] } void EndProgramStatement() : {} { ProgramName() } void CopyBookUnit() : {} { LinkageSectionEntry() } //////////////////////////////////////////////////////////////////////////////// // IDENTIFICATION DIVISION. //////////////////////////////////////////////////////////////////////////////// void IdentificationDivision() : {} { ( | ) ProgramIdParagraph() ( IdentificationDivisionParagraph() )* } void NestedIdentificationDivision() : {} { ( | ) NestedProgramIdParagraph() ( IdentificationDivisionParagraph() )* } void IdentificationDivisionParagraph() : {} { AuthorParagraph() | InstallationParagraph() | DateWrittenParagraph() | DateCompiledParagraph() | SecurityParagraph() } void ProgramIdParagraph() : {} { ProgramName() [ [ ] [ ] ] } void NestedProgramIdParagraph() : {} { ProgramName() [ [ ] InitialOrCommon() [ ] ] } void InitialOrCommon() : {} { ( [ ] | [ ] ) } void AuthorParagraph() : { /* System.out.println("Deprecated keyword : author - use a comment"); */ } { [ CommentLine() ] } void InstallationParagraph() : { /* System.out.println("Deprecated keyword : installation - use a comment"); */ } { [ CommentLine() ] } void DateWrittenParagraph() : { /* System.out.println("Deprecated keyword : date-written - use a comment"); */ } { [ CommentLine() ] } void DateCompiledParagraph() : { /* System.out.println("Deprecated keyword : date-compiled - use a comment"); */ } { [ CommentLine() ] } void SecurityParagraph() : { /* System.out.println("Deprecated keyword : security - use a comment"); */ } { [ CommentLine() ] } //////////////////////////////////////////////////////////////////////////////// // ENVIRONMENT DIVISION. //////////////////////////////////////////////////////////////////////////////// void EnvironmentDivision() : {} { ( EnvironmentSection() )* } void EnvironmentSection() : {} { ConfigurationSection() | InputOutputSection() } //------------------------------------------------------------------------------ // CONFIGURATION SECTION //------------------------------------------------------------------------------ void ConfigurationSection() : {} {
    ( ConfigurationSectionParagraph() )* } void ConfigurationSectionParagraph() : {} { SourceComputerParagraph() | ObjectComputerParagraph() | SpecialNamesParagraph() } void SourceComputerParagraph() : {} { ComputerName() [ [ ] ] } void ObjectComputerParagraph() : {} { ComputerName() ( ObjectComputerClause() )* } void ObjectComputerClause() : {} { MemorySizeClause() | CollatingSequenceClause() | SegmentLimitClause() | CharacterSetClause() } void MemorySizeClause() : { /* System.out.println("Deprecated keyword : memory - use a comment"); */ } { [ ] IntegerConstant() [ | | ] } void CollatingSequenceClause() : { /* System.out.println("Deprecated keyword : collating sequence - use a comment"); */ } { [ ] [ ] [ ] AlphabetName() } void SegmentLimitClause() : { /* System.out.println("Deprecated keyword : segment unit - use a comment"); */ } { ( | ) [ ] IntegerConstant() } // Tandem ??? void CharacterSetClause() : {} { [ CommentLine() ] } void SpecialNamesParagraph() : {} { [ ( SpecialNameClause() )+ ] } void SpecialNameClause() : {} { AlphabetClause() | ClassClause() | CurrencySignClause() | DecimalPointClause() | SymbolicCharactersClause() | CallConventionClause() | EnvironmentNameIsMnemonicNameClause() } void IterableAlphabetPhrase() : {} { ( | ) IterableLiteral() | ( IterableLiteral() )+ } void AlphabetClause() : {} { AlphabetName() [ ] ( | | | CobolWord() | ( IterableLiteral() [ IterableAlphabetPhrase() ] )+ ) } void ClassClause() : {} { // TODO (SUPPRESS) : Dirty hack : IterableLiteral() --> Identifier() | IterableLiteral() ClassName() [ ] ( ( Identifier() | IterableLiteral() ) [ ( | ) ( Identifier() | IterableLiteral() ) ] )+ } void CurrencySignClause() : {} { [ ] [ ] Literal() } void DecimalPointClause() : {} { [ ] } void SymbolicCharactersClause() : {} { [ ] ( ( SymbolicCharacter() )+ [ ( | ) ] ( NumericConstant() | )+ )+ [ AlphabetName() ] } void CallConventionClause() : {} { IntegerConstant() [ ] ConventionName() } void EnvironmentNameIsMnemonicNameClause() : {} { EnvironmentName() ( [ ] MnemonicName() [ SpecialNamesParagraphStatusPhrase() ] | SpecialNamesParagraphStatusPhrase() ) } void SpecialNamesParagraphStatusPhrase() : {} { ( [ ] [ ] IterableCondition() [ [ ] [ ] IterableCondition() ] | [ ] [ ] IterableCondition() [ [ ] [ ] IterableCondition() ] ) } //------------------------------------------------------------------------------ // INPUT-OUTPUT SECTION //------------------------------------------------------------------------------ void InputOutputSection() : {} {
    ( InputOutputSectionParagraph() )* } void InputOutputSectionParagraph() : {} { FileControlParagraph() | IOControlParagraph() } void FileControlParagraph() : {} { ( LOOKAHEAD([ ] FileControlEntry()) [ ] FileControlEntry() )* } void FileControlEntry() : {} { SelectClause() ( FileControlClause() )* } void FileControlClause() : {} { AssignClause() | ReserveClause() | OrganizationClause() | PaddingCharacterClause() | RecordDelimiterClause() | AccessModeClause() | RecordKeyClause() | AlternateRecordKeyClause() | FileStatusClause() | PasswordClause() } void SelectClause() : {} { ( CommunicationInputClause() )* ( DataName() )* } void CommunicationOutputEntry() : {} { CdName() [ ] ( CommunicationOutputClause() )* } void CommunicationIOEntry() : {} { CdName() [ ] [ ] ( CommunicationIOClause() )* ( DataName() )* } void CommunicationInputClause() : {} { ( |