Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > finite state automaton

Reply
Thread Tools

finite state automaton

 
 
Roedy Green
Guest
Posts: n/a
 
      12-23-2005
Consider a simple finite state automaton to parse property files.

They look like this:
# a comment
keyword=value

I want to categorise each fragment of text as either comment, keyword
or value. Now throw in a complication. Inside any of those three
things might be literals of the form \uffff

I find myself creating all kinds of rinky dink mechanisms to handle
the literals. I wondered if there is a clean way to do it.

There are two problems.


1) It is clumsy to invent three literal states one for in comment, one
inkeyword and one invalue just so it can remember what it was doing.
Yet whole idea of a finite state automaton in that the memory of the
system is supposed to be encapsulated in the state.

2) you leave the literal state based on a count, not the presence of
some delimiter. I could create 5 states to mark progress down the
literal, but this seems a bit nuts.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
 
 
 
Raymond DeCampo
Guest
Posts: n/a
 
      12-31-2005
Roedy Green wrote:
> Consider a simple finite state automaton to parse property files.
>
> They look like this:
> # a comment
> keyword=value
>
> I want to categorise each fragment of text as either comment, keyword
> or value. Now throw in a complication. Inside any of those three
> things might be literals of the form \uffff
>
> I find myself creating all kinds of rinky dink mechanisms to handle
> the literals. I wondered if there is a clean way to do it.
>
> There are two problems.
>
>
> 1) It is clumsy to invent three literal states one for in comment, one
> inkeyword and one invalue just so it can remember what it was doing.
> Yet whole idea of a finite state automaton in that the memory of the
> system is supposed to be encapsulated in the state.
>
> 2) you leave the literal state based on a count, not the presence of
> some delimiter. I could create 5 states to mark progress down the
> literal, but this seems a bit nuts.


Roedy,

Why not run the property file through a pre-processor to handle escape
sequences, similar to what javac does? After all, the standard property
file format supports \\ and \ followed by a line break for line
continuation and who knows what else....

HTH,
Ray

--
XML is the programmer's duct tape.
 
Reply With Quote
 
 
 
 
Stefan Ram
Guest
Posts: n/a
 
      12-31-2005
Raymond DeCampo <(E-Mail Removed)> writes:
>Why not run the property file through a pre-processor to handle
>escape sequences, similar to what javac does?


You mean a preprocessor like

native2ascii -reverse

See

http://download.java.net/jdk6/docs/t...ive2ascii.html
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      12-31-2005
Raymond DeCampo <(E-Mail Removed)> was quoting:
>>I want to categorise each fragment of text as either comment, keyword
>>or value. Now throw in a complication. Inside any of those three
>>things might be literals of the form \uffff
>>I find myself creating all kinds of rinky dink mechanisms to handle
>>the literals. I wondered if there is a clean way to do it.


The clean way is a scanner with two layers:

The first layer converts each \u-Sequence to a code point.

The second layer then reads code points supplied by the first
layer and does not have to care about the \u-sequences
anymore.

 
Reply With Quote
 
Raymond DeCampo
Guest
Posts: n/a
 
      01-01-2006
Stefan Ram wrote:
> Raymond DeCampo <(E-Mail Removed)> was quoting:
>
>>>I want to categorise each fragment of text as either comment, keyword
>>>or value. Now throw in a complication. Inside any of those three
>>>things might be literals of the form \uffff
>>>I find myself creating all kinds of rinky dink mechanisms to handle
>>>the literals. I wondered if there is a clean way to do it.

>
>
> The clean way is a scanner with two layers:
>
> The first layer converts each \u-Sequence to a code point.
>
> The second layer then reads code points supplied by the first
> layer and does not have to care about the \u-sequences
> anymore.
>


Gee, thanks for replying to my post, removing my contribution, removing
the OP's name making it seem as if I wrote what the OP did to the casual
observer, and then re-stating my idea. That was really helpful.

Ray

--
XML is the programmer's duct tape.
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      01-01-2006
Roedy Green <(E-Mail Removed) >
might have written, quoted or indirectly quoted something like:
>I want to categorise each fragment of text as either comment, keyword
>or value. Now throw in a complication. Inside any of those three
>things might be literals of the form \uffff
>I find myself creating all kinds of rinky dink mechanisms to handle
>the literals. I wondered if there is a clean way to do it.


The clean way is a scanner with two layers:

The first layer converts each \u-Sequence to a code point.

The second layer then reads code points supplied by the first
layer and does not have to care about the \u-sequences
anymore.

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-02-2006
On Sat, 31 Dec 2005 20:46:42 GMT, Raymond DeCampo
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone who
said :

>Why not run the property file through a pre-processor to handle escape
>sequences, similar to what javac does? After all, the standard property
>file format supports \\ and \ followed by a line break for line
>continuation and who knows what else....


I considered that, but I wanted to display the file literally. If the
file contained embedded \uxxx characters in binary, I wanted to
display them differently from ones properly encoded with \uxxxx

I have since solved the problem with kludge, a lookahead that handles
the entire sequence as if it were a single char from the overall state
machine point of view.

You can see it working at http://mindprod.com/jgloss/properties.html


--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Very simple finite automaton (?) kpp9c Python 6 09-23-2009 03:56 PM
Safe finite state machine design SomeDude VHDL 3 08-14-2006 12:47 PM
Does Perl combine multiple REs into a single automaton? Clint Olsen Perl Misc 2 06-29-2004 04:57 PM
How to implement linked Finite State Machines Sidney Cadot VHDL 0 04-18-2004 10:45 AM
HELP PLEASE!! - Finite State Machine - Automaton - Microprogrammed System deejayfred VHDL 0 10-02-2003 01:23 AM



Advertisments