use of priv.bajdcc.util.lexer.token.OperatorType in project jMiniLang by bajdcc.
the class OperatorTokenizer method getRegexString.
public static String getRegexString() {
MetaType[] metaTypes = new MetaType[] { MetaType.LPARAN, MetaType.RPARAN, MetaType.STAR, MetaType.PLUS, MetaType.LSQUARE, MetaType.RSQUARE, MetaType.LBRACE, MetaType.RBRACE, MetaType.DOT, MetaType.BAR, MetaType.QUERY };
StringBuilder sb = new StringBuilder();
for (OperatorType type : OperatorType.values()) {
String op = type.getName();
for (MetaType meta : metaTypes) {
op = op.replace(meta.getChar() + "", "\\" + meta.getChar());
}
if (type == OperatorType.ESCAPE)
op += op;
sb.append(op).append("|");
}
if (sb.length() > 0) {
sb.deleteCharAt(sb.length() - 1);
}
return sb.toString();
}
use of priv.bajdcc.util.lexer.token.OperatorType 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;
}
use of priv.bajdcc.util.lexer.token.OperatorType in project jMiniLang by bajdcc.
the class RuntimeMachine method runByStep.
private boolean runByStep() throws Exception {
RuntimeInst inst = RuntimeInst.values()[currentInst()];
if (inst == RuntimeInst.ihalt) {
return false;
}
if (debug) {
System.err.println();
System.err.print(stack.reg.execId + ": " + inst.toString());
}
OperatorType op = TokenTools.ins2op(inst);
nextInst();
if (op != null) {
if (!RuntimeTools.calcOp(stack.reg, inst, this)) {
err(RuntimeError.UNDEFINED_CONVERT, op.getName());
}
} else {
if (!RuntimeTools.calcData(stack.reg, inst, this)) {
if (!RuntimeTools.calcJump(stack.reg, inst, this)) {
err(RuntimeError.WRONG_INST, inst.toString());
}
}
}
if (debug) {
System.err.println();
System.err.print(stack.toString());
// System.err.print("协程栈:");
// System.err.print(stkYieldData.toString());
System.err.println();
}
return true;
}
use of priv.bajdcc.util.lexer.token.OperatorType in project jMiniLang by bajdcc.
the class ExpBinop method genCode.
@Override
public void genCode(ICodegen codegen) {
if (token.kToken == TokenType.OPERATOR && token.object == OperatorType.DOT) {
codegen.genCode(RuntimeInst.iopena);
leftOperand.genCode(codegen);
codegen.genCode(RuntimeInst.ipusha);
rightOperand.genCode(codegen);
codegen.genCode(RuntimeInst.ipusha);
codegen.genCode(RuntimeInst.ipush, codegen.genDataRef("g_get_property"));
codegen.genCode(RuntimeInst.icallx);
return;
}
if (token.kToken == TokenType.OPERATOR) {
OperatorType op = (OperatorType) token.object;
if (TokenTools.isAssignment(op)) {
RuntimeInst ins = TokenTools.op2ins(token);
ExpValue left = (ExpValue) leftOperand;
if (ins == RuntimeInst.ice) {
rightOperand.genCode(codegen);
codegen.genCode(RuntimeInst.ipush, codegen.genDataRef(left.getToken().object));
codegen.genCode(RuntimeInst.istore);
return;
}
leftOperand.genCode(codegen);
rightOperand.genCode(codegen);
codegen.genCode(ins);
codegen.genCode(RuntimeInst.ipush, codegen.genDataRef(left.getToken().object));
codegen.genCode(RuntimeInst.istore);
return;
} else if (op == OperatorType.COLON) {
rightOperand.genCode(codegen);
leftOperand.genCode(codegen);
return;
}
}
RuntimeInst inst = TokenTools.op2ins(token);
leftOperand.genCode(codegen);
RuntimeInstUnary jmp = null;
switch(inst) {
case iandl:
jmp = codegen.genCode(RuntimeInst.ijfx, -1);
break;
case iorl:
jmp = codegen.genCode(RuntimeInst.ijtx, -1);
break;
default:
break;
}
rightOperand.genCode(codegen);
codegen.genCode(inst);
if (jmp != null) {
jmp.op1 = codegen.getCodeIndex();
}
}
use of priv.bajdcc.util.lexer.token.OperatorType in project jMiniLang by bajdcc.
the class ExpBinop method analysis.
@Override
public void analysis(ISemanticRecorder recorder) {
if (token.kToken == TokenType.OPERATOR) {
OperatorType op = (OperatorType) token.object;
if (TokenTools.isAssignment(op)) {
if (!(leftOperand instanceof ExpValue)) {
recorder.add(SemanticException.SemanticError.INVALID_ASSIGNMENT, token);
}
}
}
leftOperand.analysis(recorder);
rightOperand.analysis(recorder);
}
Aggregations