Skip to content

An interpreter that can evaluate simple math calculations

Notifications You must be signed in to change notification settings

Ahmet-Oral/math-interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MathInterpreter

Final Project for class:

Formal Languages and Compilers

Instructor:

Dr inż. Maciej Gierdziewicz


The user input is analyzed in two sections of code called the lexer and parser, before finally being interpreted by the interpreter.

Lexer:
  • The lexer groups the input characters into small segments called tokens and identifies the type of each token.
  • The characters in the input for ex. 12 + 24 are grouped into the tokens: ‘NUMBER:12’, ‘PLUS’, and ‘NUMBER:24’.
  • Whitespace is ignored by the lexer.
  • The tokens are then passed on to the parser.
Parser:
  • The parser analyzes the sequence of tokens to determine what is intended to happen and in what order.
  • When the parser sees NUMBER, followed by PLUS, followed by NUMBER, it passes on that the two numbers should be added together In the case of a multiply operation added into the mix, the parser determines that the two numbers next to the multiply operator should be multiplied first before the addition takes place.
  • The represented as a tree, the result is then passed on to the interpreter.
Interpreter:

-The interpreter simply does what's intended according to the parser's results, and contains the code for all the different math operations. -It keeps calculating according to priority and keeps updating the result until there is no more operation and finally prints out the result.

About

An interpreter that can evaluate simple math calculations

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages