www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - acess the d parser and compiler from the source code

reply dennis luehring <dennis_member pathlink.com> writes:
what about extending the std.compiler module

with an parse(char[] buffer/filename) feature
why do we need extra parser projects - can't we use the dmd one
internaly?

import std.compiler;
token_tree = parse("test.d"); ...

and maybe an internal compile() feature (like java have)

ciao dennis lühring
Mar 01 2006
next sibling parent reply BCS <BCS_member pathlink.com> writes:
For one thing there would be some value in having more than one compiler (as of
now AFAIK ther is only one lexer/parcer in existance).

In article <du3vnq$6j8$1 digitaldaemon.com>, dennis luehring says...
what about extending the std.compiler module

with an parse(char[] buffer/filename) feature
why do we need extra parser projects - can't we use the dmd one
internaly?

import std.compiler;
token_tree = parse("test.d"); ...

and maybe an internal compile() feature (like java have)

ciao dennis lühring

Mar 01 2006
parent reply kellywilson nowhere.com writes:
In article <du4kni$165u$1 digitaldaemon.com>, BCS says...
For one thing there would be some value in having more than one compiler (as of
now AFAIK ther is only one lexer/parcer in existance).

Hey there BCS, If you mean a semantic checking parser, then I also believe there is only one in existence, but if you just need a parse tree then I have a implementation that can lex and parse almost all of the D language (two obscure cases won't parse right now...but otherwise I can parse Phobos and Mango and produce a parse tree). I use the Elkhound parser generator, which produces C++ output for the resulting GLR parser. The parse tree won't be as clean as dmd right now, since I have unresolved ambiguities in my grammar. When I say unresolved, I mean that there are ambiguities that could probably be removed, I just haven't gotten to all of them yet. There will probably always be a couple ambiguities due to the nature of D, though Manfred Nowak has said in the past that he produced a context free grammar for D? I haven't seen an actual working context free grammar though, as he never released it. I am willing to release my small project (as I have to Ivan Senji) if you or Dennis would like to use it for some research, as far as your "parsing feature" goes. Please email me a the University of Calgary (google for "kelly wilson computer science" and I am the first listing) if you want. I am still working on building a meaningful AST and then doing the semantic checking, then I will be more willing to publicly release the project. Thanks, Kelly Wilson P.S. I also believe that having more than one D compiler (two actually since gdc is a fully functional compiler, but it USES the dmd frontend) is important. Why are there more than 10 or 20 C++ compilers? Different companies/people produce different implementations with different "features" and optimizations. Thus, certain people prefer certain compilers for their architecture. Just my two bits on the multiple compiler issue...and something to justify my efforts, I guess ;)
In article <du3vnq$6j8$1 digitaldaemon.com>, dennis luehring says...
what about extending the std.compiler module

with an parse(char[] buffer/filename) feature
why do we need extra parser projects - can't we use the dmd one
internaly?

import std.compiler;
token_tree = parse("test.d"); ...

and maybe an internal compile() feature (like java have)

ciao dennis lühring


Mar 01 2006
parent reply BCS <BCS_member pathlink.com> writes:
In article <du4uds$1hfq$1 digitaldaemon.com>, kellywilson nowhere.com says...

 Please email me a the University of [snip] (google for "kelly wilson
computer science" and I am the first listing) if you want. 

Tried that, didn't find the address. If the domain is "cs<DOT>ualberta<DOT>ca" just post the rest.
Mar 01 2006
parent reply Hasan Aljudy <hasan.aljudy gmail.com> writes:
BCS wrote:
 In article <du4uds$1hfq$1 digitaldaemon.com>, kellywilson nowhere.com says...
 
 
Please email me a the University of [snip] (google for "kelly wilson
computer science" and I am the first listing) if you want. 

Tried that, didn't find the address. If the domain is "cs<DOT>ualberta<DOT>ca" just post the rest.

Mar 01 2006
parent kellywilson nowhere.com writes:
Thanks Hasan,

Sorry I didn't reply but I have been out of town. It is indeed a
cpsc.ucalgary.ca address, preceeded by wilsonk and the (at) symbol. Please try
again BCS, if you would like.

Thanks,
Kelly Wilson

In article <du5ajo$20c2$1 digitaldaemon.com>, Hasan Aljudy says...
BCS wrote:
 In article <du4uds$1hfq$1 digitaldaemon.com>, kellywilson nowhere.com says...
 
 
Please email me a the University of [snip] (google for "kelly wilson
computer science" and I am the first listing) if you want. 

Tried that, didn't find the address. If the domain is "cs<DOT>ualberta<DOT>ca" just post the rest.


Mar 04 2006
prev sibling parent James Dunne <james.jdunne gmail.com> writes:
dennis luehring wrote:
 what about extending the std.compiler module
 
 with an parse(char[] buffer/filename) feature
 why do we need extra parser projects - can't we use the dmd one
 internaly?
 
 import std.compiler;
 token_tree = parse("test.d"); ...
 
 and maybe an internal compile() feature (like java have)
 
 ciao dennis lühring
 
 

With the current DMD reference compiler implementation, which is written in minimal C++ using globals everywhere and is obviously not context-safe, this would prove very difficult to integrate natively with D source code. What I mean by non context-safe is that the compiler is meant to run in a single executable for a single time, not handle multiple compilations pseudo-simultaneously using different compilation context structures. Now, if the compiler were implemented as a context-safe library (and further, thread-safe) with an exposed C API, then all one would have to do is write a D header module to interface with the compiled library's C API. Voila - you have D compiler access within the D language. :) I've mentioned this before, but I see it's a fair amount of work. Since the compiler *is* implemented in C++, the classes do a fair amount of keeping context, yet the main function and its global variables do need to be refactored into a compiler class. Just one more level of abstraction necessary. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/MU/S d-pu s:+ a-->? C++++$ UL+++ P--- L+++ !E W-- N++ o? K? w--- O M-- V? PS PE Y+ PGP- t+ 5 X+ !R tv-->!tv b- DI++(+) D++ G e++>e h>--->++ r+++ y+++ ------END GEEK CODE BLOCK------ James Dunne
Mar 01 2006