lua-users home
lua-l archive

Re: OT(slightly): parser generator for expression with custom operators

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi Steve!
On 29/06/2011 17.24, steve donovan wrote:
On Wed, Jun 29, 2011 at 5:13 PM, Lorenzo Donati
<lorenzodonatibz@interfree.it> wrote:
As an end user of a programming language like Lua, in which I often write
simple DSLs, I'd like to be able to define such a parser by only defining
the operators and their characteristics, not to write down a grammar.
It does sound like an interesting problem, but why not use Lua itself?
That's a non-rhetorical question, that is,
-what features do you need that could not be done in Lua?
Arbitrary custom operators.
-are they essential to the DSL?
Well, not that often, I admit. As I said, the post had also a "philosophical" twist :-) Still, sometimes doing without custom operators is a pain. Especially when mapping concepts from math.
For example, consider math vectors:
W = V1 :x: V2 + V3
W = V1:cross_product(V2) + V3 -- less readable
a = (V1 [.] V2) / |V1 [.] V2|
a = V1:dot_product(V2) / V1:dot_product(V2):abs() -- less readable
(I won't start gong on about lexical preprocessing since I probably won't stop)
I wonder if LuaMacro could be of any help here - I only skimmed over the readme, but I did not dare "put more meat on the grill" (as we say in Italy) ;-)
steve d.
cheers,
-- Lorenzo

AltStyle によって変換されたページ (->オリジナル) /