Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yasulab/lp-calculator
A calculator as a language processer
https://github.com/yasulab/lp-calculator
Last synced: 1 day ago
JSON representation
A calculator as a language processer
- Host: GitHub
- URL: https://github.com/yasulab/lp-calculator
- Owner: yasulab
- Created: 2011-05-31T08:28:25.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2011-05-31T08:34:45.000Z (over 13 years ago)
- Last Synced: 2024-10-10T09:24:05.161Z (about 1 month ago)
- Language: C
- Homepage: http://yasulab.blogspot.com/2008/06/calculator-with-lp-2.html
- Size: 93.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
Description
-----------
This program is a calculator which can run along this specification below.1. can use operands: +, -, *, /, %
2. can use Gauss's integer using branckets
3. can change priority of operation using parenthsis
4. can assign value to a valuable structured by alphabetsThe specification is implemented by this syntax rule below.
expression = ['-'] term {('+'|'-') term }
term = primary {('*'|'/'|'%') primary }
primary = character | figure | '(' expression ')' | '[' expression ']'
character = ID | ID '=' expression
figure = {number} ['.' {number}]
number = 0|1|2|3|4|5|6|7|8|9
ID = a|b|...|y|z|A|B|...|Y|ZSample Output
-------------
yohei@YOHEI-note ~/wl/calc
$ gcc calc.c -o calcyohei@YOHEI-note ~/wl/calc
$ ./calc/* General Operations */
# +2-1
>> 1.000000# -2-1
>> -3.000000# 2+5*10
>> 52.000000# 2*5+10
>> 20.000000# 2*(5+10)
>> 30.000000# 3/2
>> 1.500000# 5.5/2.2
>> 2.500000# [5.5/2.2]
>> 2.000000# [5/(1+1)]
>> 2.000000# 2/1+6%3
>> 2.000000# 4.9%0.3
>> 0.100000# two=2
two holds 2.000000
>> 2.000000# five=5
five holds 5.000000
>> 5.000000# ten=10
ten holds 10.000000
>> 10.000000# hundred=100
hundred holds 100.000000
>> 100.000000# -(ten+five/two)*two*hundred
>> -2500.000000#
shut down this program...
yohei@YOHEI-note ~/wl/calc
$/* Exception Handler*/
# 1+ 2++ 4
error: incorrect position of symbol.
1+ 2++ 4
^
1 error was found.# (1+3*4
error: missing ')'
(1+3*4
^
1 error was found.# 1++[2*3**1
error: incorrect position of symbol.
1++[2*3**1
^
error: incorrect position of symbol.
1++[2*3**1
^
error: missing ']'
1++[2*3**1
^
3 errors were found.# two+five*second+ten
error: not registered word is used.
two+five*second+ten
^
1 error was found.# 1.3.4.5.6
unexpected error