[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: succinct awk code to check for paired parantheses?
From: |
Wolfgang Laun |
Subject: |
Re: succinct awk code to check for paired parantheses? |
Date: |
Thu, 25 Mar 2021 15:51:15 +0100 |
David,
the original post talked of code determining whether "parentheses in a
string are all paired", implying (via the given reference) that "paired"
means open precedes closed. It seems that the outputs
if ) 5 ( b = 0;
not balanced
if ((a>b) && (b>c) && // ) ((c>d)) { a = 0; }
balanced
from my function are both correct. Or did you see a request for "C code
snippets" or the like?
Lex can only parse Chomsky type-3 grammars, and parenthesized expressions
are defined by type-2 grammars, so Lex won't do.
Cheers
Wolfgang
On Thu, 25 Mar 2021 at 14:26, david kerns <david.t.kerns@gmail.com> wrote:
> I submit the following test cases that fail the proposed awk solutions:
>
> #1
> if ((a>b) && (b>c) && // )
> ((c>d)) {
> a = 0;
> }
>
> #2
> if ) 5 ( b = 0;
>
> I stand by my original post, this is a job for lex
>
>
>
>
--
Wolfgang Laun