A Structure problem for a private language [about preprocess' problem]

topdigital@hotmail.com (.X.T.I.M.)
11 Aug 2004 12:56:06 -0400

          From comp.compilers

Related articles
A Structure problem for a private language [about preprocess' problem] topdigital@hotmail.com (2004-08-11)
Re: A Structure problem for a private language [about preprocess' prob codeworker@free.fr (2004-08-13)
| List of all articles for this month |

From: topdigital@hotmail.com (.X.T.I.M.)
Newsgroups: comp.compilers
Date: 11 Aug 2004 12:56:06 -0400
Organization: http://groups.google.com
Keywords: macros, question, comment
Posted-Date: 11 Aug 2004 12:56:06 EDT

i'm in writing a small and simple compiler for my project,i want to
provide some preprocess mechine,to make some duplication labor easier.
      but i'm used RR method[it's a try!] to scan my lexeme as token, and
go on parse it. but,allow me bring a bad example:
      in my code, there is need for some duplication statement like

                  a1 + b1 + c1 = d1;
                  ___asm("mov eax , dword ptr[d1]");
                  ___asm("push eax");

                  a2 + b2 + c2 = d2;
                  ___asm("mov eax , dword ptr[d2]");
                  ___asm("push eax");

                  a3 + b3 + c3 = d3;
                  ___asm("mov eax , dword ptr[d3]");
                  ___asm("push eax");
                  a99 + b99 + c99 = d99;
                  ___asm("mov eax , dword ptr[d99]");
                  ___asm("push eax");

then,i need make some preprocess like this:

        #Loop($count,1,99) //$count is a macro variable, loop form 1 to
            #Insert("a%d + b%d + c%d = d%d\n",$count,$count,$count,$count)
            #Insert("__asm(\"mov eax ,dword ptr[d%d]");\n",$count)
            #Insert("__asm(\"push eax\");\n",$count)//C-RTL printf's format
        #EndLoop //Loop block finish

As we see,that preprocess statement has used macro variable,so,is it
need the type check?is that i can olny make my compiler has a
preprocesser,and it alway's run after the real compiler's active?has
any method i can do sth adv preprocess work such as:
      Can I Do It In A Same Pass With The Read Code?I Mean'S When The
Lexcial Scanner Scanned The Sharp Symbol,It Excape To A Proprocess
Parser,And Save The Current State Stack And Tokens As Context,When The
Proprocess Has Been Returned,Then Combine The Original Codes And
Generated Codes,And Go On The Parse With The Context,But That Will
Make A Very Complex Construction.I Don'T Know What Is The Good Way To
Do This,Can Any Guy Give Me A Tip?
        Thanks and Best Regards!

                                                                    .X.T.I.M. [topdigital@hotmail.com]
[I'd just use m4 in front of my parser. You can build in a preprocessor,
but as you suspect, it's basically a separate pass and you have to
implement it as a coroutine with your parser, which can be messy. -John]

Post a followup to this message

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