amritrout / ArcaneScript

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.
https://arcanescript.netlify.app/
6 stars 3 forks source link

Fix: Syntax Error When Calling Functions with Variable Assignments in ArcaneScript #5

Closed thecloudcode closed 1 month ago

thecloudcode commented 1 month ago

Description

This pull request addresses the issue where calling a declared function using the invoke syntax results in a syntax error. The changes implement proper function invocation handling, allowing functions to be called as standalone statements and used within expressions.

Changes

  1. Updated ArcaneGrammar7.grm to explicitly allow function calls as statements
  2. Modified FunctionInvocation.java to handle both expression and statement function calls
  3. Updated ArcaneInterpreter.java to properly initialize and handle function invocations
  4. Adjusted Expression.java to support function calls within expressions
  5. Updated Statements.java to execute function invocations correctly

Implementation Details

ArcaneGrammar7.grm

Added a new rule to allow function calls as statements:

<Statement> ::= Identifier '(' <OptionalArgumentList> ')' ';'

FunctionInvocation.java

ArcaneInterpreter.java

Expression.java

Statements.java

Testing

Tested with the following ArcaneScript code:

invoke methodName(){
  thecloudcode = 7;
}
methodName();

Output

Execution complete!

Confirmed that functions can now be called as statements and used within expressions without syntax errors.

image

Additional Notes

Checklist

Closes #4