Re: Has anyone hand-written a scanner/parser module?

jgd@cix.compulink.co.uk
Sun, 16 Nov 2008 10:57:40 -0600

          From comp.compilers

Related articles
Has anyone hand-written a scanner/parser module? tuxisthebirdforme@gmail.com (tuxisthebirdforme@gmail.com) (2008-11-15)
Re: Has anyone hand-written a scanner/parser module? echristo@gmail.com (Eric Christopher) (2008-11-15)
Re: Has anyone hand-written a scanner/parser module? felipeangriman@gmail.com (Felipe Angriman) (2008-11-15)
Re: Has anyone hand-written a scanner/parser module? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-11-16)
Re: Has anyone hand-written a scanner/parser module? jeremy.bennett@embecosm.com (Jeremy Bennett) (2008-11-16)
Re: Has anyone hand-written a scanner/parser module? barry.j.kelly@gmail.com (Barry Kelly) (2008-11-16)
Re: Has anyone hand-written a scanner/parser module? efutch@gmail.com (Egdares Futch) (2008-11-16)
Re: Has anyone hand-written a scanner/parser module? jgd@cix.compulink.co.uk (2008-11-16)
Re: Has anyone hand-written a scanner/parser module? idbaxter@semdesigns.com (Ira Baxter) (2008-11-16)
Re: Has anyone hand-written a scanner/parser module? rajamukherji@gmail.com (Raja Mukherji) (2008-11-16)
Re: Has anyone hand-written a scanner/parser module? bill@qswtools.com (Bill Cox) (2008-11-16)
Re: Has anyone hand-written a scanner/parser module? marcov@stack.nl (Marco van de Voort) (2008-11-17)
Re: Has anyone hand-written a scanner/parser module? dmaze@mit.edu (David Z Maze) (2008-11-17)
Re: Has anyone hand-written a scanner/parser module? gene.ressler@gmail.com (Gene) (2008-11-17)
[12 later articles]
| List of all articles for this month |

From: jgd@cix.compulink.co.uk
Newsgroups: comp.compilers
Date: Sun, 16 Nov 2008 10:57:40 -0600
Organization: Compilers Central
References: 08-11-061
Keywords: lex, parse, practice
Posted-Date: 16 Nov 2008 17:53:59 EST

  tuxisthebirdforme@gmail.com () wrote:


> I know most people anymore use lex/yacc or some derivative of these
> tools to create scanner/parser modules for their compiler projects. I
> was wondering if anyone has developed a scanner or parser that they
> personally hand-wrote? If so, I would like to know what language you
> used and what type of grammar you parsed. If you feel divulgent,
> please tell me a little bit about you're implementation or what you
> did for intermediate representation.


It wasn't a general-purpose parser, but I have hand-written Perl code to
take C headers for a C API apart and generate an (unsafe) C# binding for
the API. However, the task was somewhat different from normal parsing
for compilation:


* I could assume that the headers were valid C code, although I checked
    this by running them through the C compiler before starting parsing.


* I could not preprocess my C before parsing, because the names of
    large numbers of macros defining constants needed to survive into
    the C#. This was the point that set me to hand-writing code.


* I could take advantage of the conventions of the API I was dealing
    with, since this parser could be considered as an extra convention-
    enforcer. The conventions are quite constricting, which was helpful.


* Perl regexps are pretty useful.


* C# does not require declaration before use, which made outputting
    the C# code much simpler.


* I'm not even an amateur when it comes to writing compilers, so there
    were probably better ways to do the job. However, we could not find
    anything ready-made, and it works pretty well.


The intermediate representation, such as it was, is a bunch of Perl
associative arrays. These were relatively simple to dump out and examine
for problems.


John



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.