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

codeworker@free.fr (Cedric LEMAIRE)
13 Aug 2004 17:34:58 -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: codeworker@free.fr (Cedric LEMAIRE)
Newsgroups: comp.compilers
Date: 13 Aug 2004 17:34:58 -0400
Organization: http://groups.google.com
References: 04-08-067
Keywords: parse, macros
Posted-Date: 13 Aug 2004 17:34:58 EDT

topdigital@hotmail.com (.X.T.I.M.) wrote in message news:04-08-067...
> [snip...]
> then,i need make some preprocess like this:
>
> #Loop($count,1,99) //$count is a macro variable, loop form 1 to
> 99
> #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


If you accept the preprocessing being accomplished by an external
tool, instead of being executed by your parser itself, I can propose
you a simple solution.


I suppose that you recognize C-like comments. It could be a inline
format too (but as you are applying a RR scan, it can't be something
like // ... \n), however my solution is more readable with multi-line
comments.


Copy the following lines into your source file (called "example.xtim",
for instance):
/*##markup##"preprocess 1"*//*##script##*/
/*
local iCount = 1;
while $iCount < 100$ {
@
a@iCount@ + b@iCount@ + c@iCount@ = d@iCount@
__asm("mov eax ,dword ptr[d@iCount@]");
__asm("push eax");
@
increment(iCount);
}
*/
/*##script##*/




Then download 'CodeWorker' at "http://www.codeworker.org" (freeware)
and execute:
    codeworker -autoexpand example.xtim -commentbegin /* -commentend */




Explanations:
-------------


CodeWorker is a universal parsing tool (don't care here) and a
versatile source code generator. It knows various techniques in source
code generation. I call one of them "auto-expansion". It consists of
detecting markups like '##markup##"a constant string"' embedded
between comments, in any kind of text file, and executing the script
located between '##script##' tags just below.


This piece of script is a template-based script, which generates text
just below the markup. Here, the script iterates on a counter and
injects your code.
If you want to preprocess more sophisticated tasks, see the online
documentation at "http://www.codeworker.org/Documentation.html" or
download the PDF form at "http://www.codeworker.org/CodeWorker.pdf".


The format of a comment is specified on the command-line
('-commentbegin' and '-commentend').


You can use this technique on C / Java / ... / HTML / LaTeX / ...
files. You just have to change the comment formats.


Post a followup to this message

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