
Erik Christiansen wrote:
Warning: Simplest method presented last.
On 09.08.12 14:13, Trent W. Buck wrote:
Jason White wrote:
James Harper <james.harper@bendigoit.com.au> wrote:
The problem is that my sed script says to start at the "(" and then read up until a ")", but I really mean to say read up until a matching ")". Can I do this with sed or should I be using something else? ...
Thus you cannot use a regular expression, but you can use an parser that accepts some subset of CFGs, such as LALR (e.g. yacc) or LL(k) (e.g. parsec).
Just modelling the mechanics mentally, it seems that it might be quicker to implement with just a lexer (e.g. lex) to pick out the open and closing braces [...]
Well, note that my second example lacks the traditional separation of lexing and parsing phases, as seen in lex/yacc. http://research.microsoft.com/en-us/um/people/daan/download/parsec/parsec.pd... In that paper, ยง2.2 (pp. 6) covers a language with matching parens and nothing else: parens = do { char '('; parens; char ')'; parens; } <|> return () A one-liner is pretty quick and simple ;-) PS: there are better references that was simply the first that ddg returned, and it amused me to remind readers that a lot of Haskell comes out of MS Research :-)