package com.ibm.ai4code.parser.cobol;

import java.util.HashSet;

import com.ibm.ai4code.parser.commons.ReservedWordDeciderI;

public class CobolReservedWordDecider implements ReservedWordDeciderI{
	// grep ":" cobolkws_orig.txt | cut -d':' -f1 | awk '{ print "\""$0"\","}' | sed 's/ //g' | sed 's/_/-/g'
	// note we replace all _ with -, thanks to David!
	public static final String [] keywords = {
			"ABORT",
			"ACCEPT",
			"ACCESS",
			"ADD",
			"ADDRESS",
			"ADVANCING",
			"AFTER",
			"ALIGNED",
			"ALL",
			"ALPHABET",
			"ALPHABETIC",
			"ALPHABETIC-LOWER",
			"ALPHABETIC-UPPER",
			"ALPHANUMERIC",
			"ALPHANUMERIC-EDITED",
			"ALSO",
			"ALTER",
			"ALTERNATE",
			"AND",
			"ANY",
			"ARE",
			"AREA",
			"AREAS",
			"AS",
			"ASCENDING",
			"ASCII",
			"ASSIGN",
			"ASSOCIATED-DATA",
			"ASSOCIATED-DATA-LENGTH",
			"AT",
			"ATTRIBUTE",
			"AUTHOR",
			"AUTO",
			"AUTO-SKIP",
			"BACKGROUND-COLOR",
			"BACKGROUND-COLOUR",
			"BASIS",
			"BEEP",
			"BEFORE",
			"BEGINNING",
			"BELL",
			"BINARY",
			"BIT",
			"BLANK",
			"BLINK",
			"BLOCK",
			"BOUNDS",
			"BOTTOM",
			"BY",
			"BYFUNCTION",
			"BYTITLE",
			"CALL",
			"CANCEL",
			"CAPABLE",
			"CCSVERSION",
			"CD",
			"CF",
			"CH",
			"CHAINING",
			"CHANGED",
			"CHANNEL",
			"CHARACTER",
			"CHARACTERS",
			"CLASS",
			"CLASS-ID",
			"CLOCK-UNITS",
			"CLOSE",
			"CLOSE-DISPOSITION",
			"COBOL",
			"CODE",
			"CODE-SET",
			"COLLATING",
			"COL",
			"COLUMN",
			"COM-REG",
			"COMMA",
			"COMMITMENT",
			"COMMON",
			"COMMUNICATION",
			"COMP",
			"COMP-1",
			"COMP-2",
			"COMP-3",
			"COMP-4",
			"COMP-5",
			"COMPUTATIONAL",
			"COMPUTATIONAL-1",
			"COMPUTATIONAL-2",
			"COMPUTATIONAL-3",
			"COMPUTATIONAL-4",
			"COMPUTATIONAL-5",
			"COMPUTE",
			"CONFIGURATION",
			"CONTAINS",
			"CONTENT",
			"CONTINUE",
			"CONTROL",
			"CONTROL-POINT",
			"CONTROLS",
			"CONVENTION",
			"CONVERTING",
			"COPY",
			"CORR",
			"CORRESPONDING",
			"COUNT",
			"CRUNCH",
			"CURRENCY",
			"CURSOR",
			"DATA",
			"DATA-BASE",
			"DATE",
			"DATE-COMPILED",
			"DATE-WRITTEN",
			"DAY",
			"DAY-OF-WEEK",
			"DBCS",
			"DE",
			"DEBUG-CONTENTS",
			"DEBUG-ITEM",
			"DEBUG-LINE",
			"DEBUG-NAME",
			"DEBUG-SUB-1",
			"DEBUG-SUB-2",
			"DEBUG-SUB-3",
			"DEBUGGING",
			"DECIMAL-POINT",
			"DECLARATIVES",
			"DEFAULT",
			"DEFAULT-DISPLAY",
			"DEFINITION",
			"DELETE",
			"DELIMITED",
			"DELIMITER",
			"DEPENDING",
			"DESCENDING",
			"DESTINATION",
			"DETAIL",
			"DFHRESP",
			"DFHVALUE",
			"DISABLE",
			"DISK",
			"DISPLAY",
			"DISPLAY-1",
			"DIVIDE",
			"DIVISION",
			"DONTCARE",
			"DOUBLE",
			"DOWN",
			"DUPLICATES",
			"DYNAMIC",
			"EBCDIC",
			"EGCS",
			"EGI",
			"ELSE",
			"EMI",
			"EMPTY-CHECK",
			"ENABLE",
			"END",
			"END-ACCEPT",
			"END-ADD",
			"END-CALL",
			"END-COMPUTE",
			"END-DELETE",
			"END-DIVIDE",
			"END-EVALUATE",
			"END-IF",
			"END-MULTIPLY",
			"END-OF-PAGE",
			"END-PERFORM",
			"END-READ",
			"END-RECEIVE",
			"END-RETURN",
			"END-REWRITE",
			"END-SEARCH",
			"END-START",
			"END-STRING",
			"END-SUBTRACT",
			"END-UNSTRING",
			"END-WRITE",
			"ENDING",
			"ENTER",
			"ENTRY",
			"ENTRY-PROCEDURE",
			"ENVIRONMENT",
			"EOP",
			"EQUAL",
			"ERASE",
			"ERROR",
			"EOL",
			"EOS",
			"ESCAPE",
			"ESI",
			"EVALUATE",
			"EVENT",
			"EVERY",
			"EXCEPTION",
			"EXCLUSIVE",
			"EXHIBIT",
			"EXIT",
			"EXPORT",
			"EXTEND",
			"EXTENDED",
			"EXTERNAL",
			"FALSE",
			"FD",
			"FILE",
			"FILE-CONTROL",
			"FILLER",
			"FINAL",
			"FIRST",
			"FOOTING",
			"FOR",
			"FOREGROUND-COLOR",
			"FOREGROUND-COLOUR",
			"FROM",
			"FULL",
			"FUNCTION",
			"FUNCTIONNAME",
			"FUNCTION-POINTER",
			"GENERATE",
			"GOBACK",
			"GIVING",
			"GLOBAL",
			"GO",
			"GREATER",
			"GRID",
			"GROUP",
			"HEADING",
			"HIGHLIGHT",
			"HIGH-VALUE",
			"HIGH-VALUES",
			"I-O",
			"I-O-CONTROL",
			"ID",
			"IDENTIFICATION",
			"IF",
			"IMPLICIT",
			"IMPORT",
			"IN",
			"INDEX",
			"INDEXED",
			"INDICATE",
			"INITIAL",
			"INITIALIZE",
			"INITIATE",
			"INPUT",
			"INPUT-OUTPUT",
			"INSPECT",
			"INSTALLATION",
			"INTEGER",
			"INTO",
			"INVALID",
			"INVOKE",
			"IS",
			"JUST",
			"JUSTIFIED",
			"KANJI",
			"KEPT",
			"KEY",
			"KEYBOARD",
			"LABEL",
			"LANGUAGE",
			"LAST",
			"LB",
			"LD",
			"LEADING",
			"LEFT",
			"LEFTLINE",
			"LENGTH",
			"LENGTH-CHECK",
			"LESS",
			"LIBACCESS",
			"LIBPARAMETER",
			"LIBRARY",
			"LIMIT",
			"LIMITS",
			"LINAGE",
			"LINAGE-COUNTER",
			"LINE",
			"LINES",
			"LINE-COUNTER",
			"LINKAGE",
			"LIST",
			"LOCAL",
			"LOCAL-STORAGE",
			"LOCK",
			"LONG-DATE",
			"LONG-TIME",
			"LOWER",
			"LOWLIGHT",
			"LOW-VALUE",
			"LOW-VALUES",
			"MEMORY",
			"MERGE",
			"MESSAGE",
			"MMDDYYYY",
			"MODE",
			"MODULES",
			"MORE-LABELS",
			"MOVE",
			"MULTIPLE",
			"MULTIPLY",
			"NAMED",
			"NATIONAL",
			"NATIONAL-EDITED",
			"NATIVE",
			"NEGATIVE",
			"NETWORK",
			"NEXT",
			"NO",
			"NO-ECHO",
			"NOT",
			"NULL",
			"NULLS",
			"NUMBER",
			"NUMERIC",
			"NUMERIC-DATE",
			"NUMERIC-EDITED",
			"NUMERIC-TIME",
			"OBJECT-COMPUTER",
			"OCCURS",
			"ODT",
			"OF",
			"OFF",
			"OMITTED",
			"ON",
			"OPEN",
			"OPTIONAL",
			"OR",
			"ORDER",
			"ORDERLY",
			"ORGANIZATION",
			"OTHER",
			"OUTPUT",
			"OVERFLOW",
			"OVERLINE",
			"OWN",
			"PACKED-DECIMAL",
			"PADDING",
			"PAGE",
			"PAGE-COUNTER",
			"PASSWORD",
			"PERFORM",
			"PF",
			"PH",
			"PIC",
			"PICTURE",
			"PLUS",
			"POINTER",
			"POSITION",
			"POSITIVE",
			"PORT",
			"PRINTER",
			"PRINTING",
			"PRIVATE",
			"PROCEDURE",
			"PROCEDURE-POINTER",
			"PROCEDURES",
			"PROCEED",
			"PROCESS",
			"PROGRAM",
			"PROGRAM-ID",
			"PROGRAM-LIBRARY",
			"PROMPT",
			"PURGE",
			"QUEUE",
			"QUOTE",
			"QUOTES",
			"RANDOM",
			"READER",
			"REMOTE",
			"RD",
			"REAL",
			"READ",
			"RECEIVE",
			"RECEIVED",
			"RECORD",
			"RECORDING",
			"RECORDS",
			"RECURSIVE",
			"REDEFINES",
			"REEL",
			"REF",
			"REFERENCE",
			"REFERENCES",
			"RELATIVE",
			"RELEASE",
			"REMAINDER",
			"REMARKS",
			"REMOVAL",
			"REMOVE",
			"RENAMES",
			"REPLACE",
			"REPLACING",
			"REPORT",
			"REPORTING",
			"REPORTS",
			"REQUIRED",
			"RERUN",
			"RESERVE",
			"REVERSE-VIDEO",
			"RESET",
			"RETURN",
			"RETURN-CODE",
			"RETURNING",
			"REVERSED",
			"REWIND",
			"REWRITE",
			"RF",
			"RH",
			"RIGHT",
			"ROUNDED",
			"RUN",
			"SAME",
			"SAVE",
			"SCREEN",
			"SD",
			"SEARCH",
			"SECTION",
			"SECURE",
			"SECURITY",
			"SEGMENT",
			"SEGMENT-LIMIT",
			"SELECT",
			"SEND",
			"SENTENCE",
			"SEPARATE",
			"SEQUENCE",
			"SEQUENTIAL",
			"SET",
			"SHARED",
			"SHAREDBYALL",
			"SHAREDBYRUNUNIT",
			"SHARING",
			"SHIFT-IN",
			"SHIFT-OUT",
			"SHORT-DATE",
			"SIGN",
			"SIZE",
			"SORT",
			"SORT-CONTROL",
			"SORT-CORE-SIZE",
			"SORT-FILE-SIZE",
			"SORT-MERGE",
			"SORT-MESSAGE",
			"SORT-MODE-SIZE",
			"SORT-RETURN",
			"SOURCE",
			"SOURCE-COMPUTER",
			"SPACE",
			"SPACES",
			"SPECIAL-NAMES",
			"STANDARD",
			"STANDARD-1",
			"STANDARD-2",
			"START",
			"STATUS",
			"STOP",
			"STRING",
			"SUB-QUEUE-1",
			"SUB-QUEUE-2",
			"SUB-QUEUE-3",
			"SUBTRACT",
			"SUM",
			"SUPPRESS",
			"SYMBOL",
			"SYMBOLIC",
			"SYNC",
			"SYNCHRONIZED",
			"TABLE",
			"TALLY",
			"TALLYING",
			"TASK",
			"TAPE",
			"TERMINAL",
			"TERMINATE",
			"TEST",
			"TEXT",
			"THAN",
			"THEN",
			"THREAD",
			"THREAD-LOCAL",
			"THROUGH",
			"THRU",
			"TIME",
			"TIMER",
			"TIMES",
			"TITLE",
			"TO",
			"TODAYS-DATE",
			"TODAYS-NAME",
			"TOP",
			"TRAILING",
			"TRUE",
			"TRUNCATED",
			"TYPE",
			"TYPEDEF",
			"UNDERLINE",
			"UNIT",
			"UNSTRING",
			"UNTIL",
			"UP",
			"UPON",
			"USAGE",
			"USE",
			"USING",
			"VALUE",
			"VALUES",
			"VARYING",
			"VIRTUAL",
			"WAIT",
			"WHEN",
			"WHEN-COMPILED",
			"WITH",
			"WORDS",
			"WORKING-STORAGE",
			"WRITE",
			"YEAR",
			"YYYYMMDD",
			"YYYYDDD",
			"ZERO",
			"ZERO-FILL",
			"ZEROS",
			"ZEROES"
	};
	// cat cobolops_orig.txt | cut  -d':' -f2 | sed "s/'/\"/g" | sed "s/;/,/g"
	public static final String [] ops = {
			"&",
			 "*",
			 "**",
			 ":", // weiz 
			 ",",
			 "*>CE",
			 "*>",
			 "$",
			 "\"",
			 //"." ("\r" | "\n" | "\f" | "\t" | " ")+ | "." EOF, // weiz 2020-11-19, not sure how to handle this
			 ".",
			 "=",
			 "*>EXECCICS",
			 "*>EXECSQL",
			 "*>EXECSQLIMS",
			 "<",
			 "<=",
			 "(",
			 "-",
			 ">",
			 ">=",
			 "<>",
			 "+",
			 "\'",
			 ")",
			 "/",

	};

	@Override
	public boolean isReserved(String word) {
		return (keywordsHashSet.contains(word) || opsHashSet.contains(word));
	}
	
	HashSet<String> keywordsHashSet=new HashSet<String>();
	HashSet<String> opsHashSet = new HashSet<String>();
	public void buildKeyWordsHashSet() {
		for(String keyword: keywords) {
			keywordsHashSet.add(keyword);
		}
	}
	public void buildOPsHashSet() {
		for(String op: ops) {
			opsHashSet.add(op);
		}
	}
	
	public CobolReservedWordDecider() {
		buildKeyWordsHashSet();
		buildOPsHashSet();
	}
}
