/* * Copyright (c) 2008 * by Fachhochschule Gießen-Friedberg University of Applied Sciences. * * mmp is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * mmp is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * -------------------------------------------------------------------------- * $Id: package-info.java 338 2008-07-01 08:06:00Z brenz $ * -------------------------------------------------------------------------- */

The MNI Integer Calculator MIC.

The MNI Integer Calculator MIC is an implementation of the functionality of M4's eval in Java.

Usage

MIC can be used as an embedded calculator

// Instantiate mic
Mic mic = new Mic();
// calculate
int result = mic.calculate( "10*5-3" );
// use result
...

There is also a command line interface to MIC

The invocation with arguments gives the result of the computation.

java mic.cli.mic 10 * 5 - 3
47

The invocation without arguments starts mic in interactive mode.

java mic.cli.mic
mic - the MNI integer calculator, rev 1.0
mic - interactiv mode - enter q to quit
mic %

Grammar and Operators in mic

Expression comprise integer literals like "3", parenthesis "(" and ")" and the following operators

Unary Operators

+ Plus sign
- Minus sign
~ Bitwise negation
! Logical negation
Binary Operators
PrecedenceOperatorMeaningAssociativity
high** Powerright
* Multiplicationleft
/ Divisionleft
% Moduloleft
+ Additionleft
- Substractionleft
<< Left shiftleft
>> Right shiftleft
< Less thanleft
> Greater thanleft
<= Less or equalleft
>= Greater or equalleft
== Equalleft
!= Not equalleft
& Bitwise andleft
^ Bitwise xorleft
| Bitwise orleft
&& Logical andleft
low|| Logical orleft