Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
JSCPP, a simple C++ interpreter written in JavaScript (github.com/felixhao28)
98 points by turrini on Aug 26, 2018 | hide | past | favorite | 31 comments


also relevant is cling, made by the folks at CERN

https://github.com/root-project/cling

https://root.cern.ch/cling


this is neat. I noticed that with this we get Read–eval–print loop for C++. Which would make it really useful in an ide like light table.


A similar project, also good for educating but within a jupyter notebook for c++

https://github.com/QuantStack/xeus-cling


* A subset of C++.


I was going to say, "Jesus Christ did one guy actually manage to write a fully standards-conformant C++ parser?"


I know of one guy who did, as well as inventing the D language, and he also visits HN and posts semi-regularly --- http://walterbright.com/


A simple C++ interpreter is an oxymoron.


It's c++ without the "object-oriented features," so that could be fairly simple.


That's called C.


Strictly speaking, C++ is not anymore a superset of C. Mostly syntatic sugar but still, some C code can not be parsed by C++. But yeah, i know what you mean, i guess this is a bastard of C and C++?


C++ was never a superset of C. The same keywords mean different things, character literals are different types, void pointer assignment works differently, etc.


No, this isn't C either. The following doesn't work:

  struct Bob {
    int a;
  };
  int main() {
    int a;
    struct Bob x;
    x.a = 3;
    return 0;
  }
So when they say "without object oriented features" they seem to mean: "No extendable type system". Which does make this a lot simpler of a language.


C is C++ minus object-oriented features, increased type-safety, template meta-programming, lambdas, and many more features.


Not true, C has features missing from C++.


So, are there situations where one would use C over C++? I don't know C++, and only learned C while catching up on my fundamentals.


Which?



There is a more complete answer with a link but quickly : restrict, designated initializers, generic macros...


Right, the useless cruft that makes your program impossible to read, let alone reason about


Is this the cruft that gets reinvented in C whenever the project grows complex enough?

Something like: any sufficiently complicated C program contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of C++'s features.


Ha! The lambdas and tools surrounding them in C++11 and later have vastly improved the ability to make programs much easier to read and reason about.


Hardly. Compare std sort to qsort and tell me that it's superior.


yes, I guess all those C++ programs don't exist and C++ programmers don't actually read or write any programs.


It could still support e.g. function templates (not sure if it actually does).


I didn't write the README.


The example uses the iostreams header instead of cstdio. Not sure how this would work without object-oriented features.


It seems like some of the C++ library features are special-cased.

From the Q&A section of the readme:

"Which notable features are not implemented yet?

    > Object-oriented features"
"Which libraries are supported?

    > iostream (only cin and cout and endl)"


This appears to be a proof of concept, for the purposes of learning and exploration. From the README:

"Currently, it is mainly for educational uses for a MOOC course I am running (and fun)."

"Which features are implemented? (Most) operators"


Couldn't find in readme if templates are supported.


It doesn't even support structs/classes.

edit: Templated functions don't work either.


But why? Most js engines (or at least V8) are written in c++.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: