parseNode function
parse to node
Implementation
Node parseNode(
Node parent,
Token? label,
Token? opecode,
List<Token> operand,
Env env, {
required Token current,
}) {
if (opecode == null) {
return ErrorNode(
'[SYNTAX ERROR] opecode not found.',
start: current.end,
end: current.end + 1,
lineStart: current.lineStart,
lineNumber: current.lineNumber,
);
}
switch (opecode.runesAsString) {
case 'LD':
case 'ADDA':
case 'SUBA':
case 'ADDL':
case 'SUBL':
case 'AND':
case 'OR':
case 'XOR':
case 'CPA':
case 'CPL':
return parseGeneralNode(
parent,
label,
opecode,
operand,
env,
);
case 'ST':
case 'LAD':
case 'SLA':
case 'SRA':
case 'SLL':
case 'SRL':
return parseRadrxNode(
parent,
label,
opecode,
operand,
env,
);
case 'JMI':
case 'JNZ':
case 'JZE':
case 'JUMP':
case 'JPL':
case 'JOV':
case 'PUSH':
case 'CALL':
case 'SVC':
return parseAdrxNode(
parent,
label,
opecode,
operand,
env,
);
case 'POP':
return parseRNode(
parent,
label,
opecode,
operand,
env,
);
case 'RET':
return Statement(
parent,
opecode,
operand,
label: label,
code: [LiteralCode(0x8100)],
);
case 'START':
case 'END':
return Statement(
parent,
opecode,
operand,
label: label,
);
case 'DC':
// TODO error handling!
return Statement(
parent,
opecode,
operand,
label: label,
code: _parseDC(operand, env),
);
case 'DS':
// TODO error handling!
return Statement(
parent,
opecode,
operand,
label: label,
code: _parseDS(operand, env),
);
default:
return parseMacro(
parent,
label,
opecode,
operand,
env,
);
}
}