Skip to content

Commit

Permalink
creating template for egg-oop-parser lab
Browse files Browse the repository at this point in the history
  • Loading branch information
crguezl committed Apr 20, 2022
0 parents commit b9b0181
Show file tree
Hide file tree
Showing 194 changed files with 18,098 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules/
package-lock.json
please-*
crguezl-egg
moo-ignore
egg-parser-solution
docs/coverage
oop-evm-releases
.nyc_output
bin/evm
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

See <https://ull-esit-gradoii-pl.github.io/practicas/egg-parser.html> for a former description of the language

Go to <https://github.com/crguezl/oop-evm-releases> to download releases of evm for mac, linux and windows that are mostly compatible with this version of the parser. Specifically here: <https://github.com/crguezl/oop-evm-releases/releases/tag/v1.1.0>

See file `/src/egg.ne` to see the syntax of this version that has support for objects and methods via brackets and dots.

Have a look at the `examples` folder.
4 changes: 4 additions & 0 deletions bin/egg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
bin/eggc.js $1.egg
# add in this folder the evm executable with oop extensions
bin/evm $1.json
59 changes: 59 additions & 0 deletions bin/eggc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env node
/**
* @description A executable to be able to compile eggc lang files
* @author XXXX <aluXXXX@ull.edu.es>
* @since XX/XX/20XX
*/

'use strict';

const fs = require('fs');
const {program} = require('commander');
const { parseFromFile } = require("../src/parse.js");

const {version} = require('../package.json');

/**
* A function that compiles a eggc file
* @param {string} origin The name of the origin file
* @param {string} destination The name of the destination file
* @throws Will throw if there are errors in the program or if the files
* can't be opened
*/
const compile = (origin, destination = undefined) => {
if (destination == undefined) {
destination = origin.match(/^[^\.]*/)[0] + '.json';
}

const ast = parseFromFile(origin);

//console.log(ast);
const astString = JSON.stringify(ast, null, 2);

fs.writeFileSync(destination, astString);
};

program
.version(version)
.arguments('<origin>')
.option(
'-o, --out <destination>', 'Path for output file. If it isn\'t ' +
'specified the path of the origin file will be used,' +
'changing the extension to .json',
)
.description(
'Compile a Egg lang file',
{
origin: 'The path of the file to compile',
},
)
.action((origin, options) => {
try {
compile(origin, options.out);
} catch (err) {
console.log('There was an error: ' + err.message);
}
});

program.parse(process.argv);

Empty file added docs/.gitignore
Empty file.
1 change: 1 addition & 0 deletions examples/.eggtoken
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
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
4 changes: 4 additions & 0 deletions examples/array-dot.egg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
do(
def(a, [[1,2],3]),
print(a.0.1)
)
119 changes: 119 additions & 0 deletions examples/array-dot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"type": "apply",
"operator": {
"type": "word",
"line": 1,
"col": 1,
"length": 2,
"name": "do"
},
"args": [
{
"type": "apply",
"operator": {
"type": "word",
"line": 2,
"col": 5,
"length": 3,
"name": "def"
},
"args": [
{
"type": "word",
"line": 2,
"col": 9,
"length": 1,
"name": "a"
},
{
"type": "apply",
"operator": {
"type": "word",
"length": 5,
"name": "array"
},
"args": [
{
"type": "apply",
"operator": {
"type": "word",
"line": 2,
"col": 14,
"length": 5,
"name": "array"
},
"args": [
{
"type": "value",
"value": 1,
"line": 2,
"col": 14,
"length": 1
},
{
"type": "value",
"value": 2,
"line": 2,
"col": 16,
"length": 1
}
]
},
{
"type": "value",
"value": 3,
"line": 2,
"col": 19,
"length": 1
}
]
}
]
},
{
"type": "apply",
"operator": {
"type": "word",
"line": 3,
"col": 5,
"length": 5,
"name": "print"
},
"args": [
{
"type": "property",
"operator": {
"type": "property",
"operator": {
"type": "word",
"line": 3,
"col": 11,
"length": 1,
"name": "a"
},
"args": [
{
"type": "value",
"value": "0",
"line": 3,
"col": 13,
"length": 3,
"raw": "\"0\""
}
]
},
"args": [
{
"type": "value",
"value": "1",
"line": 3,
"col": 14,
"length": 3,
"raw": "\"1\""
}
]
}
]
}
]
}
5 changes: 5 additions & 0 deletions examples/array-error.egg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
do(
def(x, array(1, array(2,3))),
print(element(x,-1,4)) # Error
)

121 changes: 121 additions & 0 deletions examples/array-error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"type": "apply",
"operator": {
"type": "word",
"line": 1,
"col": 1,
"length": 2,
"name": "do"
},
"args": [
{
"type": "apply",
"operator": {
"type": "word",
"line": 2,
"col": 3,
"length": 3,
"name": "def"
},
"args": [
{
"type": "word",
"line": 2,
"col": 7,
"length": 1,
"name": "x"
},
{
"type": "apply",
"operator": {
"type": "word",
"line": 2,
"col": 10,
"length": 5,
"name": "array"
},
"args": [
{
"type": "value",
"value": 1,
"line": 2,
"col": 16,
"length": 1
},
{
"type": "apply",
"operator": {
"type": "word",
"line": 2,
"col": 19,
"length": 5,
"name": "array"
},
"args": [
{
"type": "value",
"value": 2,
"line": 2,
"col": 25,
"length": 1
},
{
"type": "value",
"value": 3,
"line": 2,
"col": 27,
"length": 1
}
]
}
]
}
]
},
{
"type": "apply",
"operator": {
"type": "word",
"line": 3,
"col": 3,
"length": 5,
"name": "print"
},
"args": [
{
"type": "apply",
"operator": {
"type": "word",
"line": 3,
"col": 9,
"length": 7,
"name": "element"
},
"args": [
{
"type": "word",
"line": 3,
"col": 17,
"length": 1,
"name": "x"
},
{
"type": "value",
"value": -1,
"line": 3,
"col": 19,
"length": 2
},
{
"type": "value",
"value": 4,
"line": 3,
"col": 22,
"length": 1
}
]
}
]
}
]
}
5 changes: 5 additions & 0 deletions examples/array-literal.egg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
do(
def(x, [1,4,5,7]),
print(x[0]), # [1,4]
print(x[1]) # 5
)

0 comments on commit b9b0181

Please sign in to comment.