|
1 | | -package parser; |
2 | | - |
3 | | -/** |
4 | | -<b> |
5 | | -Purpose: Types of Tokens to be created by Lexical Analyzer.<br> |
6 | | -Programmer: Gabriel Toban Harris <br> |
7 | | -Date: 2021-07-26, 2021-7-30 |
8 | | -</b> |
9 | | -*/ |
10 | | - |
11 | | -public class Token |
12 | | -{ |
13 | | - /** |
14 | | - * Types to be used to identify token. |
15 | | - * |
16 | | - * SPECIAL_SEPERATOR is an enum solely to divide the properly formed tokens from the error tokens. Thus should not be used outside of this enum. |
17 | | - * Thus < SPECIAL_SEPERATOR is properly formed, > SPECIAL_SEPERATOR is error token, and == SPECIAL_SEPERATOR is itself. |
18 | | - * |
19 | | - */ |
20 | | - public static enum Lexeme_Types |
21 | | - { |
22 | | - DECK_START, ID, SEMI_COLON, PROBABILITY_START, SENTINEL_START, SENTINEL_END, ASSIGN, TREE_START, NOT, CONDITION_CARD_START, CONDITION_CARD_END, |
23 | | - CONDITION_SCENARIO_START, CONDITION_SCENARIO_END, CONDITION_EXPR_START, CONDITION_EXPR_END, OR, AND, XOR, DISPLAY_START, TRUE, FALSE, LINE_COMMENT, BLOCK_COMMENT, |
24 | | - SPECIAL_SEPERATOR, UNKNOWN_CHARACTER_ERROR, ID_ERROR, BLOCK_COMMENT_ERROR; |
25 | | - |
26 | | - /** |
27 | | - * Compares SPECIAL_SEPERATOR with INPUT. Expecting it to be -1, so that value < 0 is true. |
28 | | - * |
29 | | - * @param INPUT value to be compared against, expected not to be {Lexeme_Types.SPECIAL_SEPERATOR} |
30 | | - * @return comparison < 0 |
31 | | - */ |
32 | | - public static boolean is_error(final Lexeme_Types INPUT) |
33 | | - { |
34 | | - return Lexeme_Types.SPECIAL_SEPERATOR.compareTo(INPUT) < 0; |
35 | | - } |
36 | | - |
37 | | - } |
38 | | - |
39 | | - private final Token.Lexeme_Types TYPE; |
40 | | - private final long LINE_NUMBER; |
41 | | - private final String LEXEME; |
42 | | - |
43 | | - /** |
44 | | - * Constructor of Token. |
45 | | - * |
46 | | - * @param TYPE of LEXEME |
47 | | - * @param LINE_NUMBER location in source file |
48 | | - * @param LEXEME content of lexeme which is then trimmed by {@link String#trim()} |
49 | | - */ |
50 | | - public Token(final Token.Lexeme_Types TYPE, final long LINE_NUMBER, final String LEXEME) |
51 | | - { |
52 | | - this.TYPE = TYPE; |
53 | | - this.LINE_NUMBER = LINE_NUMBER; |
54 | | - this.LEXEME = LEXEME.trim(); |
55 | | - } |
56 | | - |
57 | | - //getters |
58 | | - /** |
59 | | - * @return the LEXEME TYPE |
60 | | - */ |
61 | | - public Token.Lexeme_Types get_type() |
62 | | - { |
63 | | - return this.TYPE; |
64 | | - } |
65 | | - |
66 | | - /** |
67 | | - * @return the LINE_NUMBER |
68 | | - */ |
69 | | - public long get_line_number() |
70 | | - { |
71 | | - return this.LINE_NUMBER; |
72 | | - } |
73 | | - |
74 | | - /** |
75 | | - * @return the LEXEME |
76 | | - */ |
77 | | - public String get_lexeme() |
78 | | - { |
79 | | - return this.LEXEME; |
80 | | - } |
81 | | - |
82 | | - /* |
83 | | - * String version of class. |
84 | | - */ |
85 | | - public String toString() |
86 | | - { |
87 | | - return "[Lexeme TYPE: " + this.get_type() + ", LEXEME: " + get_lexeme() + ", line number: " + this.get_line_number() + "]"; |
88 | | - } |
89 | | -} |
| 1 | +package parser; |
| 2 | + |
| 3 | +/** |
| 4 | +<b> |
| 5 | +Purpose: Types of Tokens to be created by {@link Tokenizer}.<br> |
| 6 | +Programmer: Gabriel Toban Harris <br> |
| 7 | +Date: 2021-07-26, 2021-7-30 |
| 8 | +</b> |
| 9 | +*/ |
| 10 | + |
| 11 | +public class Token |
| 12 | +{ |
| 13 | + /** |
| 14 | + * Types to be used to identify token. |
| 15 | + * |
| 16 | + * SPECIAL_SEPERATOR is an enum solely to divide the properly formed tokens from the error tokens. Thus should not be used outside of this enum. |
| 17 | + * Thus < SPECIAL_SEPERATOR is properly formed, > SPECIAL_SEPERATOR is error token, and == SPECIAL_SEPERATOR is itself. |
| 18 | + * |
| 19 | + */ |
| 20 | + public static enum Lexeme_Types |
| 21 | + { |
| 22 | + DECK_START, ID, SEMI_COLON, PROBABILITY_START, SENTINEL_START, SENTINEL_END, ASSIGN, TREE_START, NOT, CONDITION_CARD_START, CONDITION_CARD_END, |
| 23 | + CONDITION_SCENARIO_START, CONDITION_SCENARIO_END, CONDITION_EXPR_START, CONDITION_EXPR_END, OR, AND, XOR, DISPLAY_START, TRUE, FALSE, LINE_COMMENT, BLOCK_COMMENT, |
| 24 | + SPECIAL_SEPERATOR, UNKNOWN_CHARACTER_ERROR, ID_ERROR, BLOCK_COMMENT_ERROR; |
| 25 | + |
| 26 | + /** |
| 27 | + * Compares SPECIAL_SEPERATOR with INPUT. Expecting it to be -1, so that value < 0 is true. |
| 28 | + * |
| 29 | + * @param INPUT value to be compared against, expected not to be {Lexeme_Types.SPECIAL_SEPERATOR} |
| 30 | + * @return comparison < 0 |
| 31 | + */ |
| 32 | + public static boolean is_error(final Lexeme_Types INPUT) |
| 33 | + { |
| 34 | + return Lexeme_Types.SPECIAL_SEPERATOR.compareTo(INPUT) < 0; |
| 35 | + } |
| 36 | + |
| 37 | + } |
| 38 | + |
| 39 | + private final Token.Lexeme_Types TYPE; |
| 40 | + private final long LINE_NUMBER; |
| 41 | + private final String LEXEME; |
| 42 | + |
| 43 | + /** |
| 44 | + * Constructor of Token. |
| 45 | + * |
| 46 | + * @param TYPE of LEXEME |
| 47 | + * @param LINE_NUMBER location in source file |
| 48 | + * @param LEXEME content of lexeme which is then trimmed by {@link String#trim()} |
| 49 | + */ |
| 50 | + public Token(final Token.Lexeme_Types TYPE, final long LINE_NUMBER, final String LEXEME) |
| 51 | + { |
| 52 | + this.TYPE = TYPE; |
| 53 | + this.LINE_NUMBER = LINE_NUMBER; |
| 54 | + this.LEXEME = LEXEME.trim(); |
| 55 | + } |
| 56 | + |
| 57 | + //getters |
| 58 | + /** |
| 59 | + * @return the LEXEME TYPE |
| 60 | + */ |
| 61 | + public Token.Lexeme_Types get_type() |
| 62 | + { |
| 63 | + return this.TYPE; |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * @return the LINE_NUMBER |
| 68 | + */ |
| 69 | + public long get_line_number() |
| 70 | + { |
| 71 | + return this.LINE_NUMBER; |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * @return the LEXEME |
| 76 | + */ |
| 77 | + public String get_lexeme() |
| 78 | + { |
| 79 | + return this.LEXEME; |
| 80 | + } |
| 81 | + |
| 82 | + /* |
| 83 | + * String version of class. |
| 84 | + */ |
| 85 | + public String toString() |
| 86 | + { |
| 87 | + return "[Lexeme TYPE: " + this.get_type() + ", LEXEME: " + get_lexeme() + ", line number: " + this.get_line_number() + "]"; |
| 88 | + } |
| 89 | +} |
0 commit comments