From 97a6c673c6937b96611f3040a786ed2a47df4685 Mon Sep 17 00:00:00 2001 From: AndreiM Date: Sun, 14 Jul 2024 16:05:14 -0400 Subject: [PATCH] More Comments Added --- .cirrus.yml | 2 + src/Juka/REPL.cs | 21 ++++- src/JukaAzureFunction/JukaAzureFunction.cs | 10 +-- src/JukaCompiler/Compiler.cs | 1 - src/JukaCompiler/Expressions/Expr.cs | 89 ++++++++++++++++++++++ 5 files changed, 112 insertions(+), 11 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 759f4957..5e299b09 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -35,6 +35,8 @@ task: - GITHUB_TOKEN: ENCRYPTED[!b7770b286394d89374afd6ce2ef353693b8b922c6c0d6169c4e55fb926ea26507660d0759f6a2cdf2e2436e514742573!] - JUKA_TOKEN: Linux_X86 setup_script: + - dpkg --print-architecture + - dpkg --print-foreign-architectures - dpkg --add-architecture i386 - apt-get update - apt-get install -y software-properties-common diff --git a/src/Juka/REPL.cs b/src/Juka/REPL.cs index bb27f604..453eb175 100644 --- a/src/Juka/REPL.cs +++ b/src/Juka/REPL.cs @@ -46,6 +46,7 @@ public static async Task RunRepl() } } + // A method to initialize the REPL environment with specific configurations and setup. private static async Task InitializeRepl() { Console.Title = "Juka Programming Language"; @@ -71,17 +72,20 @@ private static async Task InitializeRepl() DisplayPrompt(); } + // Displays the prompt for the Juka REPL environment. It constructs a prompt string with Juka, its current version, and the current time, then uses AnsiConsole to markup and display the prompt. private static void DisplayPrompt() { string prompt = "[bold green]Juka[/]([red]" + CurrentVersion.GetVersion() + "[/]){" + DateTime.Now.ToString("HH:mm:ss") + "}> "; AnsiConsole.Markup(prompt); } + // A method that checks whether the input line is a command by checking if it starts with '!'. private static bool IsCommand(string line) { return line.StartsWith('!'); } + // Asynchronously handles different commands based on the input command string. private static async Task HandleCommandAsync(string command) { switch (command.Split(' ')[0].ToLower()) @@ -147,6 +151,7 @@ private static async Task HandleCommandAsync(string command) } } + // A method to handle user input in the REPL environment. private static void HandleUserInput(string userInput) { if (userInput.StartsWith("sub") || userInput.StartsWith("class")) @@ -178,6 +183,7 @@ private static void HandleUserInput(string userInput) } } + // Displays the menu with various commands and their descriptions in a table format using AnsiConsole. After displaying the menu, it calls the DisplayPrompt method to show the REPL prompt. private static void DisplayMenu() { Table table = new(); @@ -200,6 +206,7 @@ private static void DisplayMenu() DisplayPrompt(); } + // A method to clear the console, initialize a new compiler, reset the class or subroutine flag, clear the subroutine stack, set the starting data for the main subroutine, set the ending data, and display the prompt. private static void ClearConsole() { Console.Clear(); @@ -213,7 +220,7 @@ private static void ClearConsole() DisplayPrompt(); } - + // Displays the code present in the subRoutineStack in reverse order and then calls the DisplayPrompt method. private static void ListCode() { foreach (string? data in subRoutineStack.Reverse()) @@ -224,12 +231,14 @@ private static void ListCode() DisplayPrompt(); } + // A method to get the list of libraries for Juka. private static void GetLibraries() { // Implement your logic to get the list of libraries for Juka DisplayPrompt(); } + // Undoes the last command by popping a line from the subRoutineStack, pushing it to the redoStack, marking it as removed in the console, and displaying the prompt. private static void UndoLastCommand() { string templine = subRoutineStack.Pop(); @@ -238,6 +247,8 @@ private static void UndoLastCommand() DisplayPrompt(); } + + // A method to redo the last command, pushing the popped command from the redo stack to the subRoutineStack, marking it as added, and displaying the prompt. private static void RedoLastCommand() { string templine = redoStack.Pop(); @@ -246,12 +257,14 @@ private static void RedoLastCommand() DisplayPrompt(); } + // A method to update Juka asynchronously. private static async Task UpdateJuka() { await SelfUpdate.Update(); DisplayPrompt(); } + // A method to download a file asynchronously from the specified URL and display a message upon completion. private static async Task DownloadAFile(string url) { await SelfUpdate.DownloadURLAsync(url); @@ -260,7 +273,7 @@ private static async Task DownloadAFile(string url) } - + // Asynchronously restarts the application based on the provided type parameter. private static async void RestartApplication(string type) { IDictionary info = SelfUpdate.GetSystemInfo(); @@ -268,11 +281,14 @@ private static async void RestartApplication(string type) await SelfUpdate.Restart(jukaexepath,type); } + // Exits the REPL environment by terminating the application. private static void ExitRepl() { Environment.Exit(0); } + // Executes the subroutines present in the subRoutineStack by iterating in reverse order, appending each item to userDataToExecute, + // resetting the subRoutineStack, updating endData with the concatenated result, and finally displaying the prompt. private static void ExecuteSub() { StringBuilder userDataToExecute = new(); @@ -287,6 +303,7 @@ private static void ExecuteSub() DisplayPrompt(); } + // Executes a line of code by compiling and running it, then displays the output. private static void ExecuteLine() { string codeToExecute = startData + endData; diff --git a/src/JukaAzureFunction/JukaAzureFunction.cs b/src/JukaAzureFunction/JukaAzureFunction.cs index 0d3b0f09..e4d7c15e 100644 --- a/src/JukaAzureFunction/JukaAzureFunction.cs +++ b/src/JukaAzureFunction/JukaAzureFunction.cs @@ -10,15 +10,9 @@ namespace JukaAzureFunction; -public class JukaAzureFunction +public class JukaAzureFunction(ILogger log) { - private ILogger logger; - - public JukaAzureFunction(ILogger log) - { - logger = log; - } - + private ILogger logger = log; [Function("JukaAzureFunction")] [OpenApiOperation(operationId: "Run", tags: new[] { "name" })] diff --git a/src/JukaCompiler/Compiler.cs b/src/JukaCompiler/Compiler.cs index d7c94d2e..5ce3adba 100644 --- a/src/JukaCompiler/Compiler.cs +++ b/src/JukaCompiler/Compiler.cs @@ -69,7 +69,6 @@ public string CompileJukaCode(string data, bool isFile = true) //This code defines a method named Compile that compiles a list of statements using a JukaInterpreter and a Resolver. //It sets up a main method runtime hook, redirects console output to capture it, interprets the statements, and returns the console output as a string. //If an exception occurs during interpretation, it returns the exception message. - private string Compile(List statements) { JukaInterpreter interpreter = new(services: _serviceProvider); diff --git a/src/JukaCompiler/Expressions/Expr.cs b/src/JukaCompiler/Expressions/Expr.cs index f5f046f6..f0483c64 100644 --- a/src/JukaCompiler/Expressions/Expr.cs +++ b/src/JukaCompiler/Expressions/Expr.cs @@ -4,27 +4,103 @@ namespace JukaCompiler.Expressions { internal abstract class Expr { + /// + /// Interface for visiting different expression types + /// internal interface IVisitor { + /// + /// Visit an Assign expression + /// R VisitAssignExpr(Assign expr); + + /// + /// Visit a Binary expression + /// R VisitBinaryExpr(Binary expr); + + /// + /// Visit a Call expression + /// R VisitCallExpr(Call expr); + + /// + /// Visit a Get expression + /// R VisitGetExpr(Get expr); + + /// + /// Visit a Grouping expression + /// R VisitGroupingExpr(Grouping expr); + + + /// + /// Visit a Literal expression + /// R VisitLiteralExpr(Literal expr); + + /// + /// Visit a Logical expression + /// R VisitLogicalExpr(Logical expr); + + /// + /// Visit a Set expression + /// R VisitSetExpr(Set expr); + + /// + /// Visit a Super expression + /// R VisitSuperExpr(Super expr); + + /// + /// Visit a This expression + /// R VisitThisExpr(This expr); + + /// + /// Visit an Unary expression + /// R VisitUnaryExpr(Unary expr); + + /// + /// Visit a Variable expression + /// R VisitVariableExpr(Variable expr); + + /// + /// Visit a LexemeTypeLiteral expression + /// R VisitLexemeTypeLiteral(LexemeTypeLiteral expr); + + /// + /// Visit an ArrayDeclaration expression + /// R VisitArrayExpr(ArrayDeclarationExpr expr); + + /// + /// Visit a NewDeclaration expression + /// R VisitNewExpr(NewDeclarationExpr expr); + + /// + /// Visit an ArrayAccess expression + /// R VisitArrayAccessExpr(ArrayAccessExpr expr); + + /// + /// Visit a DeleteDeclaration expression + /// R VisitDeleteExpr(DeleteDeclarationExpr expr); } + + + + + internal abstract R Accept(IVisitor visitor); private Lexeme? expressionLexeme; @@ -39,16 +115,29 @@ internal string ExpressionLexemeName { get => this.expressionLexeme?.ToString()!; } + + + /// + /// Represents an assignment expression in the abstract syntax tree + /// internal class Assign : Expr { internal Expr value; + + /// + /// Initializes a new instance of the Assign class with the provided expression lexeme and value + /// internal Assign(Lexeme ExpressionLexeme, Expr value) { this.expressionLexeme = ExpressionLexeme; this.value = value; } + + /// + /// Accepts a visitor and calls the VisitAssignExpr method on it + /// internal override R Accept(IVisitor visitor) { return visitor.VisitAssignExpr(this);