Skip to content

Instantly share code, notes, and snippets.

@sergi
Created August 4, 2010 18:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergi/508528 to your computer and use it in GitHub Desktop.
Save sergi/508528 to your computer and use it in GitHub Desktop.
/*
AST tree generated from parsing the following Design By Numbers program:
paper 30
repeat A 0 300
{
pen 50
line 0 55 100 55
line 0 20 100 20
pen 100
line (A*2) 0 (A*2) 20
line (A/3) 55 (A/3) 100
paper 30
}
You can find the blog article that explains it at
http://www.sergimansilla.com/blog/writing-a-javascript-interpreter-for-dbn-using-canvas-I/
*/
[
{
"type": "command",
"name": "paper",
"args": [
{
"type": "string",
"value": "30"
}
]
},
{
"type": "command",
"name": "repeat",
"args": [
{
"type": "string",
"value": "A"
},
{
"type": "string",
"value": "0"
},
{
"type": "string",
"value": "300"
}
],
"block": [
{
"type": "command",
"name": "pen",
"args": [
{
"type": "string",
"value": "50"
}
]
},
{
"type": "command",
"name": "line",
"args": [
{
"type": "string",
"value": "0"
},
{
"type": "string",
"value": "55"
},
{
"type": "string",
"value": "100"
},
{
"type": "string",
"value": "55"
}
]
},
{
"type": "command",
"name": "line",
"args": [
{
"type": "string",
"value": "0"
},
{
"type": "string",
"value": "20"
},
{
"type": "string",
"value": "100"
},
{
"type": "string",
"value": "20"
}
]
},
{
"type": "command",
"name": "pen",
"args": [
{
"type": "string",
"value": "100"
}
]
},
{
"type": "command",
"name": "line",
"args": [
{
"cmd": "*",
"args": [
{
"type": "string",
"value": "A"
},
{
"type": "string",
"value": "2"
}
]
},
{
"type": "string",
"value": "0"
},
{
"cmd": "*",
"args": [
{
"type": "string",
"value": "A"
},
{
"type": "string",
"value": "2"
}
]
},
{
"type": "string",
"value": "20"
}
]
},
{
"type": "command",
"name": "line",
"args": [
{
"cmd": "/",
"args": [
{
"type": "string",
"value": "A"
},
{
"type": "string",
"value": "3"
}
]
},
{
"type": "string",
"value": "55"
},
{
"cmd": "/",
"args": [
{
"type": "string",
"value": "A"
},
{
"type": "string",
"value": "3"
}
]
},
{
"type": "string",
"value": "100"
}
]
},
{
"type": "command",
"name": "paper",
"args": [
{
"type": "string",
"value": "30"
}
]
}
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment