2

Objective: To create a smaller version of node.js with the ultimate objective of creating a scripting language with some of the features of node (JS) and to add some of my own.

I understand, of course, that I need to look at the node.js source code but I could not find any parser code in the node.js source code on nodejs.org. Does node.js have its own parser (possibly using yacc or some such tool) as node.js is mostly written in C, C++? If so, where do I access it? Or does it reply on the V8 engine source code for parsing JS? I believe that node.js language itself is not strictly V8 Javascript compliant. Or is it? Since V8 compiles JS to native machine code, surely it must have a full fledged parser/translator somewhere.

In short, can someone point me to the parser code to let me knock out some of the unwanted grammar rules from the node.js parser? Or is there some open source project already out there which has addressed this question?

7
  • 1
    You probably won't create a smaller node.js. It uses V8 to handle JS. Node provides the http parser and other shenanigans needed to handle socket connections etc. There are similar projects such as nw.js, phantomJS. Commented Sep 18, 2015 at 14:07
  • Your comment is helpful but I believe that the other "shenanigans" modules do not need additional parsing support as they simply return JS objects. But there are statements such as "require" which I believe would not be covered in the V8 parser as they are not JS statements. And why do you say that I won't create a smaller node.js? Simply stripping some of the grammar rules (or the related code) from the parser, at least in theory, accomplishes it. Does it not? Commented Sep 18, 2015 at 14:19
  • 1
    Not really. If you wish to alter the grammar rules, you'll be altering V8, not node. require is a node module which uses JS grammar and it glues together some c++ code with V8. I don't know why you would want a "smaller" node (I'm assuming you want smaller executable, nw's is about 70mb which is pretty small for what it does), but killing really useful modules or altering grammar doesn't mean you'll end up with a smaller file / project. Anyway, I wish you good luck with your project. Commented Sep 18, 2015 at 14:24
  • I want to create a smaller and more specific language (DSL, if you will) derived from node and not a smaller executable. Commented Sep 18, 2015 at 14:31
  • 2
    Why not create something like CoffeeScript or TypeScript where you create a transpiler instead? It seems like that would be a much easier route? Commented Sep 18, 2015 at 14:38

1 Answer 1

1

If you're looking to create a new syntax/language that still takes advantage of node's machinery for doing I/O and whatnot, your best bet is probably to look into creating a transpiler (e.g. like what CoffeeScript or TypeScript does).

Doing that will be significantly easier than trying to hack on v8's source to change the JavaScript language implementation itself.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.