TweetFollow Us on Twitter

Math Compiler
Volume Number:8
Issue Number:3
Column Tag:C Workshop

A Compiler for Math Equations

We’ve seen mathematical equation interpreters, what about a compiler?

By Kevin Raner, Mt. Waverley, Victoria, Australia

I am a scientist with an interest in Macintosh programming, and I a spend a large proportion of my spare time writing number crunching programs. I set out to write an application to use various algorithms to fit specific mathematical functions to some of my experimental data. I didn’t want to hard code these equations into my application as I thought it would be nice to have one version that would handle any equation you gave it. The first version of my program took the equation as a string of characters and stored it away. Then whenever it evaluated the equation, it parsed the string and did the appropriate calculations as it went along. However, this had one big disadvantage, namely it was very slow! Since what I had written was essentially an equation interpreter, the obvious way to improve things was to write an equation compiler.

This article describes such a compiler for mathematical equations. The code, written in THINK C, is designed to be incorporated into a project that needs to evaluate an equation in order to perform some useful task, e.g., optimization, least squares curve fitting, etc. When invoked, the compiler parses a string of characters and sets up a block of executable code in the heap. In this manner, the code for evaluating the equation can be compiled at run time. Consequently, it runs as quickly as if it had been hard coded in the first place. Hence an application can be developed without prior knowledge of what equation it might have to deal with.

An Example

The following code fragment illustrates the use of the equation compiler:

/* 1 */

#include"EqnCompiler.h"

extended(*eqnFn)(); /* func ptr to code */
Handle  eqnCode; /* handle to code block */

main()
{
 char   eqnText[80];
 int    theErr, index;
 extended x, y, a, b, c, coeff[5];

 /* allocate memory */
 eqnCode = NewHandle(0);
 /* equation text to be compiled */
 strcpy(eqnText, "eqnFn(x) = a*sin(b*x+c)");
 /* compile right hand side of equation */
 index = 11;
 theErr = CompileEqn(eqnText, strlen(eqnText),
 &index, eqnCode);
 HLock(eqnCode); /* lock code block */
 eqnFn = *eqnCode; /* set function ptr */

 coeff[0] = a; /* set coefficients */
 coeff[1] = b;
 coeff[2] = c;
 y = (*eqnFn)(x, coeff); /* call function */
}

The above fragment of code allocates a block of heap space to accommodate the new function. Next it sets up a string of characters that defines the equation as text. CompileEqn() is then called with a pointer to the text, the length of the text, the location of the beginning of the equation, and the handle to a relocatable block on the heap where the new function will reside. CompileEqn() expects the code block to be unlocked so that it may grow in size as the code is compiled. (If the equation text is relocatable, it should be locked in memory so that the pointer remains valid.) The third argument, &index, is the address of an index variable. When the routine is called, index informs the routine where to start parsing (position zero indicates the first character in the buffer). In the above example the first character to be parsed is ‘a’. The text buffer is parsed until the end is reached, a semicolon is found, or a syntax error is encountered. The use of a semicolon to mark the end of the equation allows comments to be appended. On the function’s return, index will have been incremented by the number of characters that were successfully parsed. If the text cannot be compiled due to a syntax error, the nature of the error is returned in theErr and its position is indicated in index. The possible errors that can be returned are listed in the file “EqnCompiler.h”. When the code block has been set up, it is locked and dereferenced to give the function pointer. Thereafter (*eqnFn)(x, coeff) is functionally identical to the following function:

/* 2 */

extendedeqnFn(extended x, extended *coeff)
{
 extended y;

 /* eqnFn(x) = a*sin(b*x+c) */
 y = coeff[0]*sin(coeff[1]*x+coeff[2]);
 return y;
}

The equation compiler always generates code that has the prototype shown above. The new function expects two arguments, x and a pointer to an array of coefficients. CompileEqn() recognizes five coefficients namely a, b, c, d, and e. If these coefficients are referenced in the equation text then their numerical values should be placed in an array before the function is called. A pointer to this array is passed as the second argument, NULL may be passed if you are sure that the equation text does not contain references to the coefficients. If you require more than five coefficients, you can edit the routine ScanFn() to handle extra coefficients.

Equation Syntax

The equation compiler recognizes the following operands: a, b, c, d, e, x, Π, pi, and numeric strings. The numeric strings may be expressed in scientific or non-scientific format. Unary minus and the following binary operators are allowed: + (addition), - (subtraction), * (multiplication), / (division) and ^ (exponentiation). The compiler recognizes the following elementary functions: sin(), cos(), tan() atan(), sqrt(), exp() and log() (natural). Custom unary functions may also be defined, the file “CustomFn.c” implements the functions asin() and acos(). The compiler is not case sensitive and space characters inserted between operands, operators, and functions are ignored. Parentheses may be used to change the priority of operations, and comments may be appended to the end of an equation using the semicolon delimiter, e.g., “2.1*(1-exp(-a*x)); first order growth”. The relative priorities of the operators are shown below.

Priority of Operators

( ) (parentheses)

^ (exponentiation)

- (unary minus)

* / (multiplication, division)

+ - (addition, subtraction)

How it Works

I’m not going to describe this in great detail; however, I will describe the roles of the various routines that make up the compiler. You’ll need to be familiar with assembly language to understand the routines that do the actual coding. The first routine called is CompileEqn(); this initializes the global variables and coordinates the other routines which perform specific tasks. All of these routines notify CompileEqn() of their success by returning an integer error code. CompileEqn() parses the text buffer by calling any of three scanning routines: ScanNum(), ScanFn() and ScanOp(). The global variable mode controls which routine is called next. There are two modes, SCAN_OPERAND and SCAN_OPERATOR. When mode is set to SCAN_OPERAND it expects the current location in the text to contain either a numerical substring; an operand such as x, c, Π etc.; a left hand parenthesis; or a substring denoting an external function, e.g., sin(x). The first situation is handled by ScanNum() which returns the number, in extended format, by address. The variable operand is then set to CONST_OPERAND to indicate that a numerical value has been stored in the variable num. ScanFn() deals with the other possibilities and returns an integer result, by address. If ScanFn() finds an operand, operand is set to either X_OPERAND, COEFF_OPERAND or PI_OPERAND to indicate what was found. If a coefficient was found, its offset from the start of the array coeff is stored in the variable offset (e.g. c is offset 20 bytes from the start of the array). If Π was found, num is set to the value of pi as determined by the SANE function pi(). If ScanFn() finds a unary function, e.g., unary minus, sin(x) etc., the integer result contains information about the unary operation (see below).

If mode is SCAN_OPERATOR, ScanOp() is called. This scans for a binary operator or a right hand parenthesis and returns an integer result, by address. All operations are ranked in an order of priority and are executed in order. The ranking depends on the priority of an operation and on how deeply it’s embedded in parentheses. Details about the pending operations are stored in the array operation[] as long integers. Operation[0] describes the oldest entry in the queue with more recent operations having higher index numbers. The long integer entries in the array operation contain the following information.

