Skip to content

vlad1k337/tinycalc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tinycalc

Tinycalc is a quick and dirty calculator REPL written in C99. It features a recursive-descent parser and tree-walk interpeter for math expressions.

Built mostly for educational purposes, and as a ground to build more complex interpreters.

Features

  • Binary operators (+, -, *, /, ^)
  • Bit manipulation (<<, >>, &, |, ~)
  • Parentheses "(", ")"
  • Standard functions (sin, abs, etc.)
  • Type-checking against integers and floating-point expressions
  • Follows C operator precedence

Example usage

> 1 - 2
-1
> (1+2)*4 + 10
22
> -1 * (-1 + 5)
-4

Grammar

<expr>         = <bitor> 
<bitor>        = <bitand> { "|" <bitand> }*
<bitand>       = <shifts> { "&" <shifts> }*
<shifts>       = <add_sub> { ("<<" | ">>") <add_sub> }*
<add_sub>      = <mult_div> { ("+" | "-") <mult_div> }*
<mult_div>     = <power> { ("*" | "/") <power> }*
<power>        = <unary> { "^" <unary> }*
<unary>        = ("-" | "~" | <func> ) <unary> | <primary>
<primary>      = "(" <expr> ")" | <number>

About

A tiny calculator REPL in C

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published