El AST para el ejemplo array.egg
➜ prefix-lang git:(master) ✗ cat test/examples/array.egg
do(
def(x, arr(arr(1,4),5,7)),
print([](x,0)), # [1,4]
print([](x,1)) # 5
)
El ejecutable bin/eggc.js
deberá producir un fichero JSON con el ast:
✗ bin/eggc.js test/examples/array.egg -o test/ast/array.json
Puede ver los contenidos del ast:
{
"type": "apply",
"operator": {
"type": "word",
"offset": 0,
"lineBreaks": 0,
"line": 1,
"col": 1,
"name": "do"
},
"args": [
{
"type": "apply",
"operator": {
"type": "word",
"offset": 6,
"lineBreaks": 0,
"line": 2,
"col": 3,
"name": "def"
},
"args": [
{
"type": "word",
"offset": 10,
"lineBreaks": 0,
"line": 2,
"col": 7,
"name": "x"
},
{
"type": "apply",
"operator": {
"type": "word",
"offset": 13,
"lineBreaks": 0,
"line": 2,
"col": 10,
"name": "arr"
},
"args": [
{
"type": "apply",
"operator": {
"type": "word",
"offset": 17,
"lineBreaks": 0,
"line": 2,
"col": 14,
"name": "arr"
},
"args": [
{
"type": "value",
"value": 1,
"raw": "1"
},
{
"type": "value",
"value": 4,
"raw": "4"
}
]
},
{
"type": "value",
"value": 5,
"raw": "5"
},
{
"type": "value",
"value": 7,
"raw": "7"
}
]
}
]
},
{
"type": "apply",
"operator": {
"type": "word",
"offset": 35,
"lineBreaks": 0,
"line": 3,
"col": 3,
"name": "print"
},
"args": [
{
"type": "apply",
"operator": {
"type": "word",
"offset": 41,
"lineBreaks": 0,
"line": 3,
"col": 9,
"name": "[]"
},
"args": [
{
"type": "word",
"offset": 44,
"lineBreaks": 0,
"line": 3,
"col": 12,
"name": "x"
},
{
"type": "value",
"value": 0,
"raw": "0"
}
]
}
]
},
{
"type": "apply",
"operator": {
"type": "word",
"offset": 61,
"lineBreaks": 0,
"line": 4,
"col": 3,
"name": "print"
},
"args": [
{
"type": "apply",
"operator": {
"type": "word",
"offset": 67,
"lineBreaks": 0,
"line": 4,
"col": 9,
"name": "[]"
},
"args": [
{
"type": "word",
"offset": 70,
"lineBreaks": 0,
"line": 4,
"col": 12,
"name": "x"
},
{
"type": "value",
"value": 1,
"raw": "1"
}
]
}
]
}
]
}