Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #1876
| From | Hans-Peter Diettrich <DrDiettrich1@netscape.net> |
|---|---|
| Newsgroups | comp.compilers |
| Subject | Re: Designing a Domain-specific language |
| Date | 2017-05-24 06:42 +0200 |
| Organization | Compilers Central |
| Message-ID | <17-05-009@comp.compilers> (permalink) |
| References | <17-05-007@comp.compilers> |
Am 23.05.2017 um 16:12 schrieb dror.openu@gmail.com: > My dilemma is: "How's the compile process should be when you have many files". I thought about this process for the second requirement, and I'd like to hear your opinion: > 1. scan all the files (assume we have k files). > 2. for each of the files: > 2.1 run the lexer together with parser and build a parse tree. > 3. now, I have k parse trees (but only one entry-point/main). > 4. if there's a circular dependencies return an error > 5. resolve the "include"s by merging the trees into one tree. John already pointed out two commonly used methods, so let me only add some keys. A *preprocessor* can be implemented as a stand-alone tool, that resolves the "include ..." directives, and produces a combined output file that then can be compiled. Or it does the same as kind of a filter, sitting between the lexer and parser, so that it can feed one sequential stream of tokens to the parser. The preprocessor either switches its input amongst files, in order to produce a combined file, or it switches amongst lexers, each of which processes a single input file. A *linker* resolves references between object modules, or AST's, so that the result is either a single object or executable file, or a single combined AST (parse tree). A clever linker can cache individual definitions (variables, functions...), and load only the really required definitions on demand. This technique allows to eliminate all unused parts of the source files from the final program. Again a linker can be implemented as a stand-alone tool, or as part of a compiler. Caveat: If your "include" directive allows to insert *incomplete* definitions, e.g. individual lines of code into a function, only a preprocessor can produce valid input for the parser. Otherwise, if all definitions can be parsed without occurences of embedded "include" directives, all definitions (of identifiers) can be parsed individually, and merged into a common list of definitions, as the top level of the parse tree, or as a list of individual parse trees for each listed definition. DoDi
Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Designing a Domain-specific language dror.openu@gmail.com - 2017-05-23 07:12 -0700
Re: Designing a Domain-specific language bartc <bc@freeuk.com> - 2017-05-23 20:39 +0100
Re: Designing a Domain-specific language dror.openu@gmail.com - 2017-05-25 12:51 -0700
Re: Designing a Domain-specific language bartc <bc@freeuk.com> - 2017-05-27 16:00 +0100
Re: Designing a Domain-specific language Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2017-05-24 06:42 +0200
Re: Designing a Domain-specific language "lucretia9@lycos.co.uk" <laguest9000@googlemail.com> - 2017-05-24 04:13 -0700
csiph-web