Re: Basic question about creating a parser

Eric Ludlam <[email protected]> Sat, 29 Apr 2017 18:03:28 -0400
Newsgroups gmane.emacs.semantic
Message-ID <[email protected]>
On 03/20/2017 12:40 PM, Eric Abrahamsen wrote:
> [I tried to send this to the gmane.emacs.cedet group, but it didn't
> appear there, hope this is a more appropriate channel.]
>
> I've been working on a parser for vcard files, using regular
> expressions. It's going fine, but it just feels brittle and unpleasant.
>
> The vCard format comes with an ABNF, I guess[1]. I've never worked with
> lexers/parsers before, but my assumption is that I could convert this
> ABNF to a language grammar, and the make a parser that would turn a
> vCard text file into some sort of lisp structure, which I could then go
> on to work with.
>
> I've tried out the semantic and bovine manuals, and they assume a bit
> more basic knowledge than I've got.
>
> Can anyone let me know if semantic is at all an appropriate tool for
> this job? The grammar is dead simple: header, footer, and each line is a
> key-plus-value-plus-parameters deal, that's all there is to it.
>
> All I really want is to munch text files and produce some sort of
> structured result. Though, come to think of it, if this could then be
> used to make a vcard-mode, that would be great.
>
> Any pointers very welcome!

Hi Eric,

Sorry for a slow response.  Kids are pretty time consuming.

The semantic tools is a great way to build a parser for a language.  I 
recommend the 'wisent' parser generator, as it is faster than the 
original bovine version.  The wisent manual has some nice examples in it 
for building a language.  The goal of any of these parsers is to create 
a 'tag' which is then used for code analysis.  If you want to create a 
parser with some other struture output, that is also possible.  The 
example semantic/wisent/calc.wy and semantic/wisent/calc.el shows a 
calculator parser that does the math instead of generating tags, so it 
might be a nice example.

Eric

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot