为什么我的antlr lexer java类是“代码太大”? [英] Why my antlr lexer java class is "code too large"?
问题描述
这是Antlr中的词法分析器(对不起长文件):
This is the lexer in Antlr (sorry for a long file):
lexer grammar SqlServerDialectLexer;
/* T-SQL words */
AND: 'AND';
BIGINT: 'BIGINT';
BIT: 'BIT';
CASE: 'CASE';
CHAR: 'CHAR';
COUNT: 'COUNT';
CREATE: 'CREATE';
CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP';
DATETIME: 'DATETIME';
DECLARE: 'DECLARE';
ELSE: 'ELSE';
END: 'END';
FLOAT: 'FLOAT';
FROM: 'FROM';
GO: 'GO';
IMAGE: 'IMAGE';
INNER: 'INNER';
INSERT: 'INSERT';
INT: 'INT';
INTO: 'INTO';
IS: 'IS';
JOIN: 'JOIN';
NOT: 'NOT';
NULL: 'NULL';
NUMERIC: 'NUMERIC';
NVARCHAR: 'NVARCHAR';
ON: 'ON';
OR: 'OR';
SELECT: 'SELECT';
SET: 'SET';
SMALLINT: 'SMALLINT';
TABLE: 'TABLE';
THEN: 'THEN';
TINYINT: 'TINYINT';
UPDATE: 'UPDATE';
USE: 'USE';
VALUES: 'VALUES';
VARCHAR: 'VARCHAR';
WHEN: 'WHEN';
WHERE: 'WHERE';
QUOTE: '\'' { textMode = !textMode; };
QUOTED: {textMode}?=> ~('\'')*;
EQUALS: '=';
NOT_EQUALS: '!=';
SEMICOLON: ';';
COMMA: ',';
OPEN: '(';
CLOSE: ')';
VARIABLE: '@' NAME;
NAME:
( LETTER | '#' | '_' ) ( LETTER | NUMBER | '#' | '_' | '.' )*
;
NUMBER: DIGIT+;
fragment LETTER: 'a'..'z' | 'A'..'Z';
fragment DIGIT: '0'..'9';
SPACE
:
( ' ' | '\t' | '\n' | '\r' )+
{ skip(); }
;
JDK 1.6说代码太大
并且可以编译它。为什么以及如何解决这个问题?
JDK 1.6 says code too large
and can't compile it. Why and how to solve the problem?
推荐答案
实际上我不会说这是一个很大的语法,而且必须有一个之所以没有产生合理大小的代码。
Actually I wouldn't say this is a big grammar, and there must be a reason why it doesn't produce reasonably sized code.
我认为这个问题直接与此规则有关:
I think the problem is directly related to this rule:
QUOTED: {textMode}?=> ~('\'')*;
您是否有任何特殊原因要将QUOTED零件作为单独的标记,而不是将其合并引用,巴特也把它放在他的语法中?这也会使 textMode
变量过时。
Is there any particular reason why you want the QUOTED part as a separate token, rather than leaving it combined with the quote, as Bart also put it in his grammar? This would also make the textMode
variable obsolete.
删除QUOTE并用
QUOTED: '\'' (~'\'')* '\'';
最有可能解决问题,即使没有拆分语法。
most probably will solve the problem, even without splitting the grammar.
这篇关于为什么我的antlr lexer java类是“代码太大”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!