Re: Lexer and parser generator in Clojure

2012-05-22 Thread Lukas Domagala
you could try https://github.com/Cyrik/clparsec . i´m still working on an alpha release, but it already has all the basic parsec operators -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com No

Re: Lexer and parser generator in Clojure

2012-05-20 Thread Jason Jackson
This is a really great project. If you add LR1, you may want to retain ~LR0 as an option. My understanding is most grammars today are designed for LALR1. On Sun, May 20, 2012 at 4:26 AM, Christophe Grand wrote: > On Sat, May 19, 2012 at 9:44 PM, Jason Jackson wrote: > >> In retrospect, I would ha

Re: Lexer and parser generator in Clojure

2012-05-20 Thread Christophe Grand
On Sat, May 19, 2012 at 9:44 PM, Jason Jackson wrote: > In retrospect, I would have tried > https://github.com/cgrand/**parsley afaik > it has ~LR1 performance characteristics. > Parsley is closer to LR(0) (but I'd like to make it LR(1) using Pager's lane trac

Re: Lexer and parser generator in Clojure

2012-05-19 Thread Brent Millare
I wrote a library on parsing expression grammars (PEGs). Its not completely independent from clojurescript since I use java's regular expressions for the token component, but technically it works on sequences and its easy to rewrite this for js's regexps. Performance hasn't been measured but the

Re: Lexer and parser generator in Clojure

2012-05-19 Thread Jason Jackson
I didn't read the part about clojure/clojurescript interop. Also, you could write a parser by hand in clojure[script], which takes a parse table as input. The parse table can be generated with from any language. On Saturday, 19 May 2012 15:44:28 UTC-4, Jason Jackson wrote: > > I wrote a com

Re: Lexer and parser generator in Clojure

2012-05-19 Thread Jason Jackson
I wrote a compiler in Clojure for a 4th year course. For parsing I used this combinator parser library: https://github.com/jasonjckn/clarsec which is modeled after haskell's parsec. However the performance was kind of bad, combinator parsers in general can be pretty slow. In retrospect, I w

Re: Lexer and parser generator in Clojure

2012-05-19 Thread John Szakmeister
On Fri, May 18, 2012 at 8:46 AM, Alexsandro Soares wrote: > Hi, > > I'm trying to build a compiler using Clojure. Is there any tools > like flex and bison generating Clojure code? > I'm interested in a lexer/parser in pure Clojure because I think >  in use the same code with Javascript (

Re: Lexer and parser generator in Clojure

2012-05-19 Thread Matt Mitchell
Here's a parser: https://github.com/joshua-choi/fnparse Doesn't look like it's active, but could be a starting point? - Matt On Friday, May 18, 2012 8:46:19 AM UTC-4, Alexsandro Soares wrote: > > Hi, > > I'm trying to build a compiler using Clojure. Is there any tools > like flex and bison

Lexer and parser generator in Clojure

2012-05-18 Thread Alexsandro Soares
Hi, I'm trying to build a compiler using Clojure. Is there any tools like flex and bison generating Clojure code? I'm interested in a lexer/parser in pure Clojure because I think in use the same code with Javascript (via ClojureScript) and Java (via Clojure). I already know isolated too

Re: generator in Clojure

2010-10-17 Thread clwham...@gmail.com
I don't actually 'know' that I need a function that relies on mutable state, I'm really just trying to understand how to do what I want using the functional paradigm. I'm writing a data generator which creates CSV files to be uploaded to a test database. I'm simulating the behavior of some network

Re: generator in Clojure

2010-10-14 Thread Konrad Hinsen
On 14 Oct 2010, at 21:52, clwham...@gmail.com wrote: I need a function that produces the 'next' value from a lazy-seq -- something like a Python generator. I imagine it would have to be some sort of closure like: (def next-sine (let [sines (atom (cycle (map sin (range 0 6.28 0.01]

Re: generator in Clojure

2010-10-14 Thread Alan
Yes, it would be. But it's "wildly unlikely" that you need to do it. You don't say what you're using next-sine! for, but I'll imagine you're doing something like printing it. Maybe your code looks like: (dotimes [n num-iters] (let [s current-sine] (next-sine!) (println s))) This can eas

Re: generator in Clojure

2010-10-14 Thread clwham...@gmail.com
I originally thought of calling nth on the seq but isn't that pretty wildly inefficient? On Oct 14, 1:38 pm, Moritz Ulrich wrote: > Are you sure you need to capture the state in next-sine? It's not very > clojure-ly to have functions with state. I would capture the state in > the caller as an int

Re: generator in Clojure

2010-10-14 Thread Nicolas Oury
(defn iterate [s] (let [a (atom s)] (fn [] (let [s @a] (reset! a (next s)) (first s)) but it's not very idiomatic in clojure. (In Lisp it is traditional to hide a state in a closure. A lot of toy object language work like that) On Thu, Oct 14, 2010 at 9:38

Re: generator in Clojure

2010-10-14 Thread Moritz Ulrich
Are you sure you need to capture the state in next-sine? It's not very clojure-ly to have functions with state. I would capture the state in the caller as an integer and just use get or nth on the lazy seq. If you want to stick to your impure function, please mark it with a ! at the end: next-sine!

generator in Clojure

2010-10-14 Thread clwham...@gmail.com
I need a function that produces the 'next' value from a lazy-seq -- something like a Python generator. I imagine it would have to be some sort of closure like: (def next-sine (let [sines (atom (cycle (map sin (range 0 6.28 0.01] #(swap! sines rest))) Is there a more idomatic way o