المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : 11Those Who Are Expert in JAVA.



HASSON_ME
18-03-2005, 04:34 PM
السلام عليكم


Hi, if you are expert in java or you have enough idea about java please share some of you knowladge.

i an assignment where we have to develop a parser for PHP .
So, i'm doing that parser in Java. the thing i need is that ,
HOW TO GET A CONSUOL INPUT FROM THE USER at run TIME ?
i mean that , i must take character by character from the user and identify each when ever we get input until the semicolom accures,
MORE: i need a function or a way to do the work of the function (getch()) of c++
but in java.

Please if you have an idea share it with me , if you don't please replay that you don't , cuz i have to check weither i wait :28: for answer or switch to:33: some other language than JAVA.

Thanx for caring:icon6: .
Mashkoooreen 3al ehtmaaam , yezaakom alla '7eer :08:

YOUR Bro. HassoN:reporter:

ibn_alqalam
18-03-2005, 05:12 PM
There are many ways, depending on where you want the input to come from. Rememer, java can be either an application (GUI, CLI) or applet. What form is your "php parser" in?

There are TONS of I/O functions in the java.io.* package heirarchy. Your lexer will probably need to look-ahead tokens, so you might need to use the methods in the java.io.BufferedReader. If you're not reading from a file, but instead waiting for user input at the console (the user is typing the php code directly into the application shell) then you can use classes and methods in System.in.*, like:

System.in.read (); /* read next byte*/
System.in.read (byte[] n) /* read next n bytes */

Though you might have to do your own buffering, and implement puting back tokens (ala ungetc ());

http://java.sun.com/j2se/1.5.0/docs/api/java/io/InputStream.html

ibn_alqalam
18-03-2005, 05:17 PM
http://leepoint.net/notes-java/41io/15console/10console.html

This guy has a sample class.

HASSON_ME
18-03-2005, 05:26 PM
MshKooor Brother for the reply,

But the thing is i don't want to get the string of input , just i need to get character by character ,
e.g.
i/p= hassan
i have to verify from the first character weither its right input or not , if not alert will be givent that first character can't be numeric for the identifier and complete the input of the identifier if it was alphabet right accourding to the language constraints.

actually our teacher are not giving the marks if just submit the assignment with whole requirments but they are giving according to the level of the class , it means if any one in the class did it perfectly the rest will get 5/10 or less :boggled:

so i mean that just assume that you are constructing this part for a compiler.

Thanx alot Bro.
Your Bro. HasSoN

HASSON_ME
18-03-2005, 05:35 PM
mmmmmm, so if u have any English Forum related to java , where i can ask .


the question is not about simply getting input or output
cuz i think you didn't understand my question.

anaywayz i'm so thanksful for your aswers :)

ibn_alqalam
18-03-2005, 06:10 PM
System.in.read ();



Notice no argument there. It reads and returns the next input byte.




System.in.read (byte [] n);



reads n number of bytes into the buffer (i.e. similar to gets ())

It's all in the first link above; get ready to spend a substantial part of your life browsing the java documentation :-D hehehehe