/**
 * Starter file for Lexical Analysis
 * intent is to demonstrate a method for tracking file position and line number
 */
import java.util.Vector;
import java.io.RandomAccessFile;
import java.io.FileNotFoundException;
import java.io.IOException;

public class LexScan {

	public static void main(String[] args) {
		RandomAccessFile in = null;
		long position = 0;
		int lineCount = 0;
        String line;
        Vector <String> sourceCode = new Vector<String>();
        
        try {//open file
			in = new RandomAccessFile("src/LexScan.java","r");
		} catch (FileNotFoundException e) {
			System.out.println("unable to open file");
			e.printStackTrace();
		}
        try {//read a line
        	while (true) {
				position = in.getFilePointer();
				if ((line = in.readLine()) == null) 
					break;
				lineCount++;
				sourceCode.add("fp:"+position+"\tline#"+lineCount+"\tlen="+line.length()+"\t"+line);
        	}
		} catch (IOException e) {
			System.out.println("unable to read line");
			e.printStackTrace();
		}
		try {
			in.close();
		} catch (IOException e) {
			System.out.println("unable to close");
			e.printStackTrace();
		}
		//echo a line
		for (String text : sourceCode ){
			System.out.println(text);
		}
		
    }
}