Operation Information

bits 31-16 level of parentheses

bits 15-12 relative priority of operation

bits 11-8 function type

bits 7-0 low byte of SANE opword

The parenthesis level is stored in the high word of the operation[] entry. The low word is the result returned by either ScanFn() or ScanOp(). The bits 15-12 contain the relative priority of the operation. All arithmetic operations and elementary functions are performed using the SANE software packages (see The Standard Apple Numerics Manual, 2nd Edition). Bits 11-8 indicate whether the operation will be handled by the fp68k package, elems68k package or by a customized unary function. If the operation is performed by the SANE software, then the least significant byte contains the low byte of the SANE opword. If the operation is a customized unary function, then bits 7-0 contain an index to an array of custom function pointers.

The routines OperandCode(), OperationCode(), UnOpCode(), BinOpCode1(), BinOpCode2(), ReturnCode1() and ReturnCode2() write MC68000 instructions into the block on the heap. OperandCode() sets up code to copy an operand into a stack frame used by the function. OperationCode() coordinates the routines that write instructions that invoke arithmetic or elementary functions. These routines (namely UnOpCode(), BinOpCode1() and BinOpCode2()) push the addresses of the operands onto the stack followed by the SANE opword. The package trap is then called and the mathematical operation is performed. UnOpCode(), BinOpCode1() and BinOpCode2() are commented with the symbolic assembler representations of the instructions that they write to the code block.

The functions ReturnCode1() and ReturnCode2() write instructions that copy the computed result to a location specified by the caller. Usually ReturnCode2() is called which copies the result from the stack frame. The purpose of ReturnCode1() is to write more efficient code for trivial functions such as eqnFn(x) = x. Rather than copy x into the stack frame and then back out to the result address, it copies x directly to the result address without setting up a stack frame.

Custom Unary Functions

Most of the mathematical functions you may need for your project are included in the SANE packages. However, you may need to define your own functions for use with the equation compiler. For example, you may need base-10 logarithm functions, inverse trigonometric or hyperbolic trigonometric functions etc. The file “CustomFn.c” contains two predefined custom functions. (Excuse the phrase “predefined custom”. It’s a bit like “military intelligence”.)

These are included to illustrate how you can customize the equation compiler. To add your own functions to the equation compiler you edit “CustomFn.c” in the following way. First, you must redefine the macro NUM_CF to the total number of custom functions in the file. Second, you need to declare the functions. Your custom functions must have the prototype:

extendedMyFunc(extended);

Third, the function pointers to your custom functions must be added to the array CFPtr[]. Similarly, pointers to the corresponding keyword strings must be included in the array CFKeyword[] with matching index numbers. Finally, you need to include the source code for your custom functions.

When the routine ScanFn() encounters one of your custom keywords it will cause UnOpCode() to write code to call your custom function. The custom functions already included are saneasin() and saneacos(). These are SANE versions of their ANSI counterparts asin() and acos() (see The Standard Apple Numerics Manual, 2nd Edition. Chapter 9). The ANSI functions return zero when they are passed an invalid argument whereas the SANE functions return a NAN (Not-A-Number) code.

SANE, the Code and the MC68881 Option

For complete compatibility with all machines, the code that is assembled by the equation compiler performs all of its calculations using 80 bit floating point data types with calls to the SANE packages. If the MC68881 coprocessor is available, the SANE packages will take advantage of its presence, otherwise they will do all the work themselves. The code that is assembled by the equation compiler does not take direct advantage of the MC68881 coprocessor, and so there is no advantage in enabling THINK C’s MC68881 option when compiling your project. However, you may have other reasons for setting this option in your project. The code in “EqnCompiler.c” is written so that it will compile correctly with this option, but bear the following comments in mind.

The MC68881 option sets the size of type double to 96 bits and the extended data type remains as 80 bits. The equation code that will be assembled at run time expects 80 bit (extended) arguments and returns an 80 bit (extended) result. This means a 96 bit interface must be defined to call the equation function (see below). Note that the array of coefficients must contain values in 80 bit extended format.

/* 3 */

extended(*eqnFn80)();/* ptr to 80 bit func */
double  eqnFn(double, extended *);

/* 96 bit interface function */
double  eqnFn(double x96, extended *coeff)
{
 extended x80, y80;
 double y96;

 /* convert x from 96 to 80 bits */
 x96tox80(&x96, &x80);
 /* 80 bit func */
 y80=(*eqnFn80)(x80, coeff);
 /* convert result from 80 to 96 bits */
 x80tox96(&y80, &y96);
 /* return 96 bit result */  
 return y96;
}

One other point to remember is that custom unary functions are expected to take an 80 bit (extended) and return an 80 bit (extended) result. Custom functions defined by you in “CustomFn.c” must conform to this requirement. The functions saneasin() and saneacos() manipulate extended variables as if they are doubles. While this is allowed without the MC68881 option, the compiler will report errors if this option is enabled. If you want to use the MC68881 option, you must rewrite or omit these two functions.

The Demo Program

To illustrate the use of EqnCompiler, I have written a small demonstration application. In order to keep it small I’ve programmed the visual interface as a dialog box, in this manner Dialog Manager handles most of the tedious work. The code for this application is listed in the files “Demo.c” and “Demo.h”. To put together the project you need to include the ANSI, MacTraps and SANE libraries.

The completed application allows you to type a string representing an equation into the field labelled “f(x) =”. The typed string, bar comments, is then compiled when the “Compile” button is clicked. The “Plot” button does the obvious. The equation that is plotted is the most recently compiled equation that is evaluated with the current coefficients (left hand fields). The range and domain of the plot are controlled by the bottom fields.

Figure 1: The demonstration program

For those assembly language programmers who’d like to see exactly what the assembled equation code looks like, I suggest modifying “Demo.c” to write the contents of the eqnCode block into a disk file. You can then open this file with a disassembler and see what’s going on. In fact this was how I debugged EqnCompiler. As you can imagine, writing a collection of numbers to the heap and then jumping to it can produce some nasty results.

I hope this equation compiler is of use to some of you number crunchers. In the process of writing this I’ve certainly learned a lot about SANE and assembly language. Enjoy.

Final Note

At the time of submission, a similar article appeared in MacTutor, see “A Practical Parser” Vol. 7, page 8. In this article Bill Murray describes a mathematical parser of his own. However, my parser differs in that it is integrated with a compiler. This allows efficient evaluation of an equation using fast compiled object code.

Listing:  EqnCompiler.h
/* EqnCompiler and Demonstration program. */
/* Written for THINK C, compile with MacHeaders */

/* Header file for EqnCompiler */

/* maximum number of pending operations */
#define MAX_PENDING20
/* maximum length for a numeric constant */
#define MAX_CONST_LEN20
/* maximum length for a custom keyword */
#define MAX_KWORD_LEN10

