/*
 *  Some static methods for ALLL processing
 *
 *  2004 - 2011 Frantisek Zboril jr.
 *  Faculty of Information Technology
 *  zborilf@fit.vutbr.cz
 *  http://www.fit.vutbr.cz/~zborilf
 *
 * (C) Brno University of Technology
 * Freeware licence VUT v Brně
 * https://wis.fit.vutbr.cz/FIT/db/dir.php/dr/VZ2007/externiInformace/softwareNaWebu/Priloha2_rozh23.pdf

 */

package jTMass.core.jALLL;

import jTMass.TMass;
import jTMass.core.jALLL.jTObjects.TAtom;
import jTMass.core.jALLL.jTObjects.TList;
import jTMass.core.jALLL.jTObjects.TObject;
import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.TokenRewriteStream;


public class TALLL {
    
    public static TObject parseALLLData(String content){
        TObject result;
        CharStream stream=new ANTLRStringStream(content);
	ALLLLexer lexer=new ALLLLexer(stream);
	TokenRewriteStream tokenstream=new TokenRewriteStream(lexer);
	ALLLParser parser=new ALLLParser(tokenstream);

        try{
            result=parser.generalList();
            return(result);
        }catch(Exception e){
            TMass._Terminal.reportError("Parse ALLL string");
        }

        return(null);
    }

    public static Integer getNthI(TObject alll, int pos){
        
        TList list;
        if(alll instanceof TList)
            list=(TList)alll;
            else return(null);

        TObject item=list.get(pos);
        Integer result=null;
        if(item instanceof TAtom)
            try{
                result=Integer.parseInt(item.toString());
            }catch (Exception e){
                return(null);}
        
        return(result);
    }

    public static TObject getNthS(TObject alll, int pos){
        // TODO
        return(null);
    }
}
