4 ms·
Just wondering if it is true that most of the modern language parsers are written in C?
by tumurinn 10y ago
Just wondering if it is true that most of the modern language parsers are written in C?
- lifthrasiir 10y agoProbably true, but only because the implementation language for them is also C. Some of them also frequently use a mix of the implementation language and grammar specification DSL like yacc.
- sebcat 10y agoUse of DSLs and tools like flex and bison makes the implementation a whole lot more reliable (but only if they're used, and some commonly run languages have a very implementation-specific grammar). consider: input: /* empty string */ | input line ; line: '\n' | exp '\n' { printf ("\t%.10g\n", $1); } ; exp: NUM { $$ = $1; } | exp '+' exp { $$ = $1 + $3; } | exp '-' exp { $$ = $1 - $3; } | exp '*' exp { $$ = $1 * $3; } | exp '/' exp { $$ = $1 / $3; } | '-' exp %prec NEG { $$ = -$2; } | exp '^' exp { $$ = pow ($1, $3); } | '(' exp ')' { $$ = $2; } ; http://dinosaur.compilertools.net/bison/bison_5.html#SEC27 http://dinosaur.compilertools.net/bison/bison_5.html#SEC27
- matiasb 10y agoGo is now written in Go
- spriggan3 10y agoIt used to be written in C before bootstrapping.
- rtpg 10y agoI don't think this is true. Loads of FP languages are self-hosted.
- sjrd 10y agoNot only FP. Lots of languages are self-hosted. So actually most modern parsers are not written in C, since they are written in the language they parse.
- pcr0 10y agoPython, Ruby, PHP: C JS: no standard parser, but V8(chrome), SpiderMonkey(firefox) and Chakra(edge) are all C++ Go, C, C++: self-hosted (written in the same language) Java, Erlang: parser/compiler self-hosted, but VMs written in C.
- nv-vn 10y agoI doubt it. If anything, C++, but even that doesn't seem likely. The vast majority of languages seem to be self-hosted. A good portion compilers or interpreters in C or C++ probably use (F)lex and Yacc/Bison so even saying C or C++ are the most popular choice (but not necessarily the majority) sounds like a stretch.