#define OPERAND_SCAN 1
#define OPERATOR_SCAN2
#define PARENTH  0
#define RANK0xFFFFF000
/* operands */
#define X_OPERAND0x1000
#define COEFF_OPERAND0x2000
#define CONST_OPERAND0x4000
#define PI_OPERAND 0x4000
/* operations - in order of priority */
#define PRIORITY_1 0x1000 /* add, subtract */
#define PRIORITY_2 0x2000 /* mult, divide */
#define UN_MINUS 0x3000 /* unary minus */
#define EXPONENT 0x4000 /* raise power */
#define UN_FUNC  0x5000 /* unary func */
/* function types */
#define FP68K    0x0100
#define ELEMS68K 0x0200
#define CUSTOM   0x0400

/* errors returned by CompileEqn() */
#define nullEqnErr 1
/* only white space chars found in text */
#define memoryErr2
/* problems allocating memory for code */
#define longNumErr 3
/* numeric constant too long */
#define badNumErr4
/* invalid numeric constant */
#define noOperandErr 5
/* expecting operand or function */
#define noOperatorErr6
/* missing operator */
#define badTokenErr7
/* unrecognized characters */
#define noLeftParenErr  8
/* missing left parenthesis in function */
#define unbalParenErr9
/* unbalanced parentheses */
#define tooManyOpErr 10
/* too many pending operations */
#define miscErr  11
/* other error */

/* function prototypes */
intCompileEqn(void *, int, int *, Handle);
intScanNum(extended *);
intScanFn(int *);
intScanOp(int *);
intOperationCode(int, int, int, extended *);
intOperandCode(int, int, extended *);
intUnOpCode(int);
intBinOpCode1(int, int, int);
intBinOpCode2(int);
intReturnCode1(int, int, extended *);
intReturnCode2(void);
intLookUpCF(char *, int *);
Listing:  EqnCompiler.c

/* Contains the equation compiler */

#include<ctype.h>
#include<SANE.h>
#include"EqnCompiler.h"

/* Global Variables */
static int**codeBlock; /* handle to code */
static char *textPtr; /* ptr to eqn text */
static inttextLen; /* length of eqn text */
static char mode; /* text scan mode */
static int*textIndex; /* current scan posn */
static intcodeIndex; /* current write posn */
static intframeIndex; /* stack frame posn */
static intframeSize; /* stack frame size */
extern ProcPtr CFPtr[]; /* custom func ptrs */

intCompileEqn(void *textBuff, int length, 
int *index, Handle codeHand)
{
 int  level=0; /* parenthesis level */
 int  operand=0; /* current operand type */
 int  offset; /* coeff offset from array ptr */
 long operation[MAX_PENDING]; /* stored operns */
 int  opIndex=0; /* next posn in operation[] */
 int  result, error;
 extended num;
 
 /* re-initialize globals */
 codeBlock = (int **) codeHand;
 textPtr = textBuff;
 textIndex = index;
 textLen = length;
 frameIndex = 0;
 frameSize = 0;
 mode = OPERAND_SCAN;
 
 SetHandleSize(codeBlock, 0); /* zero code blk */
 if (MemError()) return memoryErr;
 
 /* get first char, ignore white space chars */
 while (isspace(*(textPtr+*textIndex)) && 
 *textIndex<textLen) (*textIndex)++;
 if (*textIndex>=textLen || *(textPtr+*textIndex)==';')
 return nullEqnErr;
 
 /* code for setting up a stack frame */
 codeIndex = 2;
 SetHandleSize(codeBlock, 4);
 if (MemError()) return memoryErr;
 **codeBlock = 0x4E56; /* link A6,#-__ */
 /* fill in size of frame later */
 
 while (true) {
 if (mode == OPERAND_SCAN) {
 /* scan for operand or unary function */
 if ((*(textPtr+*textIndex)=='.') ||
 isdigit(*(textPtr+*textIndex))) {
 /* scan for numeric constant */
 if (operand) {
 /* copy old operand to frame */
 error = OperandCode(operand, offset, &num);
 if (error) return error;
 }
 error = ScanNum(&num);
 if (error) return error;
 operand = CONST_OPERAND;
 } else {
 /* scan for operand or unary function */
 error = ScanFn(&result);
 if (error) return error;
 switch (result & 0xF000) {
 case PARENTH: /* ( */
 level++; /* inc parenth level */
 break;
 case X_OPERAND: /* x */
 case COEFF_OPERAND: /* a, b, c   */
 case PI_OPERAND: /* Π */
 if (operand) {
 /* copy old operand to frame */
 error = OperandCode(operand, offset, &num);
 if (error) return error;
 }
 operand = result & 0xF000;
 if (operand == PI_OPERAND) num = pi();
 else if (operand == COEFF_OPERAND)
   offset = result & 0x00FF;
 break;
 case UN_MINUS: /* unary minus */
 case UN_FUNC: /* unary function */
 opIndex++;
 if (opIndex > MAX_PENDING)
 return tooManyOpErr;
 /* add operation to queue */
 operation[opIndex-1] = level*0x10000 + result;                
 if ((result & 0xF000) != UN_MINUS)
 level++; /* inc parenth level */
 }
 }
 } else if (mode == OPERATOR_SCAN) {
 /* scan for binary operator */
 error = ScanOp(&result);
 if (error) return error;
 if (result) { /* found operator */
 opIndex++;
 if (opIndex > MAX_PENDING)
 return tooManyOpErr;
 /* add operation to queue */
 operation[opIndex-1] = level*0x10000 + result;
 } else { /* ')' */
 level--; /* decrement parenth level */
 if (level < 0) return unbalParenErr;
 }
 }
 /* compact pending operation array */
 while (opIndex > 1) {
 if ((operation[opIndex-1]&RANK) <=
 (operation[opIndex-2]&RANK)) {
 error = OperationCode(operation[opIndex-2],
 operand, offset, &num); /* add opern to code */
 if (error) return error;
 operand = 0;
 /* remove operation from queue */
 operation[opIndex-2] = operation[opIndex-1];
 opIndex--;
 } else break;
 }
 /* get next token, ignore white space chars */
 while (isspace(*(textPtr+*textIndex)) &&
 *textIndex<textLen) (*textIndex)++;
 if (*textIndex>=textLen || *(textPtr+*textIndex)==';') {
 if (mode==OPERAND_SCAN)
 return noOperandErr;
 else break;
 }
 }
 
 /* add pending operations to code */
 while (opIndex > 0) {
 error = OperationCode(operation[opIndex-1],
 operand, offset, &num);
 if (error) return error;
 operand = 0;
 opIndex--; /* remove opern from queue */
 }
 
 if (level) return unbalParenErr;
 /* set frame size of initial link instrn */
 *(*codeBlock+1) = -10*frameSize;

 if (operand) /* code for return value */
 error = ReturnCode1(operand, offset, &num);
 else error = ReturnCode2();
 if (error) return error;
 codeIndex += 2; /* unlink and rts code */
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 *(*codeBlock+codeIndex-2)=0x4E5E; /* unlk A6 */
 *(*codeBlock+codeIndex-1)=0x4E75; /* rts */
 return 0;
}

