Re:How to implement a programming language in JavaScript
by lifthrasiir on Wednesday June 29, 2016 @12:47AM
(#11999553)
Probably 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.
[ Parent
| on HN ]
Re:How to implement a programming language in JavaScript
by sebcat on Wednesday June 29, 2016 @01:25AM
(#11999674)
Use 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