Skip to content

Commit

Permalink
More Comments Added
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAndreiM committed Jul 14, 2024
1 parent 123d19f commit 97a6c67
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions src/Juka/REPL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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())
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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())
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -260,19 +273,22 @@ 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<string, string> info = SelfUpdate.GetSystemInfo();
string jukaexepath = info["dir"] + info["name"] + info["extension"];
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();
Expand All @@ -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;
Expand Down
10 changes: 2 additions & 8 deletions src/JukaAzureFunction/JukaAzureFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@

namespace JukaAzureFunction;

public class JukaAzureFunction
public class JukaAzureFunction(ILogger<JukaAzureFunction> log)
{
private ILogger<JukaAzureFunction> logger;

public JukaAzureFunction(ILogger<JukaAzureFunction> log)
{
logger = log;
}

private ILogger<JukaAzureFunction> logger = log;

[Function("JukaAzureFunction")]
[OpenApiOperation(operationId: "Run", tags: new[] { "name" })]
Expand Down
1 change: 0 additions & 1 deletion src/JukaCompiler/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Statement> statements)
{
JukaInterpreter interpreter = new(services: _serviceProvider);
Expand Down
89 changes: 89 additions & 0 deletions src/JukaCompiler/Expressions/Expr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,103 @@ namespace JukaCompiler.Expressions
{
internal abstract class Expr
{
/// <summary>
/// Interface for visiting different expression types
/// </summary>
internal interface IVisitor<R>
{
/// <summary>
/// Visit an Assign expression
/// </summary>
R VisitAssignExpr(Assign expr);

/// <summary>
/// Visit a Binary expression
/// </summary>
R VisitBinaryExpr(Binary expr);

/// <summary>
/// Visit a Call expression
/// </summary>
R VisitCallExpr(Call expr);

/// <summary>
/// Visit a Get expression
/// </summary>
R VisitGetExpr(Get expr);

/// <summary>
/// Visit a Grouping expression
/// </summary>
R VisitGroupingExpr(Grouping expr);


/// <summary>
/// Visit a Literal expression
/// </summary>
R VisitLiteralExpr(Literal expr);

/// <summary>
/// Visit a Logical expression
/// </summary>
R VisitLogicalExpr(Logical expr);

/// <summary>
/// Visit a Set expression
/// </summary>
R VisitSetExpr(Set expr);

/// <summary>
/// Visit a Super expression
/// </summary>
R VisitSuperExpr(Super expr);

/// <summary>
/// Visit a This expression
/// </summary>
R VisitThisExpr(This expr);

/// <summary>
/// Visit an Unary expression
/// </summary>
R VisitUnaryExpr(Unary expr);

/// <summary>
/// Visit a Variable expression
/// </summary>
R VisitVariableExpr(Variable expr);

/// <summary>
/// Visit a LexemeTypeLiteral expression
/// </summary>
R VisitLexemeTypeLiteral(LexemeTypeLiteral expr);

/// <summary>
/// Visit an ArrayDeclaration expression
/// </summary>
R VisitArrayExpr(ArrayDeclarationExpr expr);

/// <summary>
/// Visit a NewDeclaration expression
/// </summary>
R VisitNewExpr(NewDeclarationExpr expr);

/// <summary>
/// Visit an ArrayAccess expression
/// </summary>
R VisitArrayAccessExpr(ArrayAccessExpr expr);

/// <summary>
/// Visit a DeleteDeclaration expression
/// </summary>
R VisitDeleteExpr(DeleteDeclarationExpr expr);
}






internal abstract R Accept<R>(IVisitor<R> visitor);

private Lexeme? expressionLexeme;
Expand All @@ -39,16 +115,29 @@ internal string ExpressionLexemeName
{
get => this.expressionLexeme?.ToString()!;
}


/// <summary>
/// Represents an assignment expression in the abstract syntax tree
/// </summary>
internal class Assign : Expr
{
internal Expr value;


/// <summary>
/// Initializes a new instance of the Assign class with the provided expression lexeme and value
/// </summary>
internal Assign(Lexeme ExpressionLexeme, Expr value)
{
this.expressionLexeme = ExpressionLexeme;
this.value = value;
}


/// <summary>
/// Accepts a visitor and calls the VisitAssignExpr method on it
/// </summary>
internal override R Accept<R>(IVisitor<R> visitor)
{
return visitor.VisitAssignExpr(this);
Expand Down

0 comments on commit 97a6c67

Please sign in to comment.