GameMaker (2.0 - 2.2.x)
Icon

Expression Parser

Archer

You must be logged in to obtain assets

Description

A simple expression parser, that allows parsing and evaluating strings that describe mathematical operations.

The following operators are included by default:

  • minus (-)
  • unary minus (-)
  • plus (+)
  • unary plus (+) (doesn't do much, purely added for support)
  • increment (++)
  • multiplication (*)
  • division (/)
  • modulo (%)
  • power (^)

It will also detect and warn about mismatching/missing parentheses, in which case it will always return a configurable error value.

It's basically a slightly modified implementation of the shunting yard algorithm by Dijkstra, with the addition of an evaluator for the post-fix notation it creates and a tokenizer for input strings.

Adding new operators has been overhauled in version 1.4.0. To add an operator, simply duplicate one of the existing ones in the Operator folder and modify it entirely to your needs. The top part determines the operator's properties (symbol, precedence, etc), the bottom part defines the operation. It should automatically be found as long as its file name has the prefix "EP_OP".

Example usage:

evaluate_expression("(1+2)^3") 
output: 27

End User Licence Agreement (EULA).

Age Rating: 4+

Version

GMS2 - Version 1.4.6. Published July 11, 2018

  • Fixed parsing bug where unary operator detection malfunctioned when having numbers with more than one digit
Loading, please wait

Package contents

Loading, please wait

What is the issue?

Loading, please wait