// Path: src/com/equadon/intellij/mips/MipsException.java
// public class MipsException extends Exception {
//   public MipsException(String text) {
//     super(text);
//   }
// }
// 
// Path: src/com/equadon/intellij/mips/lang/psi/MipsElementType.java
// public class MipsElementType extends IElementType {
//   public MipsElementType(@NotNull String debug) {
//     super(debug, MipsLanguage.INSTANCE);
//   }
// 
//   public static IElementType fromToken(@NotNull Token token) throws MipsException {
//     TokenTypes type = token.getType();
// 
//     if (type.equals(TokenTypes.COLON))
//       return MipsElementTypes.COLON;
//     if (type.equals(TokenTypes.COMMENT))
//       return MipsTokenTypes.COMMENT;
//     if (type.equals(TokenTypes.DELIMITER))
//       return TokenType.WHITE_SPACE;
//     if (type.equals(TokenTypes.DIRECTIVE))
//       return MipsElementTypes.DIRECTIVE;
// //    if (type.equals(TokenTypes.EOL))
// //      return MipsElementTypes.EOL;
//     if (type.equals(TokenTypes.ERROR))
//       return TokenType.BAD_CHARACTER;
//     if (type.equals(TokenTypes.IDENTIFIER))
//       return MipsElementTypes.IDENTIFIER;
//     if (type.equals(TokenTypes.INTEGER_5))
//       return MipsElementTypes.INTEGER_5;
//     if (type.equals(TokenTypes.INTEGER_16))
//       return MipsElementTypes.INTEGER_16;
//     if (type.equals(TokenTypes.INTEGER_16U))
//       return MipsElementTypes.INTEGER_16U;
//     if (type.equals(TokenTypes.INTEGER_32))
//       return MipsElementTypes.INTEGER_32;
//     if (type.equals(TokenTypes.LEFT_PAREN))
//       return MipsElementTypes.LPAREN;
//     if (type.equals(TokenTypes.MINUS))
//       return MipsElementTypes.MINUS;
//     if (type.equals(TokenTypes.OPERATOR))
//       return MipsElementTypes.OPERATOR;
//     if (type.equals(TokenTypes.PLUS))
//       return MipsElementTypes.PLUS;
//     if (type.equals(TokenTypes.QUOTED_STRING))
//       return MipsElementTypes.QUOTED_STRING;
//     if (type.equals(TokenTypes.REAL_NUMBER))
//       return MipsElementTypes.REAL_NUMBER;
//     if (type.equals(TokenTypes.REGISTER_NAME))
//       return MipsElementTypes.REGISTER_NAME;
//     if (type.equals(TokenTypes.REGISTER_NUMBER))
//       return MipsElementTypes.REGISTER_NUMBER;
//     if (type.equals(TokenTypes.RIGHT_PAREN))
//       return MipsElementTypes.RPAREN;
// 
//     throw new MipsException("Unknown token type: " + type);
//   }
// }