/* scan the text for a number */
intScanNum(extended *num)
{
 int    i=0;
 char   valid;
 char   str[MAX_CONST_LEN+1]; /* C str */
 short  index;
 decimaldec;
 
 do { /* find longest valid numeric string */
 if (i>=MAX_CONST_LEN) return longNumErr;
 str[i] = *(textPtr+*textIndex+i);
 str[i+1] = 0; /* NULL terminator */
 index = 0;
 cstr2dec(str, &index, &dec, &valid);
 if (!valid) break;
 i++;
 if (*textIndex+i>=textLen || *(textPtr+*textIndex+i)==';') break;
 } while (valid);
 
 if (!index) return badNumErr;
 *num = dec2num(&dec);
 if (classextended(*num)<3 && classextended(*num)>-3)
 return badNumErr; /* NAN, INF */
 *textIndex += index;
 mode = OPERATOR_SCAN;
 return 0;
}

/* scan text for operand or function */
intScanFn(int *result)
{
 char str[MAX_KWORD_LEN+1]; /* pascal str */
 int  error, i=0;
 
 /* get longest alphabetic substring */
 while (isalpha(*(textPtr+*textIndex+i))) {
 if (i>MAX_KWORD_LEN) return badTokenErr;
 str[i+1] = *(textPtr+*textIndex+i);
 i++;
 if (*textIndex+i>=textLen || *(textPtr+*textIndex+i)==';') break;
 }
 
 str[0] = i; /* length byte */
 switch (i) {
 /* match string against expected strings */
 case 0: /* first char was not alphabetic */
 if (*(textPtr+*textIndex) == '-')
 /* unary minus */
 *result = UN_MINUS+FP68K+(FNEGX&0x00FF);
 else if (*(textPtr+*textIndex) == '(')
 *result = PARENTH; /* '(' */
 else if (*(textPtr+*textIndex) == 'Π' ||
 *(textPtr+*textIndex) == '½') {
 *result = PI_OPERAND; /* pi */
 mode = OPERATOR_SCAN;
 } else return noOperandErr;
 (*textIndex)++;
 return 0;
 case 1: /* single alphabetic character */
 if (tolower(str[1]) >= 'a' && tolower(str[1]) <= 'e') {
 /* coefficient */
 switch (tolower(str[1])) {
 case 'a':
 *result = COEFF_OPERAND;
 break;
 case 'b':
 *result = COEFF_OPERAND + 10;
 break;
 case 'c':
 *result = COEFF_OPERAND + 20;
 break;
 case 'd':
 *result = COEFF_OPERAND + 30;
 break;
 case 'e':
 *result = COEFF_OPERAND + 40;
 }
 } else if (tolower(str[1]) == 'x')
 *result = X_OPERAND; /* x */
 else goto lookup; /* custom func? */
 (*textIndex)++;
 mode = OPERATOR_SCAN;
 return 0;
 case 2: /* two alphabetic characters */
 if (EqualString(str, "\ppi", false, true))
 *result = PI_OPERAND; /* pi */
 else goto lookup; /* custom func? */
 *textIndex += 2;
 mode = OPERATOR_SCAN;
 return 0;
 case 3: /* three alphabetic characters */
 if (EqualString(str, "\psin", 0, 1))
 *result = UN_FUNC+ELEMS68K+(FSINX&0x00FF);
 else if (EqualString(str, "\pcos", 0, 1))
 *result = UN_FUNC+ELEMS68K+(FCOSX&0x00FF);
 else if (EqualString(str, "\ptan", 0, 1))
 *result = UN_FUNC+ELEMS68K+(FTANX&0x00FF);
 else if (EqualString(str, "\plog", 0, 1))
 *result = UN_FUNC+ELEMS68K+(FLNX&0x00FF);
 else if (EqualString(str, "\pexp", 0, 1))
 *result = UN_FUNC+ELEMS68K+(FEXPX&0x00FF);
 else goto lookup; /* custom func? */
 break;
 case 4: /* four alphabetic characters */
 if (EqualString(str, "\psqrt", 0, 1))
 *result = UN_FUNC+FP68K+(FSQRTX&0x00FF);
 else if (EqualString(str, "\patan", 0, 1))
 *result = UN_FUNC+ELEMS68K+(FATANX&0x00FF);
 else goto lookup; /* custom func? */
 break;
 default: /* other string lengths */
 lookup: /* custom func? */
 error = LookUpCF(str, result);
 if (error) return error;
 }

 /* check next char is '(' */
 while (isspace(*(textPtr+*textIndex+i)) &&
 *textIndex+i<textLen) i++;
 if (*textIndex+i>=textLen || *(textPtr+*textIndex+i)==';' ||
 *(textPtr+*textIndex+i)!='(')
 return noLeftParenErr;
 *textIndex += i+1;
 return 0;
}

/* scan text for an operator */
intScanOp(int *result)
{
 switch (*(textPtr+*textIndex)) {
 case '+': /* addition */
 *result = PRIORITY_1+FP68K+(FADDX&0x00FF);
 break;
 case '-': /* subtraction */
 *result = PRIORITY_1+FP68K+(FSUBX&0x00FF);
 break;
 case '*': /* multiplication */
 *result = PRIORITY_2+FP68K+(FMULX&0x00FF);
 break;
 case '/': /* division */
 *result = PRIORITY_2+FP68K+(FDIVX&0x00FF);
 break;
 case '^': /* exponentiation */
 *result = EXPONENT+ELEMS68K+(FXPWRY&0x00FF);
 break;
 case ')': /* end of parenthesis */
 *result = PARENTH;
 break;
 default: /* syntax error */
 return noOperatorErr;
 }

 /* don't change mode if ')' encountered */
 if (*result != PARENTH) mode = OPERAND_SCAN;
 (*textIndex)++;
 return 0;
}

/* classify operation, call handler routines */
intOperationCode(int operation, int operand, 
int offset, extended *numPtr)
{
 int  error;
 
 if ((operation&0xF000) == UN_MINUS ||
 (operation&0xF000) == UN_FUNC) {
 /* unary operation */
 if (operand) {
 error = OperandCode(operand, offset, numPtr);
 if (error) return error;
 }
 error = UnOpCode(operation);
 if (error) return error;
 } else {
 /* binary operation */
 if (operand == X_OPERAND || operand == COEFF_OPERAND) {
 error = BinOpCode1(operation, operand, offset);
 if (error) return error;
 } else {
 if (operand == CONST_OPERAND) {
 error = OperandCode(CONST_OPERAND, 0, numPtr);
 if (error) return error;
 }
 error = BinOpCode2(operation);
 if (error) return error;
 }
 }
 return 0;
}

