Token AddToken(string value, TokenType tokentype, bool resolved, string originalvalue) { CurrentToken = new Token(value, tokentype, CurrentToken, resolved); CurrentToken.Line = Assembler.currentLine; tokens.Add(CurrentToken); TokenizerEventArgs e = new TokenizerEventArgs(CurrentChar, CurrentToken); TokenFound?.Invoke(this, e); CurrentChar = e.CurrentChar; CurrentToken.Row = row; CurrentToken.Col = CurrentChar - originalvalue.Length; CurrentToken.OriginalValue = originalvalue; return(CurrentToken); }
Token AddToken(string value, TokenType tokentype) { if (value == "\r") { value = ""; } CurrentToken = new Token(value, tokentype, CurrentToken); CurrentToken.Line = Assembler.currentLine; tokens.Add(CurrentToken); TokenizerEventArgs e = new TokenizerEventArgs(CurrentChar, CurrentToken); TokenFound?.Invoke(this, e); CurrentChar = e.CurrentChar; CurrentToken = e.Token; CurrentToken.Row = row; CurrentToken.Col = CurrentChar - value.Length; CurrentToken.OriginalValue = value; return(CurrentToken); }
private void Tokenizer_TokenFound(object sender, TokenizerEventArgs e) { Tokenizer tokenizer = sender as Tokenizer; // ==================================================================== // If we have a symbol // ==================================================================== if (e.Token.TokenType == TokenType.Symbol) { // ==================================================================== // if the current char is a colon then we have a label // append a colon to the token // and advance the current char pointer // ==================================================================== if (e.CurrentChar < tokenizer.Source.Length) { if (tokenizer[e.CurrentChar] == ':') { e.Token.TokenType = TokenType.Label; e.Token.Value += ':'; e.CurrentChar++; } } // ==================================================================== // OK, so we still have a symbol, now determine the type of symbol // but ignore Equations // ==================================================================== if (e.Token.TokenType == TokenType.Symbol) { e.Token.TokenType = DecodeIdentifier(e.Token.Value); if (e.Token.TokenType == TokenType.Directive) { if (e.Token.Previous != null) { // ==================================================================== // if the previous char is a period // prepend a period to the token // update the previous token to be the current token // ==================================================================== if (e.Token.Previous.Value == ".") { e.Token.Previous.Value = "." + e.Token.Value; e.Token.Previous.TokenType = e.Token.TokenType; e.Token.Previous.Next = null; e.Token = e.Token.Previous; } } } } } // ==================================================================== // Now we need to consider special cases for C and AF' // ==================================================================== switch (e.Token.Value.ToUpper()) { case "C": // ==================================================================== // Special case for C (can be Register or Condition) // Check the context of the last instruction // For a CALL, JR, JP or RET; C is Condition; // anything else C is a Register // ==================================================================== if (e.Token.TokenType == TokenType.String) { break; } try { if ("|RET|JR|JP|CALL|".Contains("|" + e.Token.Previous.Value.ToUpper() + "|")) { e.Token.TokenType = TokenType.Condition; } else { e.Token.TokenType = TokenType.Register; } } catch { } break; case "AF": // ==================================================================== // Special case for AF' // if the current char is a tilde append a tilde to the token // and advance the current char pointer // ==================================================================== if (tokenizer[e.CurrentChar] == '\'') { e.CurrentChar++; e.Token.Value += "'"; } break; } }