This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from DemonExposer/requires
Requires
- Loading branch information
Showing
5 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Interpreter.Builtin.Functions; | ||
using Interpreter.Types; | ||
using Interpreter.Types.Function; | ||
using TrieDictionary; | ||
using Array = Interpreter.Types.Array; | ||
using Object = Interpreter.Types.Object; | ||
using Boolean = Interpreter.Types.Comparable.Boolean; | ||
|
||
namespace Interpreter.Tokens.Statements.Unary; | ||
|
||
public class RequireStatement : UnaryStatement { | ||
private List<Token> importFile = new List<Token>(); | ||
|
||
public RequireStatement() { | ||
Symbol = "require"; | ||
} | ||
|
||
public override Object Evaluate(List<TrieDictionary<Object>> vars) { | ||
TrieDictionary<Object> variables = new TrieDictionary<Object>(); | ||
variables["print"] = Program.Vars["print"]; | ||
variables["read"] = Program.Vars["read"]; | ||
variables["false"] = Program.Vars["false"]; | ||
variables["true"] = Program.Vars["true"]; | ||
variables["args"] = Program.Vars["args"]; | ||
variables["null"] = Program.Vars["null"]; | ||
variables["File"] = Program.Vars["File"]; | ||
variables["export"] = new Dictionary(); | ||
|
||
List<TrieDictionary<Object>> variableList = new List<TrieDictionary<Object>> {variables}; | ||
importFile.ForEach(t => t.Evaluate(variableList)); | ||
return variables["export"]; | ||
} | ||
|
||
public void ParseImportFile() { | ||
string[] lines = File.ReadAllLines(Child.Str + ".gsl"); | ||
for (int i = 0; i < lines.Length; i++) { | ||
CheckedString[] lexedLine = Lexer.Lex(lines[i], i + 1); | ||
|
||
lexedLine = Parser.CheckComment(lexedLine); | ||
if (lexedLine.Length == 0) | ||
continue; | ||
|
||
Token[] tokenizedLine = Tokenizer.Tokenize(lexedLine); | ||
|
||
importFile.Add(Parser.Parse(tokenizedLine, Parser.GetTopElementIndex(tokenizedLine, 0, true), lines, ref i, 0)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
decl Math = require math | ||
|
||
print(Math.abs(5) : " " : Math.abs(-5)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function abs(num) { | ||
on (num < 0) { | ||
return (-num) | ||
} | ||
|
||
return (num) | ||
} | ||
|
||
export = {"abs": abs} |