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
Return to the
comp.compilers page.
Search the
comp.compilers archives again.