Package xscript.compiler.standart

Source Code of xscript.compiler.standart.XLexer

package xscript.compiler.standart;

import java.util.ArrayList;
import java.util.List;

import xscript.compiler.XMessageList;
import xscript.compiler.XToken;
import xscript.compiler.XTokenParser;

public class XLexer {

  private XTokenParser parser;
  private List<XToken> tokens;
  private int i;
  private boolean read;
 
  public XLexer(String source, XMessageList messages){
    parser = new XTokenParser(source, messages);
  }
 
  public XToken getNextToken(){
    if(read && tokens!=null){
      if(tokens.isEmpty()){
        tokens = null;
      }else{
        XToken token = tokens.remove(0);
        if(tokens.isEmpty())
          tokens = null;
        return token;
      }
    }
    if(!read && tokens!=null && tokens.size()>i){
      return tokens.get(i++);
    }
    XToken token = parser.readNextToken();
    if(!read && tokens!=null){
      tokens.add(token);
    }
    return token;
  }
 
  public void notSure(){
    if(tokens==null)
      tokens = new ArrayList<XToken>();
    read = false;
    i=0;
  }
 
  public void sure(){
    tokens = null;
  }
 
  public void reset(){
    read = true;
  }
 
}
TOP

Related Classes of xscript.compiler.standart.XLexer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.