[[tokens]]
 
package forge;
 
import java.io.*;
import java.nio.file.*;
import java.util.*;
 
public class Window extends javax.swing.JFrame {
 
    private String data;
 
    private int pos;
    private int len;
    private char ch;
    private String token;
 
    private void open (String s)
    {
        data = s;
        pos = 0;
        len = data.length ();
 
        nextChar ();
        nextToken ();
    }
 
    public final char eos = 0;
 
    private void nextChar ()
    {
        if (pos >= len)
            ch = eos;
        else 
            ch = data.charAt (pos);
        pos ++;
    }
 
    private void nextToken ()
    {
        token = "";
 
        while (ch != eos && ch <= ' ')
            nextChar ();
 
        // if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z')
        if (Character.isAlphabetic (ch))
        {
            while (Character.isAlphabetic(ch) || Character.isDigit(ch) || ch == '_')
            {
                token += ch;
                nextChar ();
            }
        }
 
        else if (Character.isDigit(ch))
        {
            while (Character.isDigit(ch))
            {
                token += ch;
                nextChar ();
            }
        }
 
        else token = Character.toString (ch);
    }
 
    private void readFile (String filename)    
    {
        try 
        {
            StringBuilder b = new StringBuilder ();
 
            FileReader f = new FileReader (filename);
            BufferedReader r = new BufferedReader (f);
            String line = r.readLine();
            while (line != null)
            {
                jTextArea1.append (line + "\n");
                b.append (line + "\n");
                line = r.readLine();
            }
 
            open (b.toString());
        }
        catch (FileNotFoundException ex)  { }
        catch (IOException ex) { }
     }
 
    public Window() {
        initComponents();
 
        readFile ("abc.txt");
 
        /*
        Path path = Paths.get ("C:", "totalcmd", "size!.txt");
        List <String> lines = Files.readAllLines (path);
        for (String line : lines)
            jTextArea1.append(line + "\n");
        */    
    }
 
}
 
tokens.txt · Last modified: 2018/11/23 13:11 by 147.32.8.115
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki