Git Product home page Git Product logo

calculator-col226-'s Introduction

COL226-Assignment3

Calculator

Submitted by: Anshik Sahu

Instructions to use:

How to start-

  1. Open terminal.
  2. Go to the directory containing all files.
  3. Run "sudo sml rational.sml".
  4. Type your password and press enter key.

OR

  1. Run "sudo sml".
  2. Type your password and press enter key.
  3. Run "CM.make "makefile.cm";".
  4. Run "Calc.parse();".

How to use-

  1. Type your expression, add a semicolon at the end then press enter.
  2. Your expression can include:
    • Binary operators: "+", "-", "*" and "/"
    • Negation: "~" (Warning: Not a operator, can only be used on values)
    • Integers: Use "~" instead of "-" to denote negative numbers.
    • Decimals: In the fractional-normal form.(Use "~" instead of "-" to denote negative numbers)

Grammar for representing Rationals

Rational ::= "~" rational | rational
rational ::= integer | decimal | fraction
integer ::= digit | digitinteger
decimal ::= integer "." integer "(" integer ")" | "." integer "(" integer ")" | integer "." "(" integer ")"
fraction ::= integer "/" nonzerointeger
nonzerointeger ::= integer positivedigits
positivedigits ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
digit ::= positivedigits | "0"

Grammar used for representing values in parser

NUM ::= integer | "" integer | decimal | "" decimal
integer::= digit | digit integer
decimal::= integer "." integer "(" integer ")" | "." integer "(" integer ")" | integer "." "(" integer ")"
digit ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"

(fractions are not implemented in parser as their functionality is obtained through dividing)

Grammar for arithmetic

Start ::= Expression ";"
Expression ::= Term | Term "+" Term | Term "-" Term
Term ::= Rat | Rat "*" Rat | Rat "/" Rat
Rat ::= RAT | variable
RAT ::= Rational | "(" Expression ")"
variable ::= alphabet | alphabet integer | alphabet integer variable
alphabet ::= “A” | “B” | “C” | “D” | “E” | “F” | “G” | “H” | “I” | “J” | “K” | “L” | “M” | “N” | “O” |
“P” | “Q” | “R” | “S” | “T” | “U” | “V” | “W” | “X” | “Y” | “Z” | “a” | “b” | “c” | “d” |
“e” | “f” | “g” | “h” | “i” | “j” | “k” | “l” | “m” | “n” | “o” | “p” | “q” | “r” | “s” |
“t” | “u” | “v” | “w” | “x” | “y” | “z”

Grammar used for representing expressions in parser

START ::= EXP ";" EXP ::= NUM | EXP "+" EXP | EXP "-" EXP | EXP "*" EXP | EXP "/" EXP | "(" EXP ")"
(The rules for associativity and precedence are mentioned separately in the parser)

Acknowledgements

I have used the resources present in the SMLNJ Documentation of ML lex and ML yacc. Namely the base structure for the parser as present in the Rational_parser.lex, Rational_parser.grm, Rational_parser.sml files is taken from the above mentioned source.

calculator-col226-'s People

Contributors

anshiksahu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.