6 ms·
Compiling a Functional Language Using C++, Part 9 – Garbage Collection
- blackandblue 7y agois there a "cpp: the good parts" book that anyone can recommend for someone who has done c/cpp a long time ago?
- cannam 7y agoBjarne Stroustrup's "A Tour of C++" (http://www.stroustrup.com/Tour.html http://www.stroustrup.com/Tour.html) is close. It's a slim volume that is roughly a survey of the language as if it had begun with C++11.
- blackandblue 7y agothanks
- colejohnson66 7y agoI wish he’d update them (both books) for C++20 (C++2a), or even just C++17.
- steerablesafe 7y agoA Tour of C++ 2nd edition covers C++17, AFAIK.
- pjmlp 7y agoYes it does and also mentions parts of C++20 like concepts and modules.
- adamnemecek 7y agoMy comment might be unwarranted but at this point, considering Rust might be also an option.
- AnimalMuppet 7y agoAll right, same question: Is there a "Rust: the good bits" book that someone can recommend?
- adamnemecek 7y agoThere is the Klabnik one from NoStarch and the Blandy one from O'Reilly. The first one is more towards beginners, the second one is pretty advanced, you build some relatively advanced things. I own both. Part of the appeal of Rust is that there aren't as many bad parts as with C++.
- pjmlp 7y agoI like Rust, but it still has to grow up a bit to be an option for GUIs, iOS/Android, game engine middleware, Windows/macOS systems programming. It will eventually get there, but it isn't there yet.
- adamnemecek 7y agoYou make them yourself. With Rust you might not need those things as much, because you roll these things yourself. What are the GUI frameworks in other languages? Qt? wxWidgets? GTK? These are all so, so, so bad. I'm saying this as I'm writing my own GPU-rendered immediate-mode GUI toolkit with multiple rendering backends. I can't do this in any other language, like...I would legit get stuck on the build systems. You are right, it would be better if there were somewhat better frameworks but I'm ok writing my own. As an aside, my long term dream is to write a next-gen OS in Rust. GPU-first, new application paradigms, compiler comes with the OS, first-class networking support. The languages empowers you to an insane degree. What Windows/macOS systems programming would you want?
- pjmlp 7y agoNo I don't, I rather be productive doing what I am supposed to do in first place. Some examples, DriverKit, COM/UWP, WinUI, Metal Shaders, CUDA, SYSCL, Treble, Unreal/Unity. For all of those I already have a good mix of Swift, .NET, Java/Kotlin and C++, as they are the official OS SDK languages, writing in Rust would just slow me down in its present state. Bad UI toolkits?! Best that Rust currently has is Gtk-rs and that is being nice versus what those toolkits and GUI tooling are capable of.
- pjmlp 7y agoBesides "A Tour of C++", you might enjoy the following: - "The C++ Standard Library, 2nd Edition" from Rainer Grimm - "C++ Templates, The Complete Guide, 2nd Edition" from David Vandevoorde, Nicolai M. Josuttis, Douglas Gregor - "Functional Programming in C++" from Ivan Čukić - "Concurrency with Modern C++" from Rainer Grimm And any talk from Bjarne or Herb at CppCon or C++Now.
- LessDmesg 7y agoThese blog posts are golden, thanks. I definitely will peruse them when creating my language.
- jakearmitage 7y agoDoes anyone know anything like this, but for an indentation-based language? Writing a Python-like parser was always hard for me, ending up with a generic INDENT/DEDENT counter mess.
- andai 7y agoI wrote a simple excel formula parser a while ago, and I used a counter too -- just for parentheses. Your comment made me realize I might have been going about it the hard way.
- LessDmesg 7y agoPypy seems to be reasonably well-documented: http://doc.pypy.org/en/latest/parser.html http://doc.pypy.org/en/latest/parser.html https://bitbucket.org/pypy/pypy/raw/b7b76322a4a7f53db98a883daba13080ae882500/pypy/interpreter/pyparser/pyparse.py https://bitbucket.org/pypy/pypy/raw/b7b76322a4a7f53db98a883d...
- Jaxan 7y agoEdward Kmett has a talk about parsing with monoids [0]. Somehow that seems an elegant way of doing layout based syntax. I have never done it myself, though. [0] https://www.youtube.com/watch?v=Txf7swrcLYs https://www.youtube.com/watch?v=Txf7swrcLYs
- gnulinux 7y agoYou need to use the "lexer trick". While lexing your input data, instead of ignoring whitespace or producing token WS or TAB or whatever, keep track of your indents and newlines. Then it's simple to decide if it's an indent (newline followed by at least 1 more space or tab than previous, add this to your indents stack) or dedent (newline followed by the previous indent (look at your indent stack)). Then produce INDENT and DEDENT seperate tokens. Once you have these tokens produced by tokenizer, it's easy to parse. Do the usual recursive descent. Source: I built my own python compiler (python->C++) as a university projects.
- tomp 7y agoPretty much this. You need a stack because an single NEWLINE might result in 2 DEDENT tokens: if x: if y: f() g() You only need to keep track of whitespace (spaces and/or tabs) after a newline (and you can skip lines with only whitespace & comments). It's also useful to keep tracks of delimiters (like parentheses and brackets), if you want to ignore newlines/indents inside expressions (like Python). The easiest IMO is writing a lexer using a lexer generator (Lex, Flex, ...) and outputting a NEWLINE(spaces) tokens, then have another class that keeps track of indents, parentheses, etc. I wrote a lexer/parser combo that (1) tracks whitespace in top (file) context, (2) ignores whitespace in expressions (parentheses, [] arrays, {} records), except (3) restarts indentation-tracking in {} blocks (even if they're in parentheses themselves!) - now that's hard to code (and debug LOL).