ajout de Sheebr + support de shutdown + auto install kernel

This commit is contained in:
Marc
2021-11-27 13:51:55 +01:00
parent a40aa1c153
commit 7480c8efc8
30 changed files with 1743 additions and 45 deletions
@@ -0,0 +1,5 @@
let environment = {
path: ["/sheebr", "/usr/bin"]
}
module.exports = environment
+57
View File
@@ -0,0 +1,57 @@
const { isAlpha } = require('./utils')
class Lexer{
constructor(source){
this.tokens = [];
this.current = 0;
this.start = 0;
this.source = source
}
scanTokens(){
while(this.current < this.source.length){
this.start = this.current
this.scanToken()
}
return this.tokens;
}
scanToken(){
if(this.source[this.current] == "\""){
this.string()
}
else{
let content = ""
while(this.source[this.current] != ' ' && this.source[this.current] != '\n' && this.current < this.source.length ){
content += this.source[this.current];
this.current++;
}
this.tokens.push(content)
}
this.current++;
}
string(){
this.current++;
let content = ""
while(this.source[this.current] != "\"" && this.current < this.source.length){
content += this.source[this.current];
this.current++;
}
this.tokens.push(content)
}
addToken(tokenType, value=""){
this.tokens.push(Token(tokenType, value))
}
}
module.exports = {
Lexer
}
File diff suppressed because it is too large Load Diff
+31
View File
@@ -0,0 +1,31 @@
async function getline(str) {
process.stdout.write(str)
process.stdin.resume();
process.stdin.setEncoding('utf8')
let line = ""
return new Promise((res, rej) => {
process.stdin.on('data', function(chunk) {
line += chunk
if (chunk.toString('utf-8').endsWith('\n')) {
process.stdin.pause()
res(line.substring(0, line.length -1))
}
})
process.stdin.on('error', function(err) {
rej(err)
})
})
}
function isAlpha(str){
return /^[a-zA-Z]*$/.test(str);
}
module.exports = {
isAlpha, getline
}