-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61cd827
commit 59a59d3
Showing
4 changed files
with
12 additions
and
264 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,12 @@ | |
* Saunak Biswas <[email protected]> | ||
*/ | ||
namespace Pebbles { | ||
|
||
public errordomain CalcError { | ||
DIVIDE_BY_ZERO | ||
} | ||
|
||
|
||
public class ProgrammerCalculator { | ||
private const char[] HEXADECIMAL_DIGITS = { 'a', 'b', 'c', 'd', 'e', 'f'}; | ||
public enum TokenType { | ||
|
@@ -570,8 +576,7 @@ namespace Pebbles { | |
} | ||
} | ||
|
||
public bool[] apply_op (Programmer prog_calc, char op, bool[] a_input, bool[] b_input, Pebbles.GlobalWordLength word_size) throws CalcError { | ||
print ("finding...\n"); | ||
public bool[] apply_op (char op, bool[] a_input, bool[] b_input, Pebbles.GlobalWordLength word_size) throws CalcError { | ||
bool[] ret_val = new bool[64]; | ||
if (word_size == GlobalWordLength.BYT) { | ||
int8 a = 0; | ||
|
@@ -850,10 +855,9 @@ namespace Pebbles { | |
return ret_val; | ||
} | ||
|
||
public string evaluate_exp (GlobalWordLength? wrd_length = GlobalWordLength.BYT, NumberSystem number_system, out bool[]? output_array = null) throws CalcError { | ||
public string evaluate_exp (GlobalWordLength? wrd_length = GlobalWordLength.BYT, NumberSystem? number_system = NumberSystem.BINARY, out bool[]? output_array = null) throws CalcError { | ||
CharStack ops = new CharStack (50); | ||
BoolArrayStack values = new BoolArrayStack(50); | ||
Programmer prog_calc = new Programmer(); | ||
for (int i = 0; i < stored_tokens.length; i++) { | ||
if (stored_tokens[i].type == TokenType.OPERAND) { | ||
//ops.push((char)(stored_tokens[i].token.get_char(0))); | ||
|
@@ -865,7 +869,7 @@ namespace Pebbles { | |
else { | ||
while (ops.peek() != '(') { | ||
try { | ||
bool[] tmp = apply_op(prog_calc, ops.pop(), values.pop(), values.pop(), wrd_length); | ||
bool[] tmp = apply_op(ops.pop(), values.pop(), values.pop(), wrd_length); | ||
values.push(tmp); | ||
} catch (CalcError e) { | ||
throw e; | ||
|
@@ -876,7 +880,7 @@ namespace Pebbles { | |
} else if (stored_tokens[i].type == TokenType.OPERATOR) { | ||
while (!ops.empty() && has_precedence_pemdas(stored_tokens[i].token.get(0), ops.peek())) { | ||
try { | ||
bool[] tmp = apply_op(prog_calc, ops.pop(), values.pop(), values.pop(), wrd_length); | ||
bool[] tmp = apply_op(ops.pop(), values.pop(), values.pop(), wrd_length); | ||
values.push(tmp); | ||
} catch (CalcError e) { | ||
throw e; | ||
|
@@ -888,7 +892,7 @@ namespace Pebbles { | |
} | ||
while (!ops.empty()) { | ||
try { | ||
bool[] tmp = apply_op(prog_calc, ops.pop(), values.pop(), values.pop(), wrd_length); | ||
bool[] tmp = apply_op(ops.pop(), values.pop(), values.pop(), wrd_length); | ||
values.push(tmp); | ||
} catch (CalcError e) { | ||
throw e; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters