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

xianwei <baikaishiuc@gmail.com>
Thu, 27 Nov 2008 17:46:28 -0800 (PST)

          From comp.compilers

Related articles
[18 earlier articles]
Re: Has anyone hand-written a scanner/parser module? armelasselin@hotmail.com (Armel) (2008-11-19)
Re: Has anyone hand-written a scanner/parser module? bobduff@shell01.TheWorld.com (Robert A Duff) (2008-11-23)
Re: Has anyone hand-written a scanner/parser module? bobduff@shell01.TheWorld.com (Robert A Duff) (2008-11-23)
Re: Has anyone hand-written a scanner/parser module? charlesb.cca@mpowercom.net (Charles E. Bortle, Jr.) (2008-11-24)
Re: Has anyone hand-written a scanner/parser module? charlesb.cca@mpowercom.net (Charles E. Bortle, Jr.) (2008-11-24)
Re: Has anyone hand-written a scanner/parser module? jmvdveer@xs4all.nl (Marcel van der Veer) (2008-11-25)
Re: Has anyone hand-written a scanner/parser module? baikaishiuc@gmail.com (xianwei) (2008-11-27)
Re: Has anyone hand-written a scanner/parser module? d_j_v@mac.com (Dustin Voss) (2008-11-29)
| List of all articles for this month |
From: xianwei <baikaishiuc@gmail.com>
Newsgroups: comp.compilers
Date: Thu, 27 Nov 2008 17:46:28 -0800 (PST)
Organization: Compilers Central
References: 08-11-061
Keywords: lex, question
Posted-Date: 28 Nov 2008 12:20:27 EST

On Nov 16, 1:49 am, "tuxisthebirdfo...@gmail.com"
<tuxisthebirdfo...@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?


I write a regular expression engine (base on DFA) to scan the source
code.
the interface like this:
        AddMoreType( scanner, L"ID", L"[_a-zA-Z][a-zA-Z0-9_]*" );
        AddMoreType( scanner, L"ID.WHILE.discard",
L"while" );
        AddMoreType( scanner, L"ID.IF.discard",
L"if" );
        AddMoreType( scanner, L"ID.THEN.discard",
L"then" );
        AddMoreType( scanner, L"ID.ELSE.discard",
L"else" );
        AddMoreType( scanner, L"ID.ENDIF.discard",
L"endif" );
        AddMoreType( scanner, L"ID.DO.discard",
L"do" );
        AddMoreType( scanner, L"ID.BREAK.discard",
L"break" );
        AddMoreType( scanner, L"ID.FOR.discard",
L"for" );
        AddMoreType( scanner, L"ID.TO.discard",
L"to" );
        AddMoreType( scanner, L"ID.LET.discard",
L"let" );
        AddMoreType( scanner, L"ID.IN.discard",
L"in" );
        AddMoreType( scanner, L"ID.END.discard",
L"end" );
        AddMoreType( scanner, L"ID.TYPE.discard",
L"type" );
        AddMoreType( scanner, L"ID.ARRAY.discard",
L"array" );
        AddMoreType( scanner, L"ID.OF.discard",
L"of" );
        AddMoreType( scanner, L"ID.VAR.discard",
L"var" );
        AddMoreType( scanner, L"ID.FUNCTION.discard",
L"function" );
        AddMoreType( scanner, L"ID.NIL.discard",
L"nil" );
        AddMoreType( scanner, L"STRING", L"\"(\\\\.|[^\"])*
\"" );
        AddMoreType( scanner, L"NUM", L"[1-9][0-9]*|
0" );
        ....


but a little bug is already exists, the next version, i try to fix it.


I spent one month write a LR(1) Grammar Analysis, used to parsing
Tiger language the language defined in Modern Compiler Implementation
in C. about 85 rules. only generate trans-DFA, not support EBNF.



Post a followup to this message

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