(Mostly) Imperative Packrat Parsing

I’ve been tinkering with monadic parser combinators combined with continuations (see Monads, Mother of All), but my latest toy simplifies all that by using PEG grammars. PEGs and CFGs are nearly interchangable for most parsing of computer languages, and can be parsed in linear time and space by packrat parsing — parsing with backtracking, but uses memoization to bound backtracking cost to a constant factor as parsing work is not repeated.

The end result will be succinctly:

@grammar
def number():
  x = digit()
  while test(digit):
    x = x*10 + digit()
  return x

print parse(number, "15")

Continue reading

Rootbeer – Red Arrow

Red Arrow

image

The ingredients include “Essences of wintergreen and licorice.” That sums it up in the best way possible. Would buy again.

Rootbeer – Sprecher

Sprecher Fire-Brewed Root Beer

image

Nice tone. It’s got just enough bite, reminds me a bit of XXX Rootbeer. It has a sweetness that doesn’t linger too long, possibly due to the glucose syrup. In any case, I like it quite a bit.

Gallery

KSP – Budget (Challenge)

This gallery contains 9 photos.

It’s time for another Weekly Challenge: Budget Crisis. This time, Reddit challenges us to visit a Kerbin moon in 15 parts or less. The part about deadly reentry is real. I have an unofficial tweak to the Deadly Reentry mod, … Continue reading

Non-determinism from generators

UPDATE(7/3/2013) I’ve found an earlier use of this technique written about on a blog, Valued Lessons – Monads in Python from 2008. Please read it too!

~~~

I was tinkering a bit tonight with simulating nondeterminism a-la McCarthy’s Amb operator — in Python. This is peculiar as Amb is usually implemented using either first class continuations or syntactic abstractions. Python supports neither.

So what is non-deterministic programming? Continue reading

Rootbeer – Sioux City Sarsaparilla

Sioux City Sarsaparilla

image

Mild sarsaparilla, and well balanced. Probably great as a first time sarsaparilla.

Rootbeer – Snake River

Snake River Sarsaparilla

image

Sharp and licoricey, punchy and ends softly. A very well balanced beverage. Definitely will buy again.

Awaiting JavaScript

Funny diversions in continuations seen this week. They’re not new, but new to me.

Continue reading

A little Call/cc in C#

Yesterday, I wanted to show someone how CallCC works in C#/async, but I couldn’t find any examples in my web search results. C#/async has been out in the world for some time, I’d be surprised if this hasn’t been done before, but just in case here’s a quick implementation.

Enjoy.

Continue reading

Rootbeer – Death Valley

Death Valley Root Beer

image

Good, simpler licoricey flavor. I can’t put my finger on it, but it’s just missing something for me. Enjoyed, but not on my short list.