use of priv.bajdcc.LALR1.grammar.semantic.ISemanticRecorder in project jMiniLang by bajdcc.
the class TokenTools method sinop.
/**
* 单目运算
*
* @param recorder 错误记录
* @param exp 表达式
* @return 运算是否合法
*/
public static boolean sinop(ISemanticRecorder recorder, ExpSinop exp) {
ExpValue value = (ExpValue) exp.getOperand();
Token token = value.getToken();
OperatorType type = (OperatorType) exp.getToken().object;
if (sin(type, token)) {
return true;
}
recorder.add(SemanticError.INVALID_OPERATOR, token);
return false;
}
use of priv.bajdcc.LALR1.grammar.semantic.ISemanticRecorder in project jMiniLang by bajdcc.
the class TokenTools method triop.
/**
* 三目运算(当前只有一种形式)
*
* @param recorder 错误记录
* @param exp 表达式
* @return 运算是否合法
*/
public static int triop(ISemanticRecorder recorder, ExpTriop exp) {
ExpValue firstValue = (ExpValue) exp.getFirstOperand();
Token firstToken = exp.getFirstToken();
Token secondToken = exp.getSecondToken();
int branch = tri(firstToken, secondToken, firstValue.getToken());
if (branch != 0) {
return branch;
}
recorder.add(SemanticError.INVALID_OPERATOR, firstToken);
return 0;
}
use of priv.bajdcc.LALR1.grammar.semantic.ISemanticRecorder in project jMiniLang by bajdcc.
the class Semantic method run.
/**
* 进行语义处理
*/
private void run() throws SyntaxException {
if (!arrErrors.isEmpty()) {
System.err.println(getTrackerError());
throw new SyntaxException(SyntaxError.COMPILE_ERROR, arrErrors.get(0).position, "出现语法错误");
}
/* 规则集合 */
ArrayList<RuleItem> items = npa.getRuleItems();
/* 符号表查询接口 */
IQuerySymbol query = getQuerySymbolService();
/* 符号表管理接口 */
IManageSymbol manage = getManageSymbolService();
/* 语义错误处理接口 */
ISemanticRecorder recorder = getSemanticRecorderService();
/* 复制单词流 */
ArrayList<Token> tokens = arrTokens.stream().map(Token::copy).collect(Collectors.toCollection(ArrayList::new));
/* 运行时自动机 */
SemanticMachine machine = new SemanticMachine(items, arrActions, tokens, query, manage, recorder, debug);
/* 遍历所有指令 */
arrInsts.forEach(machine::run);
object = machine.getObject();
if (object != null) {
Function entry = (Function) object;
manage.getManageScopeService().registerFunc(entry);
}
}
use of priv.bajdcc.LALR1.grammar.semantic.ISemanticRecorder in project jMiniLang by bajdcc.
the class TokenTools method binop.
/**
* 双目运算
*
* @param recorder 错误记录
* @param exp 表达式
* @return 运算是否合法
*/
public static boolean binop(ISemanticRecorder recorder, ExpBinop exp) {
ExpValue leftValue = (ExpValue) exp.getLeftOperand();
ExpValue rightValue = (ExpValue) exp.getRightOperand();
Token token = exp.getToken();
Token leftToken = leftValue.getToken();
Token rightToken = rightValue.getToken();
OperatorType type = (OperatorType) token.object;
if (bin(type, leftToken, rightToken)) {
return true;
}
recorder.add(SemanticError.INVALID_OPERATOR, token);
return false;
}
Aggregations