Results 1 to 7 of 7
  1. #1
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Write-driven lexer?

    I want to use a write-driven lexer. Meaning, instead of giving a lexer a Reader and telling it to read, I want to write to the lexer and have it perform its actions on any tokens it matches, buffering any leftover characters to concatenate and lex along with the next write.

    Before I attempt to make JFlex do this by hacking its skeleton file... is there any lexer generator out there that already works this way?
    Get in the habit of using standard Java naming conventions!

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    JFlex or JLex.

    JLex gives you a best description about the analysis. May not exactly the same, but able to customize it accordingly.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,771
    Blog Entries
    7
    Rep Power
    21

    Default

    The first things that came to my mind are the PipedInputStream and its compadre PipedOutputStream.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default

    Jos - that's how I'm using JFlex now. But I want the input to be parsed immediately, not at the whim of the thread scheduler. (Yes, I'm optimizing prematurely. Partly out of hackish curiosity.)

    Eranga - Wait, can JFlex already do this?
    Get in the habit of using standard Java naming conventions!

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,771
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by kjkrum View Post
    Jos - that's how I'm using JFlex now. But I want the input to be parsed immediately, not at the whim of the thread scheduler. (Yes, I'm optimizing prematurely. Partly out of hackish curiosity.)
    Normally a Reader blocks when it has to read and there is nothing to read; so does the PipedInputStream; it is woken up immediately when the PipedOutputStream has written some data. When there are not many Threads running the scheduler won't be much of a PITA. Why do you think it'll be too slow for your needs? The alternative is to dissect your lexical analyzer which will be more of a PITA imho. Flushing the OutputStream might help too ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default

    Well, I'm reading from one socket, and writing to another socket. I want to guarantee that the lexer has seen the data before I write it to the other socket.

    I suppose I could have the lexer's actions write each token they've matched to a buffer, but then the problem becomes when to copy the buffer and flush the output stream.
    Get in the habit of using standard Java naming conventions!

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,771
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by kjkrum View Post
    Well, I'm reading from one socket, and writing to another socket. I want to guarantee that the lexer has seen the data before I write it to the other socket.

    I suppose I could have the lexer's actions write each token they've matched to a buffer, but then the problem becomes when to copy the buffer and flush the output stream.
    Sockets ... you have other things to worry about, e.g. Nagle's algorithm can cause a considerable transmission latency (turn it off) or your connection over the wire could be just bad, causing a lot of retransmissions.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Problem with menu-driven program
    By t0nydanzuh in forum New To Java
    Replies: 14
    Last Post: 09-30-2010, 10:43 PM
  2. Menu-driven console help please
    By floppyspace in forum New To Java
    Replies: 4
    Last Post: 03-12-2010, 05:12 PM
  3. how to create menu-driven programs?
    By princess.blue in forum Eclipse
    Replies: 0
    Last Post: 12-07-2009, 09:01 AM
  4. message driven beans
    By rob in forum Java Servlet
    Replies: 0
    Last Post: 03-12-2009, 09:01 PM
  5. Menu driven system - atm
    By thelinuxguy in forum Advanced Java
    Replies: 1
    Last Post: 02-19-2009, 12:14 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
  •