How do calculators deal with imaginary numbers?

Strangely enough I was just working on a calculator for a small project. The answer lies in grammars, (not the English kind of "grammar", commas, full stops, and so on... the computer science kind, rules that govern how language is generated.)

So here is an example of a basic calculator grammar (ignore any strange naming conventions, this wasn't for public consumption):

<bracketCalculation>    ::= (<calculation>)|<calculation>
<calculation>           ::= <bracketCalculation><operator><bracketCalculation>|<number>
<operation>             ::= +|-|x|\

//real, natural and rational numbers. <number> ::= 0<D>|-<B>|<posDigit><C> <D> ::= .<E>|ϵ <B> ::= <posDigit><C>|0.<E> <C> ::= <digit>C|.<E>|ϵ <E> ::= <digit>F <F> ::= <digit>F|ϵ <posDigit> ::= 1|2|3|4|5|6|7|8|9 <digit> ::= 0|<posDigit>

The program runs though the calculation string, splits it up into tokens and then translates it into it's corresponding internal representation, based on the patterns it matches.

So for imaginary numbers it would do a similar thing, but a lot simpler, this grammar only has to match i with -1, so:

i  ::= -1
/r/askscience Thread