✨ create lexer class
This commit is contained in:
parent
83419929e4
commit
8e28475dc1
@ -97,7 +97,6 @@
|
|||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function(){
|
document.addEventListener("DOMContentLoaded", function(){
|
||||||
juicescript.parse(juice_program);
|
juicescript.parse(juice_program);
|
||||||
juicescript.run();
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
20
src/lexer.js
Normal file
20
src/lexer.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
class Juicescript_lexer {
|
||||||
|
/*
|
||||||
|
CONSTRUCTOR: Return new juicescript lexer for SOURCE with OPTIONS
|
||||||
|
*/
|
||||||
|
constructor(source, options){
|
||||||
|
// STORE SOURCE //
|
||||||
|
this.source = source;
|
||||||
|
|
||||||
|
|
||||||
|
// STORE IO ADAPTER //
|
||||||
|
this.io = options.io;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
MAIN: Run lexical analysis
|
||||||
|
*/
|
||||||
|
scan(){
|
||||||
|
/**/this.io.stderr.debug(this.source);
|
||||||
|
}
|
||||||
|
}
|
21
src/main.js
21
src/main.js
@ -26,19 +26,14 @@ class Juicescript {
|
|||||||
Parse given PROGRAM-STRING and store syntax tree
|
Parse given PROGRAM-STRING and store syntax tree
|
||||||
*/
|
*/
|
||||||
parse(program_string){
|
parse(program_string){
|
||||||
|
// DO SCANNING //
|
||||||
|
// get lexer
|
||||||
|
var lexer = new Juicescript_lexer(program_string, {
|
||||||
|
io: this.io
|
||||||
|
});
|
||||||
|
|
||||||
}
|
// run lexical analysis
|
||||||
|
var token_list = lexer.scan();
|
||||||
|
/**/console.log(token_list);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// DEBUG STUFFS //
|
|
||||||
run(){
|
|
||||||
this.io.stdout("stdout text");
|
|
||||||
this.io.stderr.debug("This debug is a test");
|
|
||||||
this.io.stderr.info("This info is a test");
|
|
||||||
this.io.stderr.warning("This warning is a test");
|
|
||||||
this.io.stderr.error("This error is a test");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user