Results 1 to 3 of 3
  1. #1
    Tink2 is offline Member
    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    Default Compile this Program

    Hi there attach are the code:
    [CODE]

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package simpleexample;

    /**
    *
    * @author ASUS
    */
    class SimpleExample {
    public static void main(String argv[]) throws java.io.IOException {
    Yylex yy = new Yylex(System.in);
    Yytoken t;
    while ((t = yy.yylex()) != null)
    System.out.println(t);
    }
    }
    class Yytoken {
    Yytoken (int index, String text)
    {
    m_index = index;
    m_text = new String(text);
    }
    public int m_index;
    public String m_text;
    public String toString() {
    return "Token #"+m_index+": "+m_text;
    }
    }


    class Yylex {
    private final int YY_BUFFER_SIZE = 512;
    private final int YY_F = -1;
    private final int YY_NO_STATE = -1;
    private final int YY_NOT_ACCEPT = 0;
    private final int YY_START = 1;
    private final int YY_END = 2;
    private final int YY_NO_ANCHOR = 4;
    private final int YY_BOL = 128;
    private final int YY_EOF = 129;
    private java.io.BufferedReader yy_reader;
    private int yy_buffer_index;
    private int yy_buffer_read;
    private int yy_buffer_start;
    private int yy_buffer_end;
    private char yy_buffer[];
    private int yyline;
    private boolean yy_at_bol;
    private int yy_lexical_state;

    Yylex (java.io.Reader reader) {
    this ();
    if (null == reader) {
    throw (new Error("Error: Bad input stream initializer."));
    }
    yy_reader = new java.io.BufferedReader(reader);
    }

    Yylex (java.io.InputStream instream) {
    this ();
    if (null == instream) {
    throw (new Error("Error: Bad input stream initializer."));
    }
    yy_reader = new java.io.BufferedReader(new java.io.InputStreamReader(instream));
    }

    private Yylex () {
    yy_buffer = new char[YY_BUFFER_SIZE];
    yy_buffer_read = 0;
    yy_buffer_index = 0;
    yy_buffer_start = 0;
    yy_buffer_end = 0;
    yyline = 0;
    yy_at_bol = true;
    yy_lexical_state = YYINITIAL;
    }

    private boolean yy_eof_done = false;
    private final int YYINITIAL = 0;
    private final int yy_state_dtrans[] = {
    0
    };
    private void yybegin (int state) {
    yy_lexical_state = state;
    }
    private int yy_advance ()
    throws java.io.IOException {
    int next_read;
    int i;
    int j;

    if (yy_buffer_index < yy_buffer_read) {
    return yy_buffer[yy_buffer_index++];
    }

    if (0 != yy_buffer_start) {
    i = yy_buffer_start;
    j = 0;
    while (i < yy_buffer_read) {
    yy_buffer[j] = yy_buffer[i];
    ++i;
    ++j;
    }
    yy_buffer_end = yy_buffer_end - yy_buffer_start;
    yy_buffer_start = 0;
    yy_buffer_read = j;
    yy_buffer_index = j;
    next_read = yy_reader.read(yy_buffer,
    yy_buffer_read,
    yy_buffer.length - yy_buffer_read);
    if (-1 == next_read) {
    return YY_EOF;
    }
    yy_buffer_read = yy_buffer_read + next_read;
    }

    while (yy_buffer_index >= yy_buffer_read) {
    if (yy_buffer_index >= yy_buffer.length) {
    yy_buffer = yy_double(yy_buffer);
    }
    next_read = yy_reader.read(yy_buffer,
    yy_buffer_read,
    yy_buffer.length - yy_buffer_read);
    if (-1 == next_read) {
    return YY_EOF;
    }
    yy_buffer_read = yy_buffer_read + next_read;
    }
    return yy_buffer[yy_buffer_index++];
    }
    private void yy_move_end () {
    if (yy_buffer_end > yy_buffer_start &&
    '\n' == yy_buffer[yy_buffer_end-1])
    yy_buffer_end--;
    if (yy_buffer_end > yy_buffer_start &&
    '\r' == yy_buffer[yy_buffer_end-1])
    yy_buffer_end--;
    }
    private boolean yy_last_was_cr=false;
    private void yy_mark_start () {
    int i;
    for (i = yy_buffer_start; i < yy_buffer_index; ++i) {
    if ('\n' == yy_buffer[i] && !yy_last_was_cr) {
    ++yyline;
    }
    if ('\r' == yy_buffer[i]) {
    ++yyline;
    yy_last_was_cr=true;
    } else yy_last_was_cr=false;
    }
    yy_buffer_start = yy_buffer_index;
    }
    private void yy_mark_end () {
    yy_buffer_end = yy_buffer_index;
    }
    private void yy_to_mark () {
    yy_buffer_index = yy_buffer_end;
    yy_at_bol = (yy_buffer_end > yy_buffer_start) &&
    ('\r' == yy_buffer[yy_buffer_end-1] ||
    '\n' == yy_buffer[yy_buffer_end-1] ||
    2028/*LS*/ == yy_buffer[yy_buffer_end-1] ||
    2029/*PS*/ == yy_buffer[yy_buffer_end-1]);
    }
    private java.lang.String yytext () {
    return (new java.lang.String(yy_buffer,
    yy_buffer_start,
    yy_buffer_end - yy_buffer_start));
    }
    private int yylength () {
    return yy_buffer_end - yy_buffer_start;
    }
    private char[] yy_double (char buf[]) {
    int i;
    char newbuf[];
    newbuf = new char[2*buf.length];
    for (i = 0; i < buf.length; ++i) {
    newbuf[i] = buf[i];
    }
    return newbuf;
    }
    private final int YY_E_INTERNAL = 0;
    private final int YY_E_MATCH = 1;
    private java.lang.String yy_error_string[] = {
    "Error: Internal error.\n",
    "Error: Unmatched input.\n"
    };
    private void yy_error (int code,boolean fatal) {
    java.lang.System.out.print(yy_error_string
    Java Code:
    );
    		java.lang.System.out.flush();
    		if (fatal) {
    			throw new Error("Fatal Error.\n");
    		}
    	}
    	private int[][] unpackFromString(int size1, int size2, String st) {
    		int colonIndex = -1;
    		String lengthString;
    		int sequenceLength = 0;
    		int sequenceInteger = 0;
    
    		int commaIndex;
    		String workString;
    
    		int res[][] = new int[size1][size2];
    		for (int i= 0; i < size1; i++) {
    			for (int j= 0; j < size2; j++) {
    				if (sequenceLength != 0) {
    					res[i][j] = sequenceInteger;
    					sequenceLength--;
    					continue;
    				}
    				commaIndex = st.indexOf(',');
    				workString = (commaIndex==-1) ? st :
    					st.substring(0, commaIndex);
    				st = st.substring(commaIndex+1);
    				colonIndex = workString.indexOf(':');
    				if (colonIndex == -1) {
    					res[i][j]=Integer.parseInt(workString);
    					continue;
    				}
    				lengthString =
    					workString.substring(colonIndex+1);
    				sequenceLength=Integer.parseInt(lengthString);
    				workString=workString.substring(0,colonIndex);
    				sequenceInteger=Integer.parseInt(workString);
    				res[i][j] = sequenceInteger;
    				sequenceLength--;
    			}
    		}
    		return res;
    	}
    	private int yy_acpt[] = {
    		/* 0 */ YY_NOT_ACCEPT,
    		/* 1 */ YY_NO_ANCHOR,
    		/* 2 */ YY_NO_ANCHOR,
    		/* 3 */ YY_NO_ANCHOR,
    		/* 4 */ YY_NO_ANCHOR,
    		/* 5 */ YY_NO_ANCHOR,
    		/* 6 */ YY_NO_ANCHOR,
    		/* 7 */ YY_NO_ANCHOR
    	};
    	private int yy_cmap[] = unpackFromString(1,130,
    "6:9,5:2,6,5:2,6:18,5,6:10,1,6:4,3:10,6,2,6:5,4:26,6:6,4:26,6:5,0:2")[0];
    
    	private int yy_rmap[] = unpackFromString(1,8,
    "0,1:3,2,3,1:2")[0];
    
    	private int yy_nxt[][] = unpackFromString(4,7,
    "1,2,3,4,5,6,7,-1:10,4,-1:7,5,-1:2");
    
    	public Yytoken yylex ()
    		throws java.io.IOException {
    		int yy_lookahead;
    		int yy_anchor = YY_NO_ANCHOR;
    		int yy_state = yy_state_dtrans[yy_lexical_state];
    		int yy_next_state = YY_NO_STATE;
    		int yy_last_accept_state = YY_NO_STATE;
    		boolean yy_initial = true;
    		int yy_this_accept;
    
    		yy_mark_start();
    		yy_this_accept = yy_acpt[yy_state];
    		if (YY_NOT_ACCEPT != yy_this_accept) {
    			yy_last_accept_state = yy_state;
    			yy_mark_end();
    		}
    		while (true) {
    			if (yy_initial && yy_at_bol) yy_lookahead = YY_BOL;
    			else yy_lookahead = yy_advance();
    			yy_next_state = YY_F;
    			yy_next_state = yy_nxt[yy_rmap[yy_state]][yy_cmap[yy_lookahead]];
    			if (YY_EOF == yy_lookahead && true == yy_initial) {
    				return null;
    			}
    			if (YY_F != yy_next_state) {
    				yy_state = yy_next_state;
    				yy_initial = false;
    				yy_this_accept = yy_acpt[yy_state];
    				if (YY_NOT_ACCEPT != yy_this_accept) {
    					yy_last_accept_state = yy_state;
    					yy_mark_end();
    				}
    			}
    			else {
    				if (YY_NO_STATE == yy_last_accept_state) {
    					throw (new Error("Lexical Error: Unmatched Input."));
    				}
    				else {
    					yy_anchor = yy_acpt[yy_last_accept_state];
    					if (0 != (YY_END & yy_anchor)) {
    						yy_move_end();
    					}
    					yy_to_mark();
    					switch (yy_last_accept_state) {
    					case 1:
    						
    					case -2:
    						break;
    					case 2:
    						{return new Yytoken(1,"+");}
    					case -3:
    						break;
    					case 3:
    						{return new Yytoken(2,";");}
    					case -4:
    						break;
    					case 4:
    						{return new Yytoken(3, new String(yytext()));}
    					case -5:
    						break;
    					case 5:
    						{return new Yytoken(4, new String(yytext()));}
    					case -6:
    						break;
    					case 6:
    						{ /* ignore white space. */ }
    					case -7:
    						break;
    					case 7:
    						{ System.err.println("Illegal Character: "+yytext()+" at line "+yyline);}
    					case -8:
    						break;
    					default:
    						yy_error(YY_E_INTERNAL,false);
    					case -1:
    					}
    					yy_initial = true;
    					yy_state = yy_state_dtrans[yy_lexical_state];
    					yy_next_state = YY_NO_STATE;
    					yy_last_accept_state = YY_NO_STATE;
    					yy_mark_start();
    					yy_this_accept = yy_acpt[yy_state];
    					if (YY_NOT_ACCEPT != yy_this_accept) {
    						yy_last_accept_state = yy_state;
    						yy_mark_end();
    					}
    				}
    			}
    		}
    	}
    }
    and in txt filethat serves as an argument to the program above is:
    y = 2 + x

    Question is how do you compile the txt file and the source file.
    I have tried compiling via command: javac SimpleExample.java
    no error but when I do java SimpleExample input.txt
    the following error(s) occur:
    Microsoft Windows [Version 6.2.9200]
    (c) 2012 Microsoft Corporation. All rights reserved.


    C:\Users\ASUS\Documents\NetBeansProjects\SimpleExa mple\src\simpleexample>java Si
    mpleExample input.txt
    Exception in thread "main" java.lang.NoClassDefFoundError: SimpleExample (wrong
    name: simpleexample/SimpleExample)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unkno wn Source)

    C:\Users\ASUS\Documents\NetBeansProjects\SimpleExa mple\src\simpleexample>

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,942
    Rep Power
    19

    Default Re: Compile this Program

    I think you've mucked up the code tags there somewhere.

    Anyway, your class is not called SimpleExample.
    It's full name is simpleexample.SimpleExample.
    You have to include the package name.
    And if it has a package name then you need to ensure it is located in a directory with the same name as the package.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Tink2 is offline Member
    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    Default Re: Compile this Program

    Quote Originally Posted by Tolls View Post
    I think you've mucked up the code tags there somewhere.

    Anyway, your class is not called SimpleExample.
    It's full name is simpleexample.SimpleExample.
    You have to include the package name.
    And if it has a package name then you need to ensure it is located in a directory with the same name as the package.

    Thank you, it works=)

Similar Threads

  1. compile my program
    By suriyababu in forum New To Java
    Replies: 10
    Last Post: 01-31-2013, 12:18 PM
  2. compile my program
    By suriyababu in forum New To Java
    Replies: 1
    Last Post: 01-30-2013, 02:42 PM
  3. Program will not compile?
    By vtecjerry in forum New To Java
    Replies: 1
    Last Post: 09-29-2010, 10:20 PM
  4. my program cannot be compile
    By justlynn in forum NetBeans
    Replies: 8
    Last Post: 08-17-2010, 10:11 AM
  5. Compile a program
    By toby in forum New To Java
    Replies: 2
    Last Post: 07-30-2007, 09:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •