commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Dunning <ted.dunn...@gmail.com>
Subject Re: Parsing and solving algebraic equation from string
Date Mon, 21 Jul 2014 05:59:28 GMT
On Sun, Jul 20, 2014 at 9:18 PM, Mansour Al Akeel <mansour.alakeel@gmail.com
> wrote:

> As Luc said, it will big project to write a parser that takes any
> equation as a string, and generate the matrix (2-dimensional array) to
> feed it into Commons Math.
>


It actually isn't a big project.

See http://www.antlr.org/

The simplest example they give there is this one:

*grammar Expr;*
*prog: (expr NEWLINE)* ; *
*expr: expr ('*'|'/') expr *
*    | expr ('+'|'-') expr *
*    | INT | '(' expr ')' ; *
*NEWLINE : [\r\n]+ ; INT : [0-9]+ ;*

This will compile into a java program that parses expressions very much
like what you want.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message