Nested Brackets

88 views
Skip to first unread message

Simon Woods

unread,
Jul 8, 2011, 1:35:40 PM7/8/11
to sprache
Hi

Just trying to work out how to cater for nested brackets.

So, for the following examples

(a+(b*c))
or
((a+b))

What are the rules needed to parse these expressions?

Many thx

Simon

Brad Williams

unread,
Jul 8, 2011, 7:50:09 PM7/8/11
to sprache...@googlegroups.com
Logically I think this would do it:

A Val can be:
a variable like a or x
OR
a left paren + a Val + a right paren
OR
a Combination

A Combination can be:
a Val + an Operator + Val

An Operator can be:
+
OR
*

Nicholas Blumhardt

unread,
Jul 8, 2011, 8:10:46 PM7/8/11
to sprache...@googlegroups.com
This parser shows an example of expressions with support for parens:


Cheers,
Nick
Message has been deleted

Simon Woods

unread,
Jul 9, 2011, 5:14:07 AM7/9/11
to sprache
Brad

Many thx ....

That did the trick. My "most basic" parsers were crap!

Simon

Simon Woods

unread,
Jul 9, 2011, 5:20:24 AM7/9/11
to sprache
Nick

Many thx ... I think not 'getting' the ChainOperator plus Brads post
got me sorted.

On Jul 9, 1:10 am, Nicholas Blumhardt <nicholas.blumha...@gmail.com>
wrote:
> This parser shows an example of expressions with support for parens:
>
> http://code.google.com/p/sprache/source/browse/LinqyCalculator/Expres...
>
> Cheers,
> Nick
>
> On 9 July 2011 09:50, Brad Williams <brad...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Logically I think this would do it:
>
> > A Val can be:
> >  a variable like a or x
> >  OR
> >  a left paren + a Val + a right paren
> >  OR
> >  a Combination
>
> > A Combination can be:
> >  a Val + an Operator + Val
>
> > An Operator can be:
> >  +
> >  OR
> >  *
>
> > On Fri, Jul 8, 2011 at 10:35 AM, Simon Woods <simonwoods2...@gmail.com>
Reply all
Reply to author
Forward
0 new messages