Shunting Yard Algorithm

A Java implementation of Dijkstra's Shunting Yard algorithm that converts mathematical infix expressions into postfix (Reverse Polish Notation). Supports variables, negative and decimal numbers, mathematical functions (sin, cos, tan), and includes a postfix evaluator for computing results. Features graph plotting by generating PPM images for visualizing functions like sine waves.

Java
Shunting Yard Algorithm screenshot 1

About This Project

Implemented Dijkstra's Shunting Yard algorithm with a stack-based approach to parse infix expressions, handle operator precedence and associativity, support mathematical functions, and convert to postfix notation. Added an evaluator and PPM image generator for function visualization.

Parser tokenizes input expressions, Shunting Yard algorithm processes tokens using operator and output stacks, postfix evaluator computes results using a value stack, and PPM generator creates pixel-based images for graph plotting.

Challenges

  • Correctly handling operator precedence and associativity
  • Supporting both unary and binary operators (especially negative numbers)
  • Implementing function calls within the expression parser
  • Generating accurate graph plots from mathematical expressions

Key Learnings

  • Deep understanding of compiler design and expression parsing
  • Stack-based algorithm implementation and optimization
  • Handling edge cases in mathematical expression evaluation
  • Image generation using the PPM format
Shunting Yard Algorithm | Girish Oemrawsingh