This repository was archived by the owner on Mar 31, 2025. It is now read-only.
MathScript v1.0.0
·
33 commits
to main
since this release
⚠️ Always download the installer from the latest release ⚠️
Notes
The comments in the code are just placeholders, MathScript v1.0.0 doesn't support comments.
1. Basic Syntax
- Case Sensitivity: MathScript is case-sensitive.
- Keywords: MathScript utilizes keywords for control flow and function definition. Keywords are:
and
or
not
if
elif
else
for
to
step
while
func
then
pass
end
- Identifiers: Identifiers are used to name variables and functions. They can contain letters, digits, and underscores (
_
), but cannot start with a digit. - Comments: Comments are not supported by MathScript v1.0.0.
2. Data Types
MathScript supports the following data types:
- NullType:
none
,null
orundefined
. - Boolean:
true
orfalse
. - Integer: Whole numbers (e.g.,
1
,2
,-5
). - Decimal: Numbers with decimal points (e.g.,
1.5
,-2.75
). - Complex: Numbers with real and imaginary parts (e.g.,
2+3i
,-4-1i
). Note:i
is used for the imaginary unit. - String: Sequences of characters enclosed in double quotes (
""
), single quotes (''
), or backticks (``
) (e.g.,"Hello"
,'World'
,`\ This is a raw string`
). - List: Ordered collections of values enclosed in parentheses
()
(e.g.,('Bob',)
,(1, 2, 3)
). - Function: User-defined functions.
- BuiltInFunction: Built-in functions.
3. Operators
MathScript supports various operators:
- Arithmetic:
+
(addition)-
(subtraction)*
(multiplication)/
(division)^
(exponentiation)
- Comparison:
==
(equals)!=
(not equals)<
(less than)>
(greater than)<=
(less than or equal to)>=
(greater than or equal to)
- Logical:
and
(logical AND)or
(logical OR)not
(logical NOT)
- Subscript:
_
(subscripting for strings and lists, when using it with variables enclose the variables in parenthesis like this:(lst)_(index)
)
- Function Call:
(
)
(function invocation)
- Assignment:
=
(assigns a value to a variable)
- Inline function Definition:
=>
(defines the return value of a function)
4. Control Flow
MathScript includes the following control flow statements:
-
if
statement:if condition then if_true else _else
if condition then # Code to execute if condition is true else # Code to execute if condition is false end
-
elif
statement:if condition then if_true elif another_condition then if_other_true else _else
if condition then # Code to execute if condition is true elif another_condition then # Code to execute if another_condition is true else # Code to execute if neither condition is true end
-
for
loop:for variable = start to _end step _step then iteration # => (iteration1, iteration2, ...)
for variable = start to _end step _step then # Code to execute in the loop end
step
value is optional, and defaults to 1. -
while
loop:while condition then iteration # => (iteration1, iteration2, ...)
while condition then # Code to execute in the loop end
-
func
function definition:func function_name(arg1, arg2 = value) => return_value
func function_name(arg1, arg2 = value) # Code to execute in the function end
Function definition supports optional arguments with default values.
5. Built-in Functions
MathScript offers built-in functions:
print()
: Prints value to the console. Acceptssep
andend_char
arguments for formatting.input()
: Takes input from the user. Acceptsplaceholder
argument for prompting.clear()
: Clears the console.exit()
: Exits the program. Acceptscode
argument for exit code.type()
: Returns the type of an object as a string.sin()
: Returns the sine of an angle (complex numbers supported).cos()
: Returns the cosine of an angle (complex numbers supported).e
: A constant representing the value of e.pi
: A constant representing the value of pi.inf
: A constant representing positive infinity.nan
: A constant representing 'Not a Number'.
6. Execution
A MathScript program is executed using the mathscript
command.
mathscript <your_program.mscr>
: Executes a.mscr
file.mathscript
: Starts an interactive shell.