[erlang-questions] erlang-questions Digest, Vol 248, Issue 1

Mark Steele mark@REDACTED
Mon Dec 14 16:35:55 CET 2015


>
>
> Message: 1
> Date: Sun, 13 Dec 2015 22:33:37 -0500
> From: Mark Steele <mark@REDACTED>
> To: erlang-questions@REDACTED
> Subject: [erlang-questions] String parsing recommendations
> Message-ID:
>         <CAB5=
> j_qy3PFF+fGYxHWLOq2NfGc_H-ciK+_TKnggR+4nRmM8BQ@REDACTED>
> Content-Type: text/plain; charset="utf-8"
>
> Hi all,
>
> This is a pretty basic question, but I'm new so bear with me.
>
> I've got a binary that might look something like this:
>
> <<"(foo,bar(faz,fez,fur(foe)),fuz)">>
>
> Parsed, the it might look like:
>   [
>    [<<"foo">>],
>    [<<"bar>>,<<"faz">>],
>    [<<"bar">>,<<"fez">>],
>    [<<"bar">>,<<"fur">>,<<"foe">>],
>    [<<"fuz">>]
>   ]
>
>
> Any recommendations on the best approach to tackle this in Erlang?
>
> Regards,
>
> Mark
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://erlang.org/pipermail/erlang-questions/attachments/20151213/6e75379c/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 2
> Date: Mon, 14 Dec 2015 13:02:24 +0900
> From: zxq9 <zxq9@REDACTED>
> To: erlang-questions@REDACTED
> Subject: Re: [erlang-questions] String parsing recommendations
> Message-ID: <1468783.uT1lQZLqR7@REDACTED>
> Content-Type: text/plain; charset="utf-8"
>
> On 2015?12?13? ??? 22:33:37 Mark Steele wrote:
> > Hi all,
> >
> > This is a pretty basic question, but I'm new so bear with me.
> >
> > I've got a binary that might look something like this:
> >
> > <<"(foo,bar(faz,fez,fur(foe)),fuz)">>
> >
> > Parsed, the it might look like:
> >   [
> >    [<<"foo">>],
> >    [<<"bar>>,<<"faz">>],
> >    [<<"bar">>,<<"fez">>],
> >    [<<"bar">>,<<"fur">>,<<"foe">>],
> >    [<<"fuz">>]
> >   ]
> >
> >
> > Any recommendations on the best approach to tackle this in Erlang?
>
> I'm a little confused about what you are asking. Can you provide some
> example input, and some example output? It seems like you're asking
> how to write a function that takes input X and returns output Y...?
>
> -Craig
>
>
>
More along the lines of best practices and tools (eg: lex/yecc, neotoma,
etc...). I'm good, did some additional research.


> ------------------------------
>
> Message: 3
> Date: Mon, 14 Dec 2015 10:27:57 +0100
> From: Mikael Pettersson <mikpelinux@REDACTED>
> To: Mark Steele <mark@REDACTED>
> Cc: erlang-questions@REDACTED
> Subject: Re: [erlang-questions] String parsing recommendations
> Message-ID: <22126.35741.750950.255610@REDACTED>
> Content-Type: text/plain; charset=us-ascii
>
> Mark Steele writes:
>  > Hi all,
>  >
>  > This is a pretty basic question, but I'm new so bear with me.
>  >
>  > I've got a binary that might look something like this:
>  >
>  > <<"(foo,bar(faz,fez,fur(foe)),fuz)">>
>  >
>  > Parsed, the it might look like:
>  >   [
>  >    [<<"foo">>],
>  >    [<<"bar>>,<<"faz">>],
>  >    [<<"bar">>,<<"fez">>],
>  >    [<<"bar">>,<<"fur">>,<<"foe">>],
>  >    [<<"fuz">>]
>  >   ]
>  >
>  >
>  > Any recommendations on the best approach to tackle this in Erlang?
>
> The input language is clearly not regular, so you'd need
> something stronger than regular expressions for parsing.
> In this case a context-free parser should work.
>
> Personally I'd implement a separate scanner which returns tokens
> and updated input, and a recursive descent parser which handles
> the grammar and produces the output.  Your desired output is not
> like a parse tree but more like an evaluation of the parse tree
> (bar(faz,fez,...) expands to a different structure), but that
> expansion looks trivial so I'd let the parser do it -- otherwise
> an intermediate parse tree and a separate evaluator will work.
>
> There are scanner and parser generating tools for Erlang, but
> they would be overkill for this simple language -- unless you're
> new to language processing, in which case they could help by
> providing examples and imposing a sensible structure to the
> solution.  The re module could be used in a hand-written scanner.
>
> Alas, no Erlang magic here, just ordinary compiler frontend code.
>
> /Mikael
>
>
>
Yup, thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20151214/d5d111e1/attachment.htm>


More information about the erlang-questions mailing list