# Error in code Processing

**URL:** https://discourse.processing.org/t/error-in-code-processing/40742
**Category:** Coding Questions
**Created:** [January 30, 2023, 7:56am UTC](https://discourse.processing.org/t/error-in-code-processing/40742 "2023-01-30T07:56:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![OverLord](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@OverLord](https://discourse.processing.org/u/OverLord)
#### Post date: [January 30, 2023, 7:56am UTC](https://discourse.processing.org/t/error-in-code-processing/40742/1 "2023-01-30T07:56:01Z")

</div>

The error is related to char but I can’t figure out what the problem is  
public final class Lexer{  
private static final String OPERATORS\_CHARS = “±\*/”;  
private static final TokenType OPERATOR\_TOKENS ={  
TokenType.PLUS, TokenType.MINUS,  
TokenType.STAR, TokenType.SLASH,  
};  
private final String input;  
private final int length;  
private final List tokens;  
private int pos;

public Lexer(String input){  
this.input = input;  
length = input.length();

tokens = new ArrayList\<\>();  
}

public List tokenize(){  
while(pos \< length){  
final char current = peek();  
if(Character.isDigit(current)) tokenizeNumber();  
else if(OPERATOR\_CHARS.indexOf(current) != -1) {  
tokenizeOperator();  
} else{  
next();  
}  
}  
return tokens;  
}

private void tokenizeNumber(){  
final StringBuilder buffer = new StringBuilder();  
char current = peek();  
while(Character.isDigit(current)){  
buffer.append(current);  
current = next();  
}  
addToken(TokenType.NUMBER, buffer.toString());  
}

private void tokenizeOperator(){  
final int position = OPERATOR.CHARS.indexOf(peek(0));  
addToken(OPERATOR\_TOKENS[position]);  
next();  
}

private char next(){  
pos++;  
return peek(0);  
}

private char peek(int relativePosition){  
final int position = pos + relativePosition;  
if(position \>= length) return ‘/0’;  
return input.charAt(position);  
}

private void addToken(TokenType type){  
addToken(type, “”);  
}

private void addToken(TokenType type, String text){  
tokens.add(new Token(type, text));  
}

}

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 30, 2023, 11:34am UTC](https://discourse.processing.org/t/error-in-code-processing/40742/2 "2023-01-30T11:34:52Z")

</div>

> [@OverLord](#):
>
> return ‘/0’;

`return '0'; // or null`

**Full class**

```auto

class Lexer {
  private static final String OPERATORS_CHARS = "±*/";
  private static final TokenType OPERATOR_TOKENS ={
    TokenType.PLUS, TokenType.MINUS,
    TokenType.STAR, TokenType.SLASH,
  };
  private final String input;
  private final int length;
  private final List tokens;
  private int pos;

  public Lexer(String input) {
    this.input = input;
    length = input.length();

    tokens = new ArrayList<>();
  }

  public List tokenize() {
    while (pos < length) {
      final char current = peek();
      if (Character.isDigit(current)) tokenizeNumber();
      else if (OPERATOR_CHARS.indexOf(current) != -1) {
        tokenizeOperator();
      } else {
        next();
      }
    }
    return tokens;
  }

  private void tokenizeNumber() {
    final StringBuilder buffer = new StringBuilder();
    char current = peek();
    while (Character.isDigit(current)) {
      buffer.append(current);
      current = next();
    }
    addToken(TokenType.NUMBER, buffer.toString());
  }

  private void tokenizeOperator() {
    final int position = OPERATOR.CHARS.indexOf(peek(0));
    addToken(OPERATOR_TOKENS[position]);
    next();
  }

  private char next() {
    pos++;
    return peek(0);
  }

  private char peek(int relativePosition) {
    final int position = pos + relativePosition;
    if (position >= length)
      return '0'; // or null
    return input.charAt(position);
  }

  private void addToken(TokenType type) {
    addToken(type, "");
  }

  private void addToken(TokenType type, String text) {
    tokens.add(new Token(type, text));
  }
}

```
