https://github.com/innofang/calc
🎫A simple interpreter & command-line calculator written in Kotlin
https://github.com/innofang/calc
calculator command-line interpreter
Last synced: 11 months ago
JSON representation
🎫A simple interpreter & command-line calculator written in Kotlin
- Host: GitHub
- URL: https://github.com/innofang/calc
- Owner: InnoFang
- License: apache-2.0
- Created: 2016-02-15T16:00:38.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-05-13T01:40:23.000Z (over 7 years ago)
- Last Synced: 2025-01-10T09:20:38.174Z (about 1 year ago)
- Topics: calculator, command-line, interpreter
- Language: Kotlin
- Homepage:
- Size: 146 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# calc
A simple command-line calculator written in Kotlin
**PS** this is a practice project of an interpreter, to implement a command-line calculator, I design a series of grammar to do so instead of using _reverse Polish notation (RPN)_
# Grammar
```
expr : factor (( PLUS | MINUS) factor) *
term : factor (( MUL | DIV ) factor) *
factor : (PLUS | MINUS) factor | INTEGER | LPAREN expr RPAREN
```
# Usage
open your terminal, and type
```
> $ git clone git@github.com:InnoFang/calc.git
> $ cd calc
> $ gradle build
```
Then, there is a file named `calc-1.0.0.jar` in the `build/libs`
```
> $ cd build/libs
> $ java -jar calc-1.0.0.jar
```
# Example
you can use like this
```
calc> 12
12
calc> 34 * 56
1904
calc> 1234 + 87123 - 19283
69074
calc> 22 * 12 - 172 + 56
148
calc> 345 / 5 * ( 234 - 92 ) + 66
9864
calc> 1 ------------ 2
3
calc> 2 ++++-----+++ 3
-1
```
# Reference
+ [lsbasi](https://github.com/rspivak/lsbasi)
this project gave me inspiration and idea, as well as help me a lot, thanks
# [License](https://github.com/InnoFang/calc/blob/master/LICENSE)
Copyright 2018 InnoFang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.