/* set up code for copying operand into stack frame */
intOperandCode(int operand,  int offset, extended *numPtr)
{
 frameIndex++;
 if (frameIndex>frameSize) frameSize=frameIndex;
 if (operand == X_OPERAND) {
 codeIndex += 7;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* lea.l -10fi(A6),A0; A0 <- frame_adr */
 *(*codeBlock+codeIndex-7) = 0x41EE;
 *(*codeBlock+codeIndex-6) = -10*frameIndex;
 /* lea.l 12(A6),A1; A1 <- x_adr */
 *(*codeBlock+codeIndex-5) = 0x43EE;
 *(*codeBlock+codeIndex-4) = 0x000C;
 /* move.l (A1)+,(A1)+; copy x into frame */
 *(*codeBlock+codeIndex-3) = 0x20D9;
 /* move.l (A1)+,(A1)+ */
 *(*codeBlock+codeIndex-2) = 0x20D9;
 /* move.w (A1)+,(A1)+ */
 *(*codeBlock+codeIndex-1) = 0x30D9;
 } else if (operand == COEFF_OPERAND) {
 codeIndex += 2;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* move.l 22(A6),A0; A0 <- coeff base adr */
 *(*codeBlock+codeIndex-2) = 0x206E;
 *(*codeBlock+codeIndex-1) = 0x0016;
 if (offset) {
 codeIndex += 3;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* move.l off(A0),-10fi(A6); copy coeff */
 *(*codeBlock+codeIndex-3) = 0x2D68;
 *(*codeBlock+codeIndex-2) = offset;
 *(*codeBlock+codeIndex-1) = -10*frameIndex;
 } else {
 codeIndex += 2;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* move.l (A0),-10fi(A6); copy coeff */
 *(*codeBlock+codeIndex-2) = 0x2D50;
 *(*codeBlock+codeIndex-1) = -10*frameIndex;
 }
 codeIndex += 6;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* move.l off+4(A0),-10fi+4(A6); copy coeff */
 *(*codeBlock+codeIndex-6) = 0x2D68;
 *(*codeBlock+codeIndex-5) = offset+4;
 *(*codeBlock+codeIndex-4) = -10*frameIndex+4;
 /* move.w off+8(A0),-10fi+8(A6); copy coeff */
 *(*codeBlock+codeIndex-3) = 0x3D68;
 *(*codeBlock+codeIndex-2) = offset+8;
 *(*codeBlock+codeIndex-1) = -10*frameIndex+8;
 } else if (operand == CONST_OPERAND) {
 codeIndex += 11;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* move.l #__,-10fi(A6); frame <- const */
 *(*codeBlock+codeIndex-11) = 0x2D7C;
 *(*codeBlock+codeIndex-10) = *((int *) numPtr);
 *(*codeBlock+codeIndex-9) = *((int *) numPtr+1);
 *(*codeBlock+codeIndex-8) = -10*frameIndex;
 /* move.l #__,-10fi+4(A6) */
 *(*codeBlock+codeIndex-7) = 0x2D7C;
 *(*codeBlock+codeIndex-6) = *((int *) numPtr+2);
 *(*codeBlock+codeIndex-5) = *((int *) numPtr+3);
 *(*codeBlock+codeIndex-4) = -10*frameIndex+4;
 /* move.w #__,-10fi+8(A6) */
 *(*codeBlock+codeIndex-3) = 0x3D7C;
 *(*codeBlock+codeIndex-2) = *((int *) numPtr+4);
 *(*codeBlock+codeIndex-1) = -10*frameIndex+8;
 } else return miscErr;
 
return 0;
}

/* write code for unary function, operand in stack frame */
intUnOpCode(int operation)
{
 if (!frameIndex) return miscErr;
 if ((operation&0x0F00)==FP68K ||
 (operation&0x0F00)==ELEMS68K) { /* SANE func */
 codeIndex += 5;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* pea.l -10fi(A6); push operand_adr */
 *(*codeBlock+codeIndex-5) = 0x486E;
 *(*codeBlock+codeIndex-4) = -10*frameIndex;
 /* move.w opword, -(A7); push SANE opword */
 *(*codeBlock+codeIndex-3) = 0x3F3C;
 *(*codeBlock+codeIndex-2) = operation&0x00FF;
 if ((operation&0x0F00) == FP68K)
 *(*codeBlock+codeIndex-1)=0xA9EB;/* _Pack4 */
 else if ((operation&0x0F00) == ELEMS68K)
 *(*codeBlock+codeIndex-1)=0xA9EC;/* _Pack5*/
 else return miscErr;
 } else if ((operation&0x0F00) == CUSTOM) {
 /* custom unary function */
 codeIndex += 14;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* move.l -10fi+6(A6),-(A7); push operand */
 *(*codeBlock+codeIndex-14) = 0x2F2E;
 *(*codeBlock+codeIndex-13) = -10*frameIndex+6;
 /* move.l -10fi+2(A6),-(A7) */
 *(*codeBlock+codeIndex-12) = 0x2F2E;
 *(*codeBlock+codeIndex-11) = -10*frameIndex+2;
 /* move.w -10fi(A6),-(A7) */
 *(*codeBlock+codeIndex-10) = 0x3F2E;
 *(*codeBlock+codeIndex-9) = -10*frameIndex;
 /* pea.l -10fi(A6); push result adr */
 *(*codeBlock+codeIndex-8) = 0x486E;
 *(*codeBlock+codeIndex-7) = -10*frameIndex;
 /* move.l #__,A0; A0 <- func_adr */
 *(*codeBlock+codeIndex-6) = 0x207C;
 *(*codeBlock+codeIndex-5) =
 HiWord((long) CFPtr[operation&0x00FF]);
 *(*codeBlock+codeIndex-4) =
 LoWord((long) CFPtr[operation&0x00FF]);
 /* jsr (A0); jump to func */
 *(*codeBlock+codeIndex-3) = 0x4E90;
 /* lea.l 14(A7),A7; reset stack ptr */
 *(*codeBlock+codeIndex-2) = 0x4FEF;
 *(*codeBlock+codeIndex-1) = 0x000E;
 } else return miscErr;
 return 0;
}

/* set up binary operation code - only destination operand in stack frame 
*/
intBinOpCode1(int operation, int operand, int offset)
{
 if (frameIndex < 1) return miscErr;
 if (operand == X_OPERAND) {
 codeIndex += 2;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* pea.l 12(A6); push x_adr */
 *(*codeBlock+codeIndex-2) = 0x486E;
 *(*codeBlock+codeIndex-1) = 0x000C;
 } else if (operand == COEFF_OPERAND) {
 codeIndex += 2;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* move.l 22(A6),A0; A0 <- coeff base adr */
 *(*codeBlock+codeIndex-2) = 0x206E;
 *(*codeBlock+codeIndex-1) = 0x0016;
 if (offset) {
 codeIndex += 2;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* pea.l off(A0); push coeff_adr */
 *(*codeBlock+codeIndex-2) = 0x4868;
 *(*codeBlock+codeIndex-1) = offset;
 } else {
 codeIndex++;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* pea.l (A0); push coeff_adr */
 *(*codeBlock+codeIndex-1) = 0x4850;
 }
 } else return miscErr;
 codeIndex += 5;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /*  pea.l -10fi(A6); push dest_adr  */
 *(*codeBlock+codeIndex-5) = 0x486E;
 *(*codeBlock+codeIndex-4) = -10*frameIndex;
 if ((operation&0xF000) == EXPONENT) {
 /* move.w FXPWRY,-(A7); push FXPWRY */
 *(*codeBlock+codeIndex-3) = 0x3F3C;
 *(*codeBlock+codeIndex-2) = FXPWRY;
 *(*codeBlock+codeIndex-1)=0xA9EC;/* _Pack5 */
 } else if ((operation&0x0F00) == FP68K) {

 /* move.w opword,-(A7); push SANE opword */
 *(*codeBlock+codeIndex-3) = 0x3F3C;
 *(*codeBlock+codeIndex-2) = operation&0x00FF;
 *(*codeBlock+codeIndex-1)=0xA9EB;/* _Pack4 */
 } else return miscErr;
 return 0;
}

/* set up binary operation code - both operands are in stack frame */
intBinOpCode2(int operation)
{
 if (frameIndex < 2) return miscErr;
 codeIndex += 7;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* pea.l -10fi(A6); push src operand */
 *(*codeBlock+codeIndex-7) = 0x486E;
 *(*codeBlock+codeIndex-6) = -10*frameIndex;
 /* pea.l -10fi+10(A6); push dest operand */
 *(*codeBlock+codeIndex-5) = 0x486E;
 *(*codeBlock+codeIndex-4) = -10*frameIndex+10;
 if ((operation&0xF000) == EXPONENT) {
 /* move.w FXPWRY,-(A7); push FXWPRY */
 *(*codeBlock+codeIndex-3) = 0x3F3C;
 *(*codeBlock+codeIndex-2) = FXPWRY;
 *(*codeBlock+codeIndex-1)=0xA9EC;/* _Pack5 */
 } else if ((operation&0x0F00) == FP68K) {
 /* move.w opword,-(A7); push SANE opword */
 *(*codeBlock+codeIndex-3) = 0x3F3C;
 *(*codeBlock+codeIndex-2) = operation&0x00FF;
 *(*codeBlock+codeIndex-1)=0xA9EB;/* _Pack4 */
 } else return miscErr;
 frameIndex--; /* decrement frame position */
 return 0;
}

/* copy operand to address specified by 8(A6) */
intReturnCode1(int operand, int offset, extended *numPtr)
{
 if (operand == CONST_OPERAND) {
 codeIndex += 10;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* move.l 8(A6),A0; A0 <- result_adr */
 *(*codeBlock+codeIndex-10) = 0x206E;
 *(*codeBlock+codeIndex-9) = 0x0008;
 /* move.l #__,(A0)+; copy const to result_adr */
 *(*codeBlock+codeIndex-8) = 0x20FC;
 *(*codeBlock+codeIndex-7) = *((int *) numPtr);
 *(*codeBlock+codeIndex-6) = *((int *) numPtr+1);
 /* move.l #__,(A0)+ */
 *(*codeBlock+codeIndex-5) = 0x20FC;
 *(*codeBlock+codeIndex-4) = *((int *) numPtr+2);
 *(*codeBlock+codeIndex-3) = *((int *) numPtr+3);
 /* move.w #__,(A0)+ */
 *(*codeBlock+codeIndex-2) = 0x30FC;
 *(*codeBlock+codeIndex-1) = *((int *) numPtr+4);
 return 0;
 } else if (operand == X_OPERAND) {
 codeIndex += 4;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* move.l 8(A6),A0; A0 <- result_adr */
 *(*codeBlock+codeIndex-4) = 0x206E;
 *(*codeBlock+codeIndex-3) = 0x0008;
 /* lea.l 12(A6),A1; A1 <- x_adr */
 *(*codeBlock+codeIndex-2) = 0x43EE;
 *(*codeBlock+codeIndex-1) = 0x000C;
 } else if (operand == COEFF_OPERAND) {
 codeIndex += 4;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* move.l 8(A6),A0; A0 <- result_adr */
 *(*codeBlock+codeIndex-4) = 0x206E;
 *(*codeBlock+codeIndex-3) = 0x0008;
 /* move.l 22(A6),A1; A1 <- coeff base Adr */
 *(*codeBlock+codeIndex-2) = 0x226E;
 *(*codeBlock+codeIndex-1) = 0x0016;
 if (offset) {
 codeIndex += 2;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* lea.l off(A1),A1; A1 <- coeff_adr */
 *(*codeBlock+codeIndex-2) = 0x43E9;
 *(*codeBlock+codeIndex-1) = offset;
 }
 } else return miscErr;
 codeIndex += 3;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* move.l (A1)+,(A0)+; copy operand to result */
 *(*codeBlock+codeIndex-3) = 0x20D9;
 /* move.l (A1)+,(A0)+ */
 *(*codeBlock+codeIndex-2) = 0x20D9;
 /* move.w (A1)+,(A0)+ */
 *(*codeBlock+codeIndex-1) = 0x30D9;
 return 0;
}

/* copy result to address in 8(A6) */
intReturnCode2(void)
{
 codeIndex += 7;
 SetHandleSize(codeBlock, 2*codeIndex);
 if (MemError()) return memoryErr;
 /* move.l 8(A6),A0; A0 <- result_adr */
 *(*codeBlock+codeIndex-7) = 0x206E;
 *(*codeBlock+codeIndex-6) = 0x0008;
 /* lea.l -10(A6),A1; A1 <- frame_adr */
 *(*codeBlock+codeIndex-5) = 0x43EE;
 *(*codeBlock+codeIndex-4) = 0xFFF6;
 /* move.l (A1)+,(A0)+; copy frame to result */
 *(*codeBlock+codeIndex-3) = 0x20D9;
 /* move.l (A1)+,(A0)+ */
 *(*codeBlock+codeIndex-2) = 0x20D9;
 /* move.w (A1)+,(A0)+ */
 *(*codeBlock+codeIndex-1) = 0x30D9;
 return 0;
}
Listing:  Demo.c

/* Code for demo program */

#include<SANE.h>
#include"Demo.h"
#include"EqnCompiler.h"

/* Global Variables */
Handle  eqnCode; /* handle to block of code */
char    **eqnText; /* handle to eqn text */
extended(*eqnFn)(); /* func ptr to eqn code */
extendedcoeff[5]; /* array of coefficients */
extendedminX, maxX, minY, maxY; /* plot range */
DialogPtr eqnDialog; /* dialog pointer */
CursHandleiBeam, watch;

