ArcaneScript is a custom programming language developed to explore language design and interpretation. This project includes the development of both the ArcaneScript language and its online Runner.
Description:
This pull request addresses the issue of missing else-if functionality in ArcaneScript's grammar and its IfElse class implementation. The changes made enhance the script's conditional control structures to support nested conditions with else-if, improving the script's flexibility and aligning it with common programming syntax.
Closes #6
Changes Made:
Grammar Update: Modified ArcaneGrammar7.grm to add support for else-if conditions.
Added new grammar rules for else-if and else-if-else scenarios.
New rules:
| if '(' <Expression> ')' start <Statements> end else if '(' <Expression> ')' start <Statements> end
| if '(' <Expression> ')' start <Statements> end else if '(' <Expression> ')' start <Statements> end else start <Statements> end
IfElse.java Update:
Updated the @ProcessRule annotation in IfElse.java to include new else-if grammar rules.
Added new fields elseIfCondition and elseIfStatements to handle else-if conditions.
Enhanced the execute() method to evaluate else-if conditions.
Revised the constructor to handle reduction sizes (7, 11, 15, or 19) to correctly parse and process if, if-else, if-else-if, and if-else-if-else structures.
Code Changes Summary:
@ProcessRule(rule={
"<Statement> ::= if ( <Expression> ) start <Statements> end",
"<Statement> ::= if ( <Expression> ) start <Statements> end else start <Statements> end",
"<Statement> ::= if ( <Expression> ) start <Statements> end else if ( <Expression> ) start <Statements> end",
"<Statement> ::= if ( <Expression> ) start <Statements> end else if ( <Expression> ) start <Statements> end else start <Statements> end"
})
Testing Instructions:
Update ArcaneGrammar7.grm with the new rules.
Regenerate the parser if required.
Replace the IfElse.java file with the updated version provided in this PR.
Build the project.
Run the following code to validate the changes:
a = true;
if(a==true){
a = false;
} else if(a==false){
a = true;
}
Expected Output:
Execution complete!
Checklist:
[x] Grammar file updated with new else-if rules.
[x] IfElse.java updated with support for else-if.
[x] Unit tests executed and passed.
[x] Verified output of sample test cases as expected.
After running some tests, it seems that, aside from simple print statements, nothing else is working. This issue has been occurring since your last PR, so I’ll be reverting it until the problems are fixed.
Description: This pull request addresses the issue of missing else-if functionality in ArcaneScript's grammar and its
IfElse
class implementation. The changes made enhance the script's conditional control structures to support nested conditions with else-if, improving the script's flexibility and aligning it with common programming syntax.Closes #6
Changes Made:
Grammar Update: Modified
ArcaneGrammar7.grm
to add support for else-if conditions.IfElse.java Update:
@ProcessRule
annotation inIfElse.java
to include new else-if grammar rules.elseIfCondition
andelseIfStatements
to handle else-if conditions.execute()
method to evaluate else-if conditions.Code Changes Summary:
Testing Instructions:
ArcaneGrammar7.grm
with the new rules.IfElse.java
file with the updated version provided in this PR.Run the following code to validate the changes:
Expected Output:
Checklist:
IfElse.java
updated with support for else-if.