Compile Time D Expression Parser?

Philippe Sigaud philippe.sigaud at gmail.com
Sun Mar 11 09:58:50 PDT 2012


dcoder:
> I need to parse simple D expressions at compile time. I was wondering if
somebody on the list has some example code that could be of help to me.
>
> I am working on an opensource constraint solver  and expressions that I
need to parse can be reasonably complex such as "x + y*n < 32 && x > 4". I
want to code a string mixin that parses such expressions and writes out
code that creates a parse tree for the given expression.

OK, doing a bit of thread necromancy here (3 weeks, still acceptable here?)

Puneet, I might have something for you. IIUC, you want to parse expressions
that are

- an association of boolean expressions (&&, ||, !)
- each boolean expression is an equation (=, <=, >, etc)
- each equation lhs or rhs is an arithmetic expression (+, -, *, /)
- atoms in an arithmetic expression can be numbers or variables

Is that it? You do realize that any parse tree will for these constructs
will be quite deep, right? I mean, 10-levels deep or somesuch.

Philippe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120311/e6b9409a/attachment.html>


More information about the Digitalmars-d mailing list