A couple of questions about arrays and slices

Cecil Ward cecil at cecilward.com
Sat Jun 24 16:42:45 UTC 2023


On Saturday, 24 June 2023 at 15:12:14 UTC, Jonathan M Davis wrote:
> On Saturday, June 24, 2023 8:43:00 AM MDT Cecil Ward via 
> Digitalmars-d-learn wrote:
>> I started out looking into a number of runtime library 
>> routines, but in the end it seemed quicker to roll my own code 
>> for a crude recursive descent parser/lexer that parses part of 
>> D’s grammar for expressions, and (again partial grammar) 
>> parser for string literal expressions and so on. I find 
>> certain special elements and execute actions which involve 
>> doing the AA lookup and replacing variable names with ordinal 
>> numbers in decimal in the output stream. Admission: The 
>> parsing is the thing that has to be fast, even though again 
>> the size of the D language text is not likely to be huge at 
>> all. But 40 years ago, I came from a world with 2k RAM and 0.9 
>> MHz clock rates so I have developed a habit of always thinking 
>> about speed before I do anything, needful or not, to be 
>> honest. I once wrote a program that took 35 mins to evaluate 
>> 2+2 and print out the answer, so I’m now ashamed of writing 
>> slow code. Those were bad days, to be honest. 4 GHz+ and ILP 
>> is nicer.
>
> Well, dmd is open source (and Boost-licensed, so it doesn't 
> really have any restrictions), so depending on what you're 
> doing, it might make sense to just take code from that (and 
> it's very fast). IIRC, it pulls some fun tricks like replacing 
> identical strings with pointers to the same string so that it 
> can just compare pointers.
>
> - Jonathan M Davis

Yeah, it would take me forever to get my head around that, and I 
only want a crude toy partial parser for certain portions of the 
grammar, and the parsing code is done now. A hand-written 
recursive descent type thing mainly dealing with things like 
comments and literal string that have to be taken account of as 
they prevent hazards to naive straight string searching for what 
you want to find, as comments and eg double-quoted strings could 
have things in them that are red-herrings or the things that you 
want to find items in, depending on circumstances.

I’m trying to get my head round the differences between OSX tools 
and those for Linux relating to LDC and GDC which seems slightly 
inferior in some situations. I’m a serious professional asm 
programmer of old, before compilers were of usable output quality 
for
git-hard applications. (‘a git’ a disreputable person, colloquial 
English English. ‘git hard’ - brain-meltingly hard, like quantum 
gravity.)


More information about the Digitalmars-d-learn mailing list