dmd Lexer and Parser in D
reachzachatgooglesmailservice at dot.com
Sat Feb 4 20:43:21 PST 2012
On 2/4/12 1:24 PM, Timon Gehr wrote:
> On 02/04/2012 06:39 PM, Zach Tollen wrote:
>> If anybody can refer me to any examples and demonstrations of this type
>> of code-editing, please do. As someone new to programming I'm really
>> wondering why, if the program itself is understood by the computer as a
>> tree, why do I have to edit a text file instead of a tree?
> You are: The source file can be seen as the representation of a tree
> structure, and if you read the source you group the characters in a
> tree-like way in order to understand what it is saying. Anyway, this is
> true for any language. Your post could be parsed into a tree structure too.
I know what you mean, but what I mean is that it would be cool if my
text editor knew that when I started a line with 'writeln(' that I had
no intention of finishing the line without inserting a corresponding
');'. Instead, if I forget to add the ending parenthesis, the compiler
thinks I meant never to end the function call and it gives a parse error
when it gets to something it can't read according to its expectations.
It gets a little worse when the structure in question gets larger or
What I wish would happen is that I simply told the editor directly "I
want to insert a complete statement here", and then it inserts the
statement into it's tree, and I can't get rid of it without giving a
specific command to do so. So while I understand that the text file
*represents* a syntax tree, I wish it were more controlled than that.
That thought made it tempting to consider, well how hard would it be to
have the editor just hold the tree itself in memory and all the editor's
commands were oriented toward adding, deleting, changing the program
itself instead of changing textual characters which merely represent the
I see two reasons this might be a bad idea.
First, even in an ideal world, where you had a fully implemented syntax
tree editor, it might turn out that it's just worse than manually
editing the files.
But the other reason is one of tradition and infrastructure. If all the
experiences folks have is with text editing then they don't want to
change, and all the infrastructure is already built to support text
It's this second reason I'm scared of. It would seem like a shame if
that were the only reason nobody wants to build a syntax-tree editor.
So I'm still interested in this idea. I'm going to try to research
people's experiences with this kind of thing.
More information about the Digitalmars-d