Class keywordsPrepare
Object
keywordsPrepare
收到新关键字列表后的处理流程,关键字分为 reserved words 和 non-reserved keywords 两种
这两类都是用逗号隔开的字符串表示,如果收到的是 同时包含 reserved words 和 non-reserved keywords 的列表,
需要先分成这两类独立的列表。 可以调用 extractNonReservedKeywords() 把 non-reserved keywords 从 full list 中分类出来。
1. 处理 reserved words
1.1 根据提供的 keyword list 列表, 确保当前 lexer 中已有的对应keyword 类型一致。调用 adjustKeywords() 实现
1.2 根据提供的 keyword list 列表, 把不在当前 lexer 中的 keyword 加入到 lexer keyword 列表中。调用 addNewKeywords() 实现
新增的 keyword 需要在 .y 文件中也加一下。
1.3 移除在 lexer 中的 keyword,但不在提供的 keyword list 列表中的 keyword, 考虑到这些 keyword 可能在 y 文件中使用,
不进行实际的移除,只是把类型从 ttreserved 改为 ttidentifier
通过调用 checkFalseKeywords() 实现
2. 处理 non-reserved keywords
2.1 根据提供的 non-keyword list 列表, 确保当前 lexer 中已有的对应 keyword 类型一致。调用 adjustKeywords() 实现
2.2 根据提供的 non-keyword list 列表, 把不在当前 lexer 中的 keyword 加入到 lexer keyword 列表中。调用 addNewKeywords() 实现
新增的 keyword 需要在 .y 文件中也加一下,并且在 rule 中要加入成为 ident。
2.3 移除在 lexer 中的 keyword,但不在提供的 non-keyword list 列表中的 keyword, 考虑到这些 keyword 可能在 y 文件中使用,
不进行实际的移除,只是把类型从 ttkeyword 改为 ttidentifier
通过调用 checkFalseKeywords() 实现
3. 检查处理结果
3.1 调用 adjustKeywords(), keywords num with different type 应该为零。
3.2 调用 addNewKeywords(), 新增的 keyword num 应该为零。
3.3 调用 checkFalseKeywords(), 发现的 false keyword 应该为零。
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddNewKeywords(String pKeywords, String pKeywordsInLexer, String kwType) static voidadjustKeywords(String pKeywords, String pKeywordsInLexer, String pKwMark) 核对 lexer keyword 列表中的 keyword,如果这些 keyword 在 规定 keyword 列表中出现,必须保证类型的也相同, 如果不同,把 lexer keyword 列表中keyword的类型调整为指定的类型。 这个操作不改变 lexer keyword 列表中 keyword 的个数static voidcheckFalseKeywords(String pKeywords, String pKeywordsInLexer, String pKwMark) 检查 lexer keywords 列表中的指定类型的 keyword 是否在 规定的 keyword 列表中出现。 理想的结果是没有发现 false keywordstatic voidcompareKeywordsWithLexerKeywords(String pReservedWords, String pKeywordsInLexer) static StringextractNonReservedKeywords(String allKeywords, String reservedWords) 输入完整的 keyword 列表 和 reserved words 列表, 输出 non-reserved keywords 列表static intinsertReservedWord(String kw, ArrayList<keywordRec> targetList, int startFrom) static ArrayList<keywordRec>keywordsInLexerToArrayList(String pKeywordsInLexer) keywordsStringToArrayList(String pReservedWords) static voidstatic StringoutNewAddReservedWords(ArrayList<keywordRec> targetList) static intsearchKwInList(String kw, ArrayList<keywordRec> targetList)
-
Field Details
-
TTRESERVED
-
TTKEYWORD
-
TTCOLUMN
-
TTIDENTIFIER
-
-
Constructor Details
-
keywordsPrepare
public keywordsPrepare()
-
-
Method Details
-
main
- Throws:
Exception
-
outNewAddReservedWords
-
searchKwInList
-
insertReservedWord
-
keywordsStringToArrayList
-
keywordsInLexerToArrayList
-
compareKeywordsWithLexerKeywords
-
addNewKeywords
-
adjustKeywords
核对 lexer keyword 列表中的 keyword,如果这些 keyword 在 规定 keyword 列表中出现,必须保证类型的也相同, 如果不同,把 lexer keyword 列表中keyword的类型调整为指定的类型。 这个操作不改变 lexer keyword 列表中 keyword 的个数- Parameters:
pKeywords-pKeywordsInLexer-pKwMark-
-
checkFalseKeywords
检查 lexer keywords 列表中的指定类型的 keyword 是否在 规定的 keyword 列表中出现。 理想的结果是没有发现 false keyword- Parameters:
pKeywords- 规定的 keyword 列表pKeywordsInLexer- lexer keywords 列表pKwMark- 需要检查的 keyword 类型, 有 TTRESERVED 和 TTKEYWORD
-
extractNonReservedKeywords
输入完整的 keyword 列表 和 reserved words 列表, 输出 non-reserved keywords 列表- Parameters:
allKeywords-reservedWords-- Returns:
-