import mars.ErrorList;
import mars.ErrorMessage;
import mars.ProcessingException;
import mars.assembler.SourceLine;
import mars.assembler.Token;
import mars.assembler.TokenList;
import com.equadon.intellij.mips.MipsException;
import com.equadon.intellij.mips.lang.psi.MipsElementType;
import com.equadon.intellij.mips.mars.old.MipsProgram;
import com.intellij.lexer.LexerBase;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;

  @Override
  public void advance() {
    if (tokenStart >= bufferEnd || tokens.isEmpty()) {
//      System.out.println("LEXER: end of file");

      tokenType = null;
      tokenStart = bufferEnd;
      tokenEnd = bufferEnd;
      prevIndex = bufferEnd;
      eof = true;
      return;
    }

    Token token = tokens.pop();
    try {
      tokenType = MipsElementType.fromToken(token);

      tokenStart = lineIndexes.get(token.getOriginalSourceLine() - 1) + token.getStartPos() - 1;
      String value = token.getValue();
      tokenEnd = tokenStart + value.length();

//      System.out.println("LEXER: Token: " + tokenType + " (index=" + (tokenStart == tokenEnd ? tokenStart : tokenStart + ".." + tokenEnd) + "): \"" + buffer.subSequence(tokenStart, tokenEnd).toString().replace("\n", "\\n").replace("\t", "\\t") + "\"");

      if (prevIndex != tokenStart) {
        System.out.println("WARNING: gap found at " + prevIndex);
        throw new RuntimeException("gap at " + prevIndex + " to " + tokenStart);
      }

      prevIndex = tokenEnd;
// Path: src/com/equadon/intellij/mips/MipsException.java
// public class MipsException extends Exception {
//   public MipsException(String text) {
//     super(text);
//   }
// }
// 
// Path: src/com/equadon/intellij/mips/lang/psi/MipsElementType.java
// public class MipsElementType extends IElementType {
//   public MipsElementType(@NotNull String debug) {
//     super(debug, MipsLanguage.INSTANCE);
//   }
// 
//   public static IElementType fromToken(@NotNull Token token) throws MipsException {
//     TokenTypes type = token.getType();
// 
//     if (type.equals(TokenTypes.COLON))
//       return MipsElementTypes.COLON;
//     if (type.equals(TokenTypes.COMMENT))
//       return MipsTokenTypes.COMMENT;
//     if (type.equals(TokenTypes.DELIMITER))
//       return TokenType.WHITE_SPACE;
//     if (type.equals(TokenTypes.DIRECTIVE))
//       return MipsElementTypes.DIRECTIVE;
// //    if (type.equals(TokenTypes.EOL))
// //      return MipsElementTypes.EOL;
//     if (type.equals(TokenTypes.ERROR))
//       return TokenType.BAD_CHARACTER;
//     if (type.equals(TokenTypes.IDENTIFIER))
//       return MipsElementTypes.IDENTIFIER;
//     if (type.equals(TokenTypes.INTEGER_5))
//       return MipsElementTypes.INTEGER_5;
//     if (type.equals(TokenTypes.INTEGER_16))
//       return MipsElementTypes.INTEGER_16;
//     if (type.equals(TokenTypes.INTEGER_16U))
//       return MipsElementTypes.INTEGER_16U;
//     if (type.equals(TokenTypes.INTEGER_32))
//       return MipsElementTypes.INTEGER_32;
//     if (type.equals(TokenTypes.LEFT_PAREN))
//       return MipsElementTypes.LPAREN;
//     if (type.equals(TokenTypes.MINUS))
//       return MipsElementTypes.MINUS;
//     if (type.equals(TokenTypes.OPERATOR))
//       return MipsElementTypes.OPERATOR;
//     if (type.equals(TokenTypes.PLUS))
//       return MipsElementTypes.PLUS;
//     if (type.equals(TokenTypes.QUOTED_STRING))
//       return MipsElementTypes.QUOTED_STRING;
//     if (type.equals(TokenTypes.REAL_NUMBER))
//       return MipsElementTypes.REAL_NUMBER;
//     if (type.equals(TokenTypes.REGISTER_NAME))
//       return MipsElementTypes.REGISTER_NAME;
//     if (type.equals(TokenTypes.REGISTER_NUMBER))
//       return MipsElementTypes.REGISTER_NUMBER;
//     if (type.equals(TokenTypes.RIGHT_PAREN))
//       return MipsElementTypes.RPAREN;
// 
//     throw new MipsException("Unknown token type: " + type);
//   }
// }


// Path: src/com/equadon/intellij/mips/mars/lexer/MipsLexer.java
import mars.ErrorList;
import mars.ErrorMessage;
import mars.ProcessingException;
import mars.assembler.SourceLine;
import mars.assembler.Token;
import mars.assembler.TokenList;
import com.equadon.intellij.mips.MipsException;
import com.equadon.intellij.mips.lang.psi.MipsElementType;
import com.equadon.intellij.mips.mars.old.MipsProgram;
import com.intellij.lexer.LexerBase;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;


  @Override
  public void advance() {
    if (tokenStart >= bufferEnd || tokens.isEmpty()) {
//      System.out.println("LEXER: end of file");

      tokenType = null;
      tokenStart = bufferEnd;
      tokenEnd = bufferEnd;
      prevIndex = bufferEnd;
      eof = true;
      return;
    }

    Token token = tokens.pop();
    try {
      tokenType = MipsElementType.fromToken(token);

      tokenStart = lineIndexes.get(token.getOriginalSourceLine() - 1) + token.getStartPos() - 1;
      String value = token.getValue();
      tokenEnd = tokenStart + value.length();

//      System.out.println("LEXER: Token: " + tokenType + " (index=" + (tokenStart == tokenEnd ? tokenStart : tokenStart + ".." + tokenEnd) + "): \"" + buffer.subSequence(tokenStart, tokenEnd).toString().replace("\n", "\\n").replace("\t", "\\t") + "\"");

      if (prevIndex != tokenStart) {
        System.out.println("WARNING: gap found at " + prevIndex);
        throw new RuntimeException("gap at " + prevIndex + " to " + tokenStart);
      }

      prevIndex = tokenEnd;
    } catch (MipsException e) {