Skip to content

Instantly share code, notes, and snippets.

import "container/vector"
type fsa_s struct {
states []StringVector
cur_state []StringVector
}
func initFsa(states *StringVector, alphabet *StringVector) {
package main
import vector "container/vector"
import "fmt"
type Fsa struct {
States *vector.StringVector
Alpha *vector.StringVector
Current string
}
@dcolish
dcolish / phplex.py
Created July 21, 2010 16:33 — forked from ramen/phplex.py
# ----------------------------------------------------------------------
# phplex.py
#
# A lexer for PHP.
# ----------------------------------------------------------------------
import ply.lex as lex
# todo: literal html
# todo: double-quoted strings
from ply import lex
t_ignore = ' \t'
reserved = {'Theorem': 'THEOREM',
'Goal': 'GOAL',
'Proof': 'PROOF',
'Prop': 'PROP',
'forall': 'FORALL',
'exists': 'EXISTS',
from ply import lex
t_ignore = ' \t'
reserved = {'Theorem': 'THEOREM',
'Goal': 'GOAL',
'Proof': 'PROOF',
'Prop': 'PROP',
'forall': 'FORALL',
'exists': 'EXISTS',
import ast
node = ast.Expression(ast.BinOp(left=ast.Num(5, lineno=0, col_offset=0),
op=ast.Add(),
right=ast.Num(2, lineno=0, col_offset=0),
lineno=0,
col_offset=0),
lineno=0,
col_offset=0)
import ast
from phpparse import parser
input = '<?php echo "hello, world!"; ?>'
output = parser.parse(input)
map = {'Echo': ast.Print}
node_type, args = output[0].generic()
op = map[node_type](values=[ast.Str(args['nodes'].pop(), lineno=0,
ZOMG WOMBAT!
@dcolish
dcolish / lazy_fib.py
Created October 27, 2010 02:35
Lazy evaluation example using python iterators
from itertools import takewhile
from math import sqrt
class Fib(object):
def __init__(self):
self.i = 2
self.items = [0, 1]
from ctypes import *
class Node(Structure):
pass
Node._fields_ = [("next", POINTER(Node)),
("foo", c_int)]