public static void CheckArgIsRegisterOrAtom(Token token) { if (token == null) { throw new ArgumentNullException("token"); } bool ok = false; do { if (TokenIsRegister(token)) { ok = true; break; } if (TokenIsAtom(token)) { ok = true; break; } // got here => got problem (ok is false) } while (false); if (!ok) { throw new ApplicationException(); // todo2[ak] } }
public override Instruction Build(Token[] args) { AsmHelper.CheckArgsCount(args, 1); Instruction instr = (JmpInstructionBase)Activator.CreateInstance(this.JmpInstructionType); return instr; }
public override Instruction Build(Token[] args) { // todo1[ak] check args AsmHelper.CheckArgsCount(args, 0); Instruction instr = new RetInstruction(); return instr; }
public static void CheckArgsCount(Token[] tokens, int expectedCount) { // todo1[ak] check args if (tokens.Length != expectedCount) { throw new ApplicationException(); // todo1[ak] } }
public override Instruction Build(Token[] args) { // todo1[ak] check args AsmHelper.CheckArgsCount(args, 1); RegisterName regName = AsmHelper.TokenToRegisterName(args[0]); TestInstruction instr = new TestInstruction(regName); return instr; }
public static void CheckArgIsRegister(Token token) { // todo1[ak] check args bool isReg = _registersIds.ContainsKey(TokenToSymbolName(token)); if (!isReg) { throw new ApplicationException(); // todo2[ak] } }
public void AddInstruction(InstructionBuilder instructionBuilder, Token[] argTokens) { // todo1[ak] check args if (this.IsFinished) { throw new ApplicationException(); // todo2[ak] } InstructionData data = new InstructionData(instructionBuilder, argTokens); _instructionDatas.Add(data); }
public override Instruction Build(Token[] args) { // todo1[ak] check args AsmHelper.CheckArgsCount(args, 2); int index = AsmHelper.TokenToInt(args[0]); RegisterName regName = AsmHelper.TokenToRegisterName(args[1]); NthInstruction instr = new NthInstruction(index, regName); return instr; }
public override Instruction Build(Token[] args) { // todo1[ak] check args if (args.Length != 1) { throw new ApplicationException(); } RegisterName regName = AsmHelper.TokenToRegisterName(args[0]); Instruction instr = new PopInstruction(regName); return instr; }
public override Instruction Build(Token[] args) { // todo1[ak] check args AsmHelper.CheckArgsCount(args, 2); AsmHelper.CheckArgIsRegister(args[0]); AsmHelper.CheckArgIsRegisterOrAtom(args[1]); RegisterName to = AsmHelper.TokenToRegisterName(args[0]); object from = AsmHelper.TokenToRegisterNameOrAtom(args[1]); MovInstruction instr = new MovInstruction(to, from); return instr; }
public override Instruction Build(Token[] args) { // todo1[ak] check args if (args.Length != 1) { throw new ApplicationException(); } Token tok = args[0]; if (!(tok is SymbolToken)) { throw new ApplicationException(); } SymbolToken sym = (SymbolToken)tok; RegisterName registerName = AsmHelper.GetRegisterName(sym.Name); Instruction instr = new CarInstruction(registerName); return instr; }
public override Instruction Build(Token[] args) { // todo1[ak] check args AsmHelper.CheckArgsCount(args, 1, 2); int from = AsmHelper.TokenToInt(args[0]); int to; if (args.Length == 2) { to = AsmHelper.TokenToInt(args[1]); } else { to = from; } // todo1[ak] check from..to Instruction instr = new CheckArgsCountInstruction(from, to); return instr; }
private Atom TokenToSimpleAtom(Token token) { Atom atom; if (token is SymbolToken) { atom = new Symbol(((SymbolToken)token).Name); } else if (token is NumberToken) { atom = new Number(((NumberToken)token).Value); } else { throw new NotImplementedException(); } return atom; }
public static LispObject TokenToAtom(Token tok) { // todo1[ak] check args LispObject el; if (tok is SymbolToken) { el = new Symbol(((SymbolToken)tok).Name); } else if (tok is NumberToken) { el = new Number(((NumberToken)tok).Value); } else { throw new NotImplementedException(); } return el; }
public static bool TokenIsAtom(Token token) { bool res = token is SymbolToken || token is NumberToken; return res; }
public static bool TokenIsRegister(Token token) { bool res = token is SymbolToken && _registersIds.ContainsKey(TokenToSymbolName(token)); return res; }
public static bool IsAtomToken(Token tok) { // todo1[ak] check args bool res; if ( tok is SymbolToken || tok is NumberToken) { res = true; } else { res = false; } return res; }
public abstract Instruction Build(Token[] args);
public static int TokenToInt(Token token) { // todo1[ak] if (!(token is NumberToken)) { throw new ApplicationException(); // todo2[ak] } NumberToken numTok = (NumberToken)token; int val = int.Parse(numTok.Value); return val; }
public static RegisterName TokenToRegisterName(Token token) { // todo1[ak] check args RegisterName res = _registersIds[TokenToSymbolName(token)]; return res; }
public static object TokenToRegisterNameOrAtom(Token token) { // todo1[ak] check args object res; if (TokenIsRegister(token)) { res = TokenToRegisterName(token); } else if (token is SymbolToken) { SymbolToken symTok = (SymbolToken)token; string name = symTok.Name; if (name == "NIL") { res = Symbol.Nil; } else if (name == "T") { res = Symbol.True; } else { throw new ApplicationException(); // todo2[ak] } } else { throw new NotImplementedException(); } return res; }
internal InstructionData(InstructionBuilder builder, Token[] argTokens) { this.Builder = builder; this.ArgTokens = argTokens; }
public static string TokenToSymbolName(Token token) { if (token == null) { throw new ArgumentNullException("token"); } if (!(token is SymbolToken)) { throw new ApplicationException(); // todo1[ak] } string name = ((SymbolToken)token).Name; return name; }
public static void CheckArgsCount(Token[] tokens, int from, int to) { // todo1[ak] check args if (!tokens.Length.Between(from, to)) { throw new ApplicationException(); // todo1[ak] } }