use of priv.bajdcc.util.lexer.token.KeywordType in project jMiniLang by bajdcc.
the class SemanticHandler method initializeAction.
/**
* 初始化动作
*/
private void initializeAction() {
/* 进入块 */
mapSemanticAction.put("do_enter_scope", (indexed, manage, access, recorder) -> manage.getManageScopeService().enterScope());
/* 离开块 */
mapSemanticAction.put("do_leave_scope", (indexed, manage, access, recorder) -> manage.getManageScopeService().leaveScope());
/* 声明过程名 */
mapSemanticAction.put("predeclear_funcname", (indexed, manage, access, recorder) -> {
Token token = access.relativeGet(0);
String funcName = token.toRealString();
if (token.kToken == TokenType.ID) {
if (manage.getQueryScopeService().getEntryName().equals(funcName)) {
recorder.add(SemanticError.DUP_ENTRY, token);
} else if (manage.getQueryScopeService().isRegisteredFunc(funcName)) {
recorder.add(SemanticError.DUP_FUNCNAME, token);
}
}
Function func = new Function();
func.setName(token);
manage.getManageScopeService().registerFunc(func);
if (token.kToken != TokenType.ID) {
token.object = func.getRealName();
token.kToken = TokenType.ID;
}
});
/* 声明变量名 */
mapSemanticAction.put("declear_variable", (indexed, manage, access, recorder) -> {
KeywordType spec = (KeywordType) access.relativeGet(-1).object;
Token token = access.relativeGet(0);
String name = token.toRealString();
if (spec == KeywordType.VARIABLE) {
if (!manage.getQueryScopeService().findDeclaredSymbol(name)) {
if (!manage.getQueryScopeService().isRegisteredFunc(name)) {
manage.getManageScopeService().registerSymbol(name);
} else {
recorder.add(SemanticError.VAR_FUN_CONFLICT, token);
}
} else if (!TokenTools.isExternalName(name) && manage.getQueryScopeService().findDeclaredSymbolDirect(name)) {
recorder.add(SemanticError.VARIABLE_REDECLARAED, token);
}
} else if (spec == KeywordType.LET) {
if (!manage.getQueryScopeService().findDeclaredSymbol(name)) {
recorder.add(SemanticError.VARIABLE_NOT_DECLARAED, token);
}
}
});
/* 声明参数 */
mapSemanticAction.put("declear_param", (indexed, manage, access, recorder) -> {
Token token = access.relativeGet(0);
if (!manage.getManageScopeService().registerFutureSymbol(token.toRealString())) {
recorder.add(SemanticError.DUP_PARAM, token);
}
});
/* 清除参数 */
mapSemanticAction.put("func_clearargs", (indexed, manage, access, recorder) -> {
manage.getManageScopeService().clearFutureArgs();
Token token = access.relativeGet(0);
KeywordType type = (KeywordType) token.object;
if (type == KeywordType.YIELD) {
manage.getQueryBlockService().enterBlock(BlockType.kYield);
}
});
/* CATCH 清除参数 */
mapSemanticAction.put("clear_catch", (indexed, manage, access, recorder) -> {
manage.getManageScopeService().clearFutureArgs();
});
/* 循环体 */
mapSemanticAction.put("do_enter_cycle", (indexed, manage, access, recorder) -> manage.getQueryBlockService().enterBlock(BlockType.kCycle));
/* 匿名函数处理 */
mapSemanticAction.put("lambda", (indexed, manage, access, recorder) -> {
manage.getManageScopeService().clearFutureArgs();
Token token = access.relativeGet(0);
Function func = new Function();
func.setName(token);
manage.getManageScopeService().registerLambda(func);
token.object = func.getRealName();
});
}
use of priv.bajdcc.util.lexer.token.KeywordType in project jMiniLang by bajdcc.
the class Grammar method declareTerminal.
/**
* 声明终结符
*
* @throws SyntaxException 词法错误
*/
private void declareTerminal() throws SyntaxException {
addTerminal("ID", TokenType.ID, null);
addTerminal("BOOLEAN", TokenType.BOOL, null);
addTerminal("LITERAL", TokenType.STRING, null);
addTerminal("CHARACTER", TokenType.CHARACTER, null);
addTerminal("INTEGER", TokenType.INTEGER, null);
addTerminal("DECIMAL", TokenType.DECIMAL, null);
for (KeywordType keywordType : KeywordType.values()) {
addTerminal(keywordType.name(), TokenType.KEYWORD, keywordType);
}
addTerminal("ELLIPSIS", TokenType.OPERATOR, OperatorType.ELLIPSIS);
addTerminal("PTR_OP", TokenType.OPERATOR, OperatorType.POINTER);
addTerminal("INC_OP", TokenType.OPERATOR, OperatorType.PLUS_PLUS);
addTerminal("DEC_OP", TokenType.OPERATOR, OperatorType.MINUS_MINUS);
addTerminal("LEFT_OP", TokenType.OPERATOR, OperatorType.LEFT_SHIFT);
addTerminal("RIGHT_OP", TokenType.OPERATOR, OperatorType.RIGHT_SHIFT);
addTerminal("LE_OP", TokenType.OPERATOR, OperatorType.LESS_THAN_OR_EQUAL);
addTerminal("GE_OP", TokenType.OPERATOR, OperatorType.GREATER_THAN_OR_EQUAL);
addTerminal("EQ_OP", TokenType.OPERATOR, OperatorType.EQUAL);
addTerminal("NE_OP", TokenType.OPERATOR, OperatorType.NOT_EQUAL);
addTerminal("AND_OP", TokenType.OPERATOR, OperatorType.LOGICAL_AND);
addTerminal("OR_OP", TokenType.OPERATOR, OperatorType.LOGICAL_OR);
addTerminal("MUL_ASSIGN", TokenType.OPERATOR, OperatorType.TIMES_ASSIGN);
addTerminal("DIV_ASSIGN", TokenType.OPERATOR, OperatorType.DIV_ASSIGN);
addTerminal("MOD_ASSIGN", TokenType.OPERATOR, OperatorType.MOD_ASSIGN);
addTerminal("ADD_ASSIGN", TokenType.OPERATOR, OperatorType.PLUS_ASSIGN);
addTerminal("SUB_ASSIGN", TokenType.OPERATOR, OperatorType.MINUS_ASSIGN);
addTerminal("LEFT_ASSIGN", TokenType.OPERATOR, OperatorType.LEFT_SHIFT_ASSIGN);
addTerminal("RIGHT_ASSIGN", TokenType.OPERATOR, OperatorType.RIGHT_SHIFT_ASSIGN);
addTerminal("AND_ASSIGN", TokenType.OPERATOR, OperatorType.AND_ASSIGN);
addTerminal("XOR_ASSIGN", TokenType.OPERATOR, OperatorType.XOR_ASSIGN);
addTerminal("OR_ASSIGN", TokenType.OPERATOR, OperatorType.OR_ASSIGN);
addTerminal("EQ_ASSIGN", TokenType.OPERATOR, OperatorType.EQ_ASSIGN);
addTerminal("ADD", TokenType.OPERATOR, OperatorType.PLUS);
addTerminal("SUB", TokenType.OPERATOR, OperatorType.MINUS);
addTerminal("MUL", TokenType.OPERATOR, OperatorType.TIMES);
addTerminal("DIV", TokenType.OPERATOR, OperatorType.DIVIDE);
addTerminal("MOD", TokenType.OPERATOR, OperatorType.MOD);
addTerminal("AND", TokenType.OPERATOR, OperatorType.BIT_AND);
addTerminal("OR", TokenType.OPERATOR, OperatorType.BIT_OR);
addTerminal("XOR", TokenType.OPERATOR, OperatorType.BIT_XOR);
addTerminal("NOT", TokenType.OPERATOR, OperatorType.BIT_NOT);
addTerminal("NOT_OP", TokenType.OPERATOR, OperatorType.LOGICAL_NOT);
addTerminal("LT", TokenType.OPERATOR, OperatorType.LESS_THAN);
addTerminal("GT", TokenType.OPERATOR, OperatorType.GREATER_THAN);
addTerminal("QUERY", TokenType.OPERATOR, OperatorType.QUERY);
addTerminal("COMMA", TokenType.OPERATOR, OperatorType.COMMA);
addTerminal("SEMI", TokenType.OPERATOR, OperatorType.SEMI);
addTerminal("DOT", TokenType.OPERATOR, OperatorType.DOT);
addTerminal("ASSIGN", TokenType.OPERATOR, OperatorType.ASSIGN);
addTerminal("COLON", TokenType.OPERATOR, OperatorType.COLON);
addTerminal("LPA", TokenType.OPERATOR, OperatorType.LPARAN);
addTerminal("RPA", TokenType.OPERATOR, OperatorType.RPARAN);
addTerminal("LSQ", TokenType.OPERATOR, OperatorType.LSQUARE);
addTerminal("RSQ", TokenType.OPERATOR, OperatorType.RSQUARE);
addTerminal("LBR", TokenType.OPERATOR, OperatorType.LBRACE);
addTerminal("RBR", TokenType.OPERATOR, OperatorType.RBRACE);
addTerminal("PROPERTY", TokenType.OPERATOR, OperatorType.PROPERTY);
}
use of priv.bajdcc.util.lexer.token.KeywordType in project jMiniLang by bajdcc.
the class IdentifierTokenizer method getToken.
/*
* (非 Javadoc)
*
* @see
* priv.bajdcc.lexer.algorithm.ITokenAlgorithm#getToken(java.lang.String,
* priv.bajdcc.lexer.token.Token)
*/
@Override
public Token getToken(String string, Token token, IRegexStringIterator iterator) {
if (mapKeywords.containsKey(string)) {
KeywordType kw = mapKeywords.get(string);
switch(kw) {
case TRUE:
token.kToken = TokenType.BOOL;
token.object = true;
break;
case FALSE:
token.kToken = TokenType.BOOL;
token.object = false;
break;
default:
token.kToken = TokenType.KEYWORD;
token.object = kw;
break;
}
} else {
token.kToken = TokenType.ID;
token.object = string;
}
return token;
}
Aggregations