main()
{
 Handle userItemH;
 int    i, type, itemHit, error, index;
 Rect   rect;
 
 InitStuff();
 /* get dialog */
 eqnDialog = GetNewDialog(300, NULL, (WindowPtr) -1);
 /* get handle to eqn text */
 GetDItem(eqnDialog, FUNCTION, &type, &eqnText, &rect);
 /* get user item (plot frame) */
 GetDItem(eqnDialog, FRAME, &type, &userItemH, &rect);
 /* install user item */
 SetDItem(eqnDialog, FRAME, type, FramePlot, &rect);
 /* centre window on screen */
 MoveWindow(eqnDialog, (screenBits.bounds.right-
 screenBits.bounds.left - 490)/2, 45, true);
 ShowWindow(eqnDialog);
 SetPort(eqnDialog);
 
 do {
 ModalDialog(DialogFilter, &itemHit);
 if (itemHit == COMPILE) { /* compile eqn */
 /* Code block should be unlocked and */
 /* eqn text buffer should be locked. */
 HUnlock(eqnCode);
 HLock(eqnText);
 index = 0; /* parse text from start */
 error = CompileEqn(*eqnText, GetHandleSize(eqnText),
 &index, eqnCode);
 if (error) {
 /* position of error is in index */
 SelIText (eqnDialog, FUNCTION, index, index);
 /* put up alert to explain error */
 SyntaxErr(error);
 eqnFn = NULL; /* null function ptr */
 } else {
 SelIText (eqnDialog, FUNCTION, 0, 0);
 /* compiled OK, lock code block and */
 /* dereference to get address of func */
 HLock(eqnCode);
 eqnFn = (void *) *eqnCode;
 }
 } else if (itemHit == PLOT) { /* plot eqn */
 /* update coefficients array */
 for (i=0; i<5; i++)
 coeff[i] = GetEditField(COEFF_A + i);
 /* update plot range */
 minX = GetEditField(MIN_X);
 maxX = GetEditField(MAX_X);
 minY = GetEditField(MIN_Y);
 maxY = GetEditField(MAX_Y);
 PlotEqn();
 }
 } while (itemHit != QUIT);
 
 DisposDialog(eqnDialog); /* tidy up & leave */
 HUnlock(eqnCode);
}

/* Plot the equation */
void  PlotEqn(void)
{
 extended x, y, vert;
 int    hPos=0, lastvPos, vPos;
 char   skip=2;
 Rect   plotRect, bigRect;
 
 if (!eqnFn) return; /* invalid function */
 if ((minX >= maxX) || (minY >= maxY))
 return; /* invalid plot range */
 SetRect(&plotRect, 170, 59, 470, 230);
 EraseRect(&plotRect); /* clear plot area */
 ClipRect(&plotRect); /* new clip region */
 SetCursor(*watch);
 
 do {
 /* calculate x */
 x = minX + (maxX - minX)*hPos/300.0;
 y = (*eqnFn)(x, coeff); /* calculate y */
 if (fabs(classextended(y)) < 2)
 skip = 2; /* y is a NAN */
 else { /* get new Y screen coord */
 lastvPos = vPos; /* save last Y coord */
 vert = rint(170*(maxY-y)/(maxY-minY));
 /* pin extreme values to window's edge */
 if (vert+59>eqnDialog->portRect.bottom)
 vPos = eqnDialog->portRect.bottom-59;
 else if (vert+59<eqnDialog->portRect.top)
 vPos = eqnDialog->portRect.top-59;
 else vPos = vert;
 if (y >= minY && y <= maxY) {
 /* y is in range */
 if (skip < 2) /* last y was not NAN */
 LineTo(170+hPos, 59+vPos);
 else MoveTo(170+hPos, 59+vPos);
 skip = 0;
 } else { /* y is out of range */
 if (!skip) /* last point was in range */
 LineTo(170+hPos, 59+vPos);
 else MoveTo(170+hPos, 59+vPos);
 skip = 1;
 }
 }
 } while ((hPos += 2) <= 300);
 
 SetRect(&bigRect, -32767, -32767, 32767, 32767);
 ClipRect(&bigRect); /* reset clip rect */
}
pascal Boolean DialogFilter(DialogPtr theDialog,
 EventRecord *theEvent, int *itemHit)
{
 Point  mousePt;
 int    item, type;
 char   c;
 Rect   rect;
 Handle hand;
 TEHandle dialogTE;
 
 if (theEvent->what == keyDown) {
 /* disable clear, enter keys in all fields */
 c = theEvent->message & charCodeMask;
 if (c == CLEAR_KEY || c == ENTER)
 return true;
 if (((DialogPeek) theDialog)->editField + 1
 == FUNCTION) {
 /* current edit field is function */
 if (c == TAB) {
 /* override default tab behaviour */
 dialogTE = ((DialogPeek) theDialog)->textH;
 TEKey(TAB, dialogTE);
 return true;
 }
 } else if (c == RETURN)
 /* disable return in other fields */
 return true;
 }
 
 /* set cursor as appropriate */
 GetMouse(&mousePt);
 item = 1 + FindDItem(theDialog, mousePt);
 if (item) {
 GetDItem(theDialog, item, &type, &hand, &rect);
 if (type == editText) SetCursor(*iBeam);
 else InitCursor();
 } else InitCursor();

 return false;
}
 
AAPL
$97.19
Apple Inc.
+2.47
MSFT
$44.87
Microsoft Corpora
+0.04
GOOG
$595.98
Google Inc.
+1.24

MacTech Search:
Community Search:

Software Updates via MacUpdate

