Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #101058
| Newsgroups | comp.lang.c |
|---|---|
| Date | 2017-01-03 16:01 -0800 |
| References | <o4gf2a$bl9$1@dont-email.me> <dbf92bb2-ae2d-4133-83f6-f0f9a5c5d198@googlegroups.com> <o4gv18$8sc$1@dont-email.me> <f878a326-cda4-491f-be4c-65977eb7d1e9@googlegroups.com> <o4h5ei$1ht$1@dont-email.me> |
| Message-ID | <f7b25ec4-e790-4ddd-acef-39a438c3b2af@googlegroups.com> (permalink) |
| Subject | Re: 'Amalgamated' source code |
| From | Thiago Adams <thiago.adams@gmail.com> |
On Tuesday, January 3, 2017 at 7:36:53 PM UTC-2, Bart wrote: > On 03/01/2017 20:48, Thiago Adams wrote: > > On Tuesday, January 3, 2017 at 5:47:24 PM UTC-2, Bart wrote: > >> On 03/01/2017 16:47, Thiago Adams wrote: > > >>> (I also have implemented an C preprocessor.) > >> > >> (I'm [in] the middle of one at the minute. Most online refs on writing > >> compilers tend to ignore this piffling little obstacle that you have to > >> overcome first!) > > > > I didn't find a good references. I did it completely wrong at the beginning. > > This is an sample from C standard that shows me my first mistakes. > > > > #define hash_hash # ## # > > #define mkstr(a) # a > > #define in_between(a) mkstr(a) > > #define join(c, d) in_between(c hash_hash d) > > char p[] = join(x, y); > > // equivalent to > > // char p[] = "x ## y"; > > > > I saw much more mistakes, parsing real code. (windows.h) > > I'll have to make a collection of tricky examples for my testing. > > (But I've just seen one detail I hadn't allowed for, in gcc.c (from > http://people.csail.mit.edu/smcc/projects/single-file-programs/). On > line 733881 in a macro call: > > DEF_FORMAT_ATTRIBUTE(PRINTF,1,1_0) > > The token '1_0' appears. It starts as a number but presumably must be > treated as alphanumeric. This did not work for me as well. #define M(1_0) M(1) I have used the same tokens for preprocessor and parser. I just treat they differently. I think my tokenizer will output [1:number] and [_0:identifier]. I guess my problem is simple i just count the wrong number of arguments for M. I will try to fix later. > I don't know if that puts paid to the idea of introducing underscores as > numeric separators; from the bizarreness of how the CPP works, probably > not!) > > >> OS where the right modules have to be picked). I'll be glad when my new > >> C to C translator works then it'll be automatic. > > > > What is this "C to C translator"? > > It was originally a compiler for another language with C source as a > possible target (which builds entire projects). Then I thought it would > be more fun to work on a front end for C source. > > But retaining a C output option has several benefits, including > converting multi-module apps to single-file C source code, and > translating experimental language extensions to standard C. If you do language extensions for instance I think the users would like to see one "natural" code. This is almost like a code format, where you must keep comments and macro without expansion. For instance, if the programmer use #ifdef then the code extension should be always processed for each #ifdef option. If the generated C code were "natural" it could include these #ifdefs. Also for debbuging. And instead of having one big file you could keep the same file logic that user choose. As an option the compiler could generate the module one-file only. Today I can read one translation unit and generate the AST. After that I can generate C code again. If I do that, the generated code will contain all the definitions from system includes for instance, and no macros. For each declaration I have the source file, so I can ignore declaration from extern code. Doing this the generated code is small but all the macros and #ifs disappears (expanded). I think I can keep comments inside the AST as something appended on each ast node. for macros I dont have idea what to do.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-03 15:14 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-03 08:47 -0800
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-03 19:47 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-03 12:48 -0800
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-03 21:36 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-03 16:01 -0800
Re: 'Amalgamated' source code Keith Thompson <kst-u@mib.org> - 2017-01-03 16:26 -0800
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-03 18:00 -0800
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-04 03:34 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-04 03:31 -0800
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 12:03 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-04 05:00 -0800
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-05 02:38 -0800
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-05 14:28 +0000
Re: 'Amalgamated' source code supercat@casperkitty.com - 2017-01-05 08:20 -0800
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-05 17:05 +0000
Re: 'Amalgamated' source code supercat@casperkitty.com - 2017-01-05 10:11 -0800
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-05 19:46 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-05 12:15 -0800
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-05 21:54 +0000
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-05 17:40 +0000
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-05 19:33 +0000
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 10:53 +0000
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-04 01:51 +0000
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 11:54 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-04 05:57 -0800
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 14:20 +0000
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 15:07 +0000
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-04 15:34 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-04 08:03 -0800
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-04 17:09 +0000
Re: 'Amalgamated' source code bart4858@gmail.com - 2017-01-04 08:54 -0800
Re: 'Amalgamated' source code Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-04 17:22 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-04 07:55 -0800
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-05 18:04 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-01-05 11:50 -0800
Re: 'Amalgamated' source code Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-01-04 16:29 +0000
Re: 'Amalgamated' source code bart4858@gmail.com - 2017-01-04 09:15 -0800
Re: 'Amalgamated' source code Ian Collins <ian-news@hotmail.com> - 2017-01-05 08:33 +1300
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 20:26 +0000
Re: 'Amalgamated' source code supercat@casperkitty.com - 2017-01-04 13:09 -0800
Re: 'Amalgamated' source code Ian Collins <ian-news@hotmail.com> - 2017-01-05 10:21 +1300
Re: 'Amalgamated' source code supercat@casperkitty.com - 2017-01-04 13:51 -0800
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-04 22:02 +0000
Re: 'Amalgamated' source code Ian Collins <ian-news@hotmail.com> - 2017-01-05 11:15 +1300
Re: 'Amalgamated' source code Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-01-07 06:38 +0000
Re: 'Amalgamated' source code BartC <bc@freeuk.com> - 2017-01-07 11:35 +0000
Re: 'Amalgamated' source code supercat@casperkitty.com - 2017-01-04 09:53 -0800
Re: 'Amalgamated' source code Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-04 11:50 -0800
Re: 'Amalgamated' source code raltbos@xs4all.nl (Richard Bos) - 2017-01-10 01:34 +0000
Re: 'Amalgamated' source code Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-10 01:59 -0800
Re: 'Amalgamated' source code Les Cargill <lcargill99@comcast.com> - 2017-01-10 06:55 -0600
Re: 'Amalgamated' source code Richard Heathfield <rjh@cpax.org.uk> - 2017-01-10 14:48 +0000
Re: 'Amalgamated' source code Thiago Adams <thiago.adams@gmail.com> - 2017-04-26 07:17 -0700
csiph-web