Stack Exchange
log in
users (34)
rooms (27)
faq
Spencer Rathbun
general
recent
conversations
Room for maple_shaft and Spencer Rathbun
Spencer Rathbun
Jan 27, 2012 16:30
K
Spencer Rathbun
Jan 27, 2012 16:29
I'll stick around if you've got more questions, but it's back to the grind right now
Spencer Rathbun
Jan 27, 2012 16:29
No problem,
Spencer Rathbun
Jan 27, 2012 16:28
The example source is free for download, and has a great example of a simple c parser.
Spencer Rathbun
Jan 27, 2012 16:27
The best book ever written on the topic is
shop.oreilly.com/product/9781565920002.do
Spencer Rathbun
Jan 27, 2012 16:26
Totally possible.
Spencer Rathbun
Jan 27, 2012 16:24
With the right tool, you can have arbitrary commands associated with each state. So yes, a regex can be used within a state.
Spencer Rathbun
Jan 27, 2012 16:24
This is an example from the flex manual for eating all input:
flex.sourceforge.net/manual/…
Spencer Rathbun
Jan 27, 2012 16:23
Otherwise, it waits in the "just right" state for more input
Spencer Rathbun
Jan 27, 2012 16:22
If it is not correct, an error is created and the machine goes back to the ready state.
Spencer Rathbun
Jan 27, 2012 16:22
just right
Spencer Rathbun
Jan 27, 2012 16:22
too many coins
Spencer Rathbun
Jan 27, 2012 16:22
Not enough coins
Spencer Rathbun
Jan 27, 2012 16:22
So if I put some coins in the pop machine, then it matches them to:
Spencer Rathbun
Jan 27, 2012 16:20
Exactly like that.
Spencer Rathbun
Jan 27, 2012 16:20
That moves it to another state, where an arbitrary action can be performed.
Spencer Rathbun
Jan 27, 2012 16:20
Upon receiving input, it sees what "rule" the input matches, if any.
Spencer Rathbun
Jan 27, 2012 16:19
It sits in a "ready" state, waiting for input
Spencer Rathbun
Jan 27, 2012 16:19
A state machine is like a pop dispenser
Spencer Rathbun
Jan 27, 2012 16:18
So each regex becomes simple as it only has to match some specific item from the text stream.
Spencer Rathbun
Jan 27, 2012 16:17
That is,
input
->
select
->
sql
->
ending flag
->
back to input stat
Spencer Rathbun
Jan 27, 2012 16:17
Because what you really want is a state machine.
Spencer Rathbun
Jan 27, 2012 16:16
I've found that lots of people try and do a parser's job with JUST regex
Spencer Rathbun
Jan 27, 2012 16:16
No problem
Spencer Rathbun
Jan 27, 2012 16:15
The python was just a suggestion for fast turn around.
The Whiteboard
General Discussion for
softwareengineering.stackexchange.com
P...
Spencer Rathbun
Jan 27, 2012 16:15
Heya