Firefox 31.0 - Fast, safe Web browser. (...
Firefox for Mac offers a fast, safe Web browsing experience. Browse quickly, securely, and effortlessly. With its industry-leading features, Firefox is the choice of Web development professionals... Read more
Little Snitch 3.3.3 - Alerts you to outg...
Little Snitch gives you control over your private outgoing data. Track background activityAs soon as your computer connects to the Internet, applications often have permission to send any... Read more
Thunderbird 31.0 - Email client from Moz...
As of July 2012, Thunderbird has transitioned to a new governance model, with new features being developed by the broader free software and open source community, and security fixes and improvements... Read more
Together 3.2 - Store and organize all of...
Together helps you organize your Mac, giving you the ability to store, edit and preview your files in a single clean, uncluttered interface. Smart storage. With simple drag-and-drop functionality,... Read more
Cyberduck 4.5 - FTP and SFTP browser. (F...
Cyberduck is a robust FTP/FTP-TLS/SFTP browser for the Mac whose lack of visual clutter and cleverly intuitive features make it easy to use. Support for external editors and system technologies such... Read more
iExplorer 3.4 - View and transfer all th...
iExplorer is an iPhone browser for Mac lets you view the files on your iOS device. By using a drag and drop interface, you can quickly copy files and folders between your Mac and your iPhone or... Read more
Airmail 1.4 - Powerful, minimal email cl...
Airmail is a powerful, minimal mail client.It was designed to retain the same experience with a single or multiple accounts and provide a quick, modern and easy-to-use user experience. Airmail... Read more
Macs Fan Control 1.1.12 - Monitor and co...
Macs Fan Control allows you to monitor and control almost any aspect of your computer's fans, with support for controlling fan speed, temperature sensors pane, menu-bar icon, and autostart with... Read more
A Better Finder Rename 9.37 - File, phot...
A Better Finder Rename is the most complete renaming solution available on the market today. That's why, since 1996, tens of thousands of hobbyists, professionals and businesses depend on A Better... Read more
MacBook Air EFI Firmware Update 2.9 - Fo...
MacBook Air EFI Firmware Update is recommended for MacBook Air (Mid 2011) models. This update addresses an issue where systems may take longer to wake from sleep than expected and fixes a rare issue... Read more

Latest Forum Discussions

See All

Together for iOS (Productivity)
Together for iOS 1.0 Device: iOS Universal Category: Productivity Price: $9.99, Version: 1.0 (iTunes) Description: Together is an app for keeping things in one place. Notes, documents, images, movies, sounds, web pages and bookmarks... | Read more »
The Phantom PI Mission Apparition (Game...
The Phantom PI Mission Apparition 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: ** Release sale! 50% off for a limited time! ** The Phantom PI Mission Apparition is a spooky, puzzly, rock’... | Read more »
The Great Prank War (Games)
The Great Prank War 1.0.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0.0 (iTunes) Description: Help Mordecai, Rigby, Muscle Man and Skips take the park back from Gene and his goons with a plethora of prank-related... | Read more »
Traps n' Gemstones (Games)
Traps n' Gemstones 1.00 Device: iOS Universal Category: Games Price: $2.99, Version: 1.00 (iTunes) Description: LAUNCH SALE! 40% off, JULY ONLY! TRAPS N' GEMSTONES is an adventurous platform game, among gamers typically known as the... | Read more »
Soccer Physics (Games)
Soccer Physics 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: One-button soccer game! So dumb it's fun. "Soccer Physics is probably the funniest football game you'll play on iOS" —... | Read more »
Ex-Angry Birds Developers Release Monsu...
Ex-Angry Birds Developers Release Monsu Teaser Trailer Posted by Jennifer Allen on July 23rd, 2014 [ permalink ] Finnish developer Boomlagoon has released a teaser trailer of their forthcoming side-scrolling action platformer, | Read more »
Dragons: Rise of Berk – Tips, Tricks, an...
Things have changed in Berk, the fantasy Viking village of DreamWorks’ How to Train Your Dragon series. Dragons and Vikings, once mortal enemies, now must learn to live together in peace. Dragons: Rise of Berk lets players manage dragon-Viking... | Read more »
Cowabunga! Teenage Mutant Ninja Turtles:...
Cowabunga! Teenage Mutant Ninja Turtles: Rooftop Run Is Currently Free Posted by Jennifer Allen on July 23rd, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Lots of New Modes Have Been Added to Can...
Lots of New Modes Have Been Added to Canabalt Posted by Jennifer Allen on July 23rd, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Stronghold 3: The Campaigns Review
Stronghold 3: The Campaigns Review By Jennifer Allen on July 23rd, 2014 Our Rating: :: DULL STRATEGIZINGiPad Only App - Designed for the iPad A cumbersome strategy game, Stronghold 3: The Campaigns has a few too many issues to... | Read more »

Price Scanner via MacPrices.net

What Should Apple’s Next MacBook Priority Be;...
Stabley Times’ Phil Moore says that after expanding its iMac lineup with a new low end model, Apple’s next Mac hardware decision will be how it wants to approach expanding its MacBook lineup as well... Read more
ArtRage For iPhone Painting App Free During C...
ArtRage for iPhone is currently being offered for free (regularly $1.99) during Comic-Con San Diego #SDCC, July 24-27, in celebration of the upcoming ArtRage 4.5 and other 64-bit versions of the... Read more
With The Apple/IBM Alliance, Is The iPad Now...
Almost since the iPad was rolled out in 2010, and especially after Apple made a 128 GB storage configuration available in 2012, there’s been debate over whether the iPad is a serious tool for... Read more
MacBook Airs on sale starting at $799, free s...
B&H Photo has the new 2014 MacBook Airs on sale for up to $100 off MSRP for a limited time. Shipping is free, and B&H charges NY sales tax only. They also include free copies of Parallels... Read more
Apple 27″ Thunderbolt Display (refurbished) a...
The Apple Store has Apple Certified Refurbished 27″ Thunderbolt Displays available for $799 including free shipping. That’s $200 off the cost of new models. Read more
WaterField Designs Unveils Cycling Ride Pouch...
High end computer case and bag maker WaterField Designs of San Francisco now enters the cycling market with the introduction of the Cycling Ride Pouch – an upscale toolkit with a scratch-free iPhone... Read more
Kingston Digital Ships Large Capacity Near 1T...
Kingston Digital, Inc., the Flash memory affiliate of Kingston Technology Company, Inc.,has announced its latest addition to the SSDNow V300 series, the V310. The Kingston SSDNow V310 solid-state... Read more
Apple’s Fiscal Third Quarter Results; Record...
Apple has announced financial results for its fiscal 2014 third quarter ended June 28, 2014, racking up quarterly revenue of $37.4 billion and quarterly net profit of $7.7 billion, or $1.28 per... Read more
15-inch 2.0GHz MacBook Pro Retina on sale for...
B&H Photo has the 15″ 2.0GHz Retina MacBook Pro on sale for $1829 including free shipping plus NY sales tax only. Their price is $170 off MSRP. B&H will also include free copies of Parallels... Read more
Apple restocks refurbished Mac minis for up t...
The Apple Store has restocked Apple Certified Refurbished Mac minis for up to $150 off the cost of new models. Apple’s one-year warranty is included with each mini, and shipping is free: - 2.5GHz Mac... Read more

Jobs Board

Sr Software Lead Engineer, *Apple* Online S...
Sr Software Lead Engineer, Apple Online Store Publishing Systems Keywords: Company: Apple Job Code: E3PCAK8MgYYkw Location (City or ZIP): Santa Clara Status: Full Read more
Senior Interaction Designer, *Apple* Online...
**Job Summary** Apple is looking for a hands on Senior…will be a key player in designing for the Apple Online Store. The ideal designer will have a Read more
*Apple* Sales Chat Rep - Apple (United State...
…is looking for motivated, outgoing, and tech savvy individuals who want to offer Apple Customers an unparalleled customer experience over chat. At Apple , we believe Read more
Mac Expert - *Apple* Online Store Mexico -...
…MUST be fluent in English and Spanish to be considered for this position At Apple , we believe that hard work, a fun environment, creativity and innovation fuel the Read more
*Apple* Industrial Design CAD Sculptor - App...
**Job Summary** The Apple Industrial Design team is looking for a CAD sculptor/Digital 3D modeler to create high quality CAD models used in the industrial design process Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.