Live data from Hacker News

Ragel State Machine Compiler

colm.net

1–10 of 22 posts

Re: Ragel State Machine Compiler

#3
post #2

How is this different from Lex, written in 1975? Even the syntax looks fairly similar. https://en.wikipedia.org/wiki/Lex_(software)

Ragel allows embedding actions into the subexpressions of a regular expression. This allows one to compose a parser using a single regular expression.

Re: Ragel State Machine Compiler

#5
post #3
post #2

How is this different from Lex, written in 1975? Even the syntax looks fairly similar. https://en.wikipedia.org/wiki/Lex_(software)

Ragel allows embedding actions into the subexpressions of a regular expression. This allows one to compose a parser using a single regular expression.

To add some color: Without much difficulty I was able to build a small POP3 server by describing the protocol as a Ragel grammar with the verbs implemented as semantic actions (a small amount of Go). It reads very nicely compared to a hand-built version of the same thing. The only real downside I found was that it was hard to tell what's wrong when your grammar isn't behaving as expected but no worse than other parser generators I've used.

Re: Ragel State Machine Compiler

#6
post #3
post #2

How is this different from Lex, written in 1975? Even the syntax looks fairly similar. https://en.wikipedia.org/wiki/Lex_(software)

Ragel allows embedding actions into the subexpressions of a regular expression. This allows one to compose a parser using a single regular expression.

Why would you want to do that?

Re: Ragel State Machine Compiler

#7
post #3

Earlier quoted context omitted.

Ragel allows embedding actions into the subexpressions of a regular expression. This allows one to compose a parser using a single regular expression.

Why would you want to do that?

There are a lot of advantages to a declarative approach, and a lot of risks and problems with hand written parsers and state machines.

A good example is the http code Zed wrote with ragel. From what I remember it was contracted by verisign because they wanted an implementation that actually followed the spec in detail, unlike all other code available at the time. That ragel code has been reused by a lot of embedded http servers in many languages now.

Re: Ragel State Machine Compiler

#8
post #3

Earlier quoted context omitted.

Ragel allows embedding actions into the subexpressions of a regular expression. This allows one to compose a parser using a single regular expression.

Why would you want to do that?

Same reason you would want to use yacc to write a parser. A grammar annotated with code is a nice way to express a parser. If the language happens to be regular, you can use ragel to generate a directly executable deterministic state machine. The code is simple and fast.
Post reply on HN