Compare commits

...

10 Commits

Author SHA1 Message Date
Johnny Peck
d8d4013045 Update the-super-tiny-compiler.js
Plural "node"
2020-01-07 10:12:27 -08:00
Jamie Kyle
f0321d5b1d
Update README.md 2019-06-21 19:02:05 -07:00
Donald Pipowitch
4f7a85a9f8 change interface for visitor in description 2017-10-13 17:13:29 +11:00
james kyle
386d1efd5b Update the-super-tiny-compiler.js 2017-05-31 12:48:50 -07:00
Elliptica
c5979db026 Fix typo 2017-04-25 09:19:22 -07:00
james kyle
3aa9f63aa8 Update README.md 2017-04-13 14:07:03 -07:00
薛定谔的猫
bc2898670e bugfix: filename error (#53) 2017-01-10 14:18:45 -08:00
G. Kay Lee
dee8b924ea Update the-super-tiny-compiler.js (#51)
Made some modifications to make the newly-added text fit into existing paragraphs.
2017-01-04 12:21:30 -05:00
james kyle
a7f50205ee Update Image 2016-12-31 16:23:56 -05:00
james kyle
ca64396847 Update Image 2016-12-31 16:17:37 -05:00
3 changed files with 33 additions and 21 deletions

View File

@ -1,4 +1,4 @@
<a href="the-super-tiny-compiler.js"><img width="731" alt="THE SUPER TINY COMPILER" src="https://cloud.githubusercontent.com/assets/952783/14171276/ed7bf716-f6e6-11e5-96df-80a031c2769d.png"/></a>
[![The Super Tiny Compiler](https://cloud.githubusercontent.com/assets/952783/21579290/5755288a-cf75-11e6-90e0-029529a44a38.png)](the-super-tiny-compiler.js)
***Welcome to The Super Tiny Compiler!***
@ -10,6 +10,8 @@ work from end to end.
### [Want to jump into the code? Click here](the-super-tiny-compiler.js)
### [You can also check it out on Glitch](https://the-super-tiny-compiler.glitch.me/)
---
### Why should I care?
@ -32,10 +34,7 @@ file.
### I'm back, that didn't make sense
Ouch, I'm really sorry. I'm planning on doing a lot more work on this to add
inline annotations. If you want to come back when that's done, you can either
watch/star this repo or follow me on
[twitter](https://twitter.com/thejameskyle) for updates.
Ouch, I'm really sorry. Let me know how it can be improved.
### Tests

View File

@ -4,7 +4,7 @@ const {
transformer,
codeGenerator,
compiler,
} = require('./super-tiny-compiler');
} = require('./the-super-tiny-compiler');
const assert = require('assert');
const input = '(add 2 (subtract 4 2))';

View File

@ -259,7 +259,7 @@
*
* If we were manipulating this AST directly, instead of creating a separate AST,
* we would likely introduce all sorts of abstractions here. But just visiting
* each node in the tree is enough.
* each node in the tree is enough for what we're trying to do.
*
* The reason I use the word "visiting" is because there is this pattern of how
* to represent operations on elements of an object structure.
@ -275,8 +275,8 @@
* CallExpression() {},
* };
*
* When we traverse our AST we will call the methods on this visitor whenever we
* encounter a node of a matching type.
* When we traverse our AST, we will call the methods on this visitor whenever we
* "enter" a node of a matching type.
*
* In order to make this useful we will also pass the node and a reference to
* the parent node.
@ -286,10 +286,8 @@
* CallExpression(node, parent) {},
* };
*
* We call these functions when we "enter" the node. But there is also the
* possibilty of calling things on "exit".
*
* Imagine our tree structure from before in list form:
* However, there also exists the possibility of calling things on "exit". Imagine
* our tree structure from before in list form:
*
* - Program
* - CallExpression
@ -315,7 +313,7 @@
* <- CallExpression (exit)
* <- Program (exit)
*
* In order to supper that, our visitors will look like this:
* In order to support that, the final form of our visitor will look like this:
*
* var visitor = {
* NumberLiteral: {
@ -335,7 +333,7 @@
*
* Code generators work several different ways, some compilers will reuse the
* tokens from earlier, others will have created a separate representation of
* the code so that they can print node linearly, but from what I can tell most
* the code so that they can print nodes linearly, but from what I can tell most
* will use the same AST we just created, which is what were going to focus on.
*
* Effectively our code generator will know how to print all of the different
@ -711,16 +709,31 @@ function parser(tokens) {
* encounter a node with a matching type.
*
* traverse(ast, {
* Program(node, parent) {
* // ...
* Program: {
* enter(node, parent) {
* // ...
* },
* exit(node, parent) {
* // ...
* },
* },
*
* CallExpression(node, parent) {
* // ...
* CallExpression: {
* enter(node, parent) {
* // ...
* },
* exit(node, parent) {
* // ...
* },
* },
*
* NumberLiteral(node, parent) {
* // ...
* NumberLiteral: {
* enter(node, parent) {
* // ...
* },
* exit(node, parent) {
* // ...
* },
* },
* });
*/