10 ms·
Make Your Own Programming Language
- fcanela 12y agoServer not found error when connecting. Tried removing the "-" but didn't work neither.
- Hemospectrum 12y agoApparently the hyphen isn't there by mistake. Here's the blog source repo: https://github.com/Mattias-/Mattias-.github.io https://github.com/Mattias-/Mattias-.github.io Are you perhaps using a browser or a DNS stack that rejects this type of domain name?
- th0br0 12y agoThe question should probably be: which OS are you using? It's quite interesting... dig seems to resolve the domain just fine, but neither chrome, curl nor firefox seem to be able to open the page. (tested on Fedora/CentOS/Android)
- blablablaat 12y agoSame here. My dnsmasq server responds with the domain name when I try it with 'host', but curl and firefox fail on Debian and Ubuntu with only that 1 DNS server in resolv.conf. Curl says "curl: (6) Could not resolve host: mattias-.github.io". However, curl and firefox seem to be RFC-compliant. RFC952 states: "The last character must not be a minus sign or period."
- jwatte 12y agoAndroid, Google chrome, also have the resolver problem.
- steveklabnik 12y agoFirefox on Debian here, also get a "Problem loading page"
- cipher0 12y agoFirefox on Arch, same stuff. Edit: Google Chrome works.
- vortico 12y agoI had the same problem, but you can read the page from the Markdown-parsed source. https://github.com/Mattias-/Mattias-.github.io/blob/master/_posts/2015-01-03-DIY-Make-Your-Own-Programming-language.markdown https://github.com/Mattias-/Mattias-.github.io/blob/master/_...
- randunel 12y agoUbuntu 14.04 / Chrome + Firefox... same behaviour :( DNS resolves, curl + both browsers fail. randunel@18:~$ curl Mattias-.github.io curl: (6) Could not resolve host: Mattias-.github.io randunel@18:~$ dig +short Mattias-.github.io github.map.fastly.net. 185.31.18.133
- anindyabd 12y agoInteresting... I'm on Ubuntu 14.04 too, and Firefox fails for me, but Chrome succeeds.
- anaphor 12y agoI got it with curl -I 185.31.18.133 --header "Host: mattias-.github.io"
- stringy 12y agoAccording to RFC 1034[1] hyphens can only be interior to a label; it appears many tools simply follow these recommendations strictly. The exact wording is: "They must start with a letter, end with a letter or digit, and have as interior characters only letters, digits, and hyphen." [1]: http://www.ietf.org/rfc/rfc1034.txt http://www.ietf.org/rfc/rfc1034.txt
- teddyh 12y agoThe wording “must start with” doesn’t sound like a “recommendation”, and I would think that these tools are right to interpret the standard strictly, and that Github is wrong to allow such domain names.
- poizan42 12y agoWhatever happened to "be lenient in what you accept, conservative in what you send"?
- teddyh 12y agoGithub ignores that rule when they emit such domain names. One might make the point that Firefox and others who in turn reject such domain names are not being lenient in what they accept, but since domain names on the edge of acceptability often are a security issue, I think that a strict interpretation of the standard is the safe choice to make here.
- MichaelGG 12y agoIt's a terrible idea that just causes all sorts of intro l interop problems. Web development, for instance, is a mess because of all the various attempts to interpret stuff in some way, versus just failing.
- lelandbatey 12y agoI am also unable to visit the page. I'm on Android 4.2, using Firefox and Chrome.
- Pirate-of-SV 12y agoAuthor here: This is slightly embarrassing. I just added a custom domain/CNAME to my github pages so it should be reachable at http://blog.ppelgren.se http://blog.ppelgren.se
- fcanela 12y agoCould happen to anyone. Nice job solving it fast.
- gue5t 12y agoIn glibc's libresolv, this is caused by res_hnok in resolv/res_name.c returning 0: /* * Verify that a domain name uses an acceptable character set. */ /* * Note the conspicuous absence of ctype macros in these definitions. On * non-ASCII hosts, we can't depend on string literals or ctype macros to * tell us anything about network-format data. The rest of the BIND system * is not careful about this, but for some reason, we're doing it right here. */ #define PERIOD 0x2e #define hyphenchar(c) ((c) == 0x2d) #define underscorechar(c) ((c) == 0x5f) #define bslashchar(c) ((c) == 0x5c) #define periodchar(c) ((c) == PERIOD) #define asterchar(c) ((c) == 0x2a) #define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \ || ((c) >= 0x61 && (c) <= 0x7a)) #define digitchar(c) ((c) >= 0x30 && (c) <= 0x39) #define borderchar(c) (alphachar(c) || digitchar(c)) #define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c)) #define domainchar(c) ((c) > 0x20 && (c) < 0x7f) int res_hnok(const char *dn) { int pch = PERIOD, ch = *dn++; while (ch != '\0') { int nch = *dn++; if (periodchar(ch)) { (void)NULL; } else if (periodchar(pch)) { if (!borderchar(ch)) return (0); } else if (periodchar(nch) || nch == '\0') { if (!borderchar(ch)) return (0); } else { if (!middlechar(ch)) return (0); } pch = ch, ch = nch; } return (1); }
- gue5t 12y agoAnd the hack fix: /* hnokpre.c: LD_PRELOAD shim to bypass valid hostname checking in glibc gcc -fPIC -shared hnokpre.c -o libhnokpre.so LD_PRELOAD=./libhnokpre.so curl http://mattias-.github.io/ */ int res_hnok(const char* dn) { return 1; } int __res_hnok(const char* dn) { return 1; }
- poizan42 12y agoI'm kinda wondering what's the reason for that that check to begin with. Just being pedantic for pedentrys sake?
- deleted 12y ago[deleted]
- anindyabd 12y agoGreat post. Recently I wrote an interpreter for Scheme using Haskell using the guide "Write Yourself a Scheme" [1]. It was great fun, and it seems that it will be fairly straightforward to write a new domain-specific language using Haskell, using the same principles. That said, it was never clear to me how something like that would work in a non-purely-functional language, and so the fact that the OP used Rust is very exciting. [1] http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_H...
- rasur 12y agoThis is a great tutorial, although the one complaint I had was the errors in the pdf version (can't remember the specifics).. took me a while to realise the html version was far superior. Regardless of my complaints, it was an interesting experience.
- 0942v8653 12y agoWow. I'm sure I've seen Rust before (in fact, I have it installed) but I'm just surprised how similar it is to Swift. EDIT: s/is/looks/. I meant the syntax.
- mjburgess 12y ago> I'm just surprised how similar it is to Swift. A lot of language enthusiasts just winced.
- Hemospectrum 12y agoThe design of Swift was influenced by Rust. However, most of the resemblances are superficial or relate only to areas where Rust in turn was heavily influenced by other languages. For example, Rust's memory management model could not work in Swift (because this is an area where Swift remains compatible with Objective-C).
- Gurrewe 12y agoI started creating a language by myself a few days ago, this is a great read. Thanks!
- Pirate-of-SV 12y agoNice, what kind of language? I think nice beginner languages are Query languages (like SQL) or markup languages (like Markdown).
- Gurrewe 12y agoI'm aming for a scripting language that is a sort of mix between Lua and Go. The project is currently very overambitions, but it is fun! :)
- alediaferia 12y agoLet's add the next thing I won't have time to play with. Anyway, this is a great post and I look forward to the whole guide. Keep it up!
- Pirate-of-SV 12y agoThank you! If I can at least make one person interested I'm happy to continue.
- dochtman 12y agoFun! I've been working on Python-like systems language with a compiler in Python targeting LLVM IR, and it's been cool (though so much work to get a halfway usable language!). https://github.com/djc/runa https://github.com/djc/runa if anyone's interested.
- Pirate-of-SV 12y agoDid you create an interpreter for the language before you started on the compiler? I think it's not much overhead and you can run tests with it to make sure you get all the lexing and parsing done correctly. Then you just replace the evaluation with code generation and BAM! you've got a compiler.
- dochtman 12y agoNo, I didn't. For my language, being compiled down to machine code has been one of the design goals. Also, it doesn't seem to me like building an interpreter is significantly simpler than building a compiler (at least given the fact that I've left a bunch of the hard stuff to LLVM magic). LLVM IR isn't that hard to write.
- jmcdonald-ut 12y agoThis was a really cool read :). I'm working on my own DSL for generating code. I'll make a Show HN soon, but it was really cool to see someone else doing something so similar.
- Pirate-of-SV 12y agoNice what kind of code is it going to be used for to generate? A specific language or something more generic. It would be cool with a DSL to generate low level code like X86 ASM, LLVM IR or JVM bytecode. That would be so meta!
- jmcdonald-ut 12y agoHeh, not so complicated. It's just used to generate boiler plate code. Kind of like data object files in C#, Java, PHP, etc. That would be really cool though :).
- wldlyinaccurate 12y agoThe author appears to have added a CNAME since this was posted to HN. The updated URL is http://blog.ppelgren.se/2015-01-03/DIY-Make-Your-Own-Programming-language/ http://blog.ppelgren.se/2015-01-03/DIY-Make-Your-Own-Program...
- thomasfoster96 12y agoI started making a language a few months ago. I found Douglas Crockford's parser from his Top Down Operator Precedence paper pretty useful, which is here: http://javascript.crockford.com/tdop/index.html http://javascript.crockford.com/tdop/index.html When looking for resources on making toy languages, most of them said not to bother with a parser and use a pre-built solution. I think they're probably wrong - the parser is actually pretty easy (relative to the rest of the process of getting a language working) and at a stretch, fun.
- tachyonbeam 12y agoI agree. It's not as hard as one might think. I implemented my own handwritten JS parser using TDOP: https://github.com/higgsjs/Higgs/blob/master/source/parser/parser.d#L689 https://github.com/higgsjs/Higgs/blob/master/source/parser/p... I think it's more flexible and maintainable this way. I didn't have to wrestle with odd grammar rules. Implementing the JS "automatic semicolon insertion" with parser generator tools seems like it would have been a cluster headache.
- thomasfoster96 12y agoI have to admit I also wrote my own parser because I was keen on implementing some pretty advanced macros in it (which I've almost done already). A lot of those parser generator tools assume you have a nice C-like language syntax.
- seanmcdirmid 12y agoYes! I write my own recursive descent parsers because my programming languages tend to have incremental execution stories to them (you can see an example at http://research.microsoft.com/en-us/people/smcdirm/managedtime.aspx http://research.microsoft.com/en-us/people/smcdirm/managedti...). And writing a recursive descent parser really isn't that hard, plus it gives you more flexibility in tweaking error recovery. It also turns out that in industry, auto generated parsers are rarely used (Java is an exception) given performance and error recovery concerns. On the topic of precedence parsing, they have some really good properties in an incremental context: you can start parsing anywhere and the results will be the same. The problem is expressiveness, and while I came up with some hacks to push them beyond operators, pure recursive descent is much easier to work with (as I learned from Martin Odersky's scalac compiler).
- gpsarakis 12y agoGreat read! An effort on a DSL using PLY (Python LEX-YACC implementation): https://github.com/georgepsarakis/quick-bash https://github.com/georgepsarakis/quick-bash . It is actually a transcompilation to Bash from a functional language, using Python for the intermediate processing.
- jwatte 12y agoI would argue that this statement is a mistake that should have been foreseen: "negative integers isn't literals!" Specifically, twos complement signed integers will be a bitch of you continue down that path.
- dezgeg 12y agoOn the other hand, having negative integers as literals will cause even harder problems with subtraction (as in "2-2")
- Pirate-of-SV 12y agoIn a language like C the parser is going to try to parse Expr - Expr but not Expr Expr since there's no such construct in the language to put two expressions after each other.
- Vendan 12y agoActually, it's an incredibly good idea, cause you can then just implement constant folding on the AST, and that (unary negate)1 turns into an actual -1, as well as a lot of other good optimizations.
- Tenjou 12y agoNice article, inspired me to invest time in the future to learn Rust. Also working on JavaScript native compiler + developing a new language on top as subset for JavaScript: https://github.com/InfiniteFoundation/dopple https://github.com/InfiniteFoundation/dopple (front page info is outdated though).
- msie 12y agoIt would be cool if we could add a "Rust" tag to this entry. I almost didn't give this link a second look because I thought it was an older link. Glad I did give it a second look.
- rtpg 12y agowhitespace sensitivity is a pretty big pain to deal with in the current toolkits available for building out a programming language, unfortunately. The pain is compared to the absolute and total simplicity of defining a grammar when you're in a whitespace-insensitive setting (parser generators are easy to express and efficient in deterministic grammars). We have a lot of good parsing tools out there, but we might be missing the right tools for building out good lexers
- nadams 12y agoAfter writing a lexer, parser, compiler and virtual machine in C++ and ported parts to Python, Java and FreeBASIC - I think this is a good starting point. Most of the concepts are pretty simple - it's when you get into if/while/for statements. Especially if you have nested if/while/for statements. Conceptually easy to implement using recursion but during the compilation phase keeping track of where you are at can be...difficult. I'll be the first to admit my implementation sucked but it worked.
- mataug 12y agoI'm getting started with LLVM, Just downloaded the source and now wondering how to go about things.
- marcofiset 12y agoVery interesting read. I am myself writing a series on the same subject and I was pretty inspired by your way of writing. Your article is paced a lot faster than what I have written so far and I really like the style. I submitted my own posts to HN also, but I did not get the same attention as you did, congratulations! I'm looking forward to the next iteration ;)
- loop2 12y agoI started one a while ago, but I became fascinated by the "middle end" and bought a compiler textbook. Now I have SSA optmizations but no strings still.