Javacc Eof problem.

View: New views
3 Messages — Rating Filter:   Alert me  

Javacc Eof problem.

by netchandri :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi There,

I am new to Javacc, please consider.

I am facing problem with EOF for my input stream and I need some assistance for the below problem:
I have a small .jj file with the following code
-------------------------------------------------------
**
 * JavaCC file
 */
 
options {
  JDK_VERSION = "1.5";
}
PARSER_BEGIN(check)
package test1;
import java.io.*;

public class check {
  public static void main(String args[]) throws ParseException {
   BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    check parser = new check(bf);  
    String test = check.event();
    System.out.println("Result:" +test);
  }    
}
PARSER_END(check)

SKIP :
{
        "\r"
| "\t"
| "\n"
}
TOKEN : /* OPERATORS */
{
        < TEXT: "\"" | "(" | ")" | "data.dbxml" >
| < INSERT: "insert" >
| < NODES: "nodes" >
| < TABLE: "Pending" >
| < space : " " >
}
String event()  :
{
Token t;
String i ;
int value ;
}{
t = <INSERT>
{ i = t.image; }
<EOF>
{ System.out.println(i);
        return i ;
}
}
-------------------------------------------------------

When I enter input at the console the console does not exit for the <EOF> tag. For Example for the above program I enter: insert

Now the console just stands there and doesn't provide me with the result. I know I am making a mistake here with the "/r" key as I have allowed the parser to skip this. Now I have no clue how to exit from my user input console. Please help me to understand this.

Thanks.

Re: Javacc Eof problem.

by Artur Rataj :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello.

If you want the parser to exit after <INSERT>, make it simply the last token by deleting <EOF>.

You'll still need to enter \r, so that the console flushes the line buffer.


When I enter input at the console the console does not exit for the <EOF>
tag. For Example for the above program I enter: insert

Now the console just stands there and doesn't provide me with the result. I
know I am making a mistake here with the "/r" key as I have allowed the
parser to skip this. Now I have no clue how to exit from my user input
console. Please help me to understand this.



Re: Javacc Eof problem.

by J.Chris Findlay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Alternatively, press whatever signifies end-of-file on your console,
e.g. under most unix terminals, ctrl-d, or DOS ctrl-z.  This will
close the input stream causing the EOF to fire.

On Mon, Mar 23, 2009 at 9:01 PM, Artur Rataj <arturrataj@...> wrote:

> Hello.
>
> If you want the parser to exit after <INSERT>, make it simply the last token
> by deleting <EOF>.
>
> You'll still need to enter \r, so that the console flushes the line buffer.
>
>>
>> When I enter input at the console the console does not exit for the <EOF>
>> tag. For Example for the above program I enter: insert
>>
>> Now the console just stands there and doesn't provide me with the result.
>> I
>> know I am making a mistake here with the "/r" key as I have allowed the
>> parser to skip this. Now I have no clue how to exit from my user input
>> console. Please help me to understand this.
>>
>
>



--
 - J.Chris Findlay
   (c:

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...