Building the GraphPaper Application
Now that we’ve thought about GraphPaper a bit, let’s get on with the work of building the application.
Changes to the Evaluator Back End
We need to make one change to Evaluator so that it can recognize more than a single expression on a line — that’s important, because GraphPaper will be sending (x,y) pairs such as (3,2*3+1) to Evaluator. (If we sent only y values, we might get confused.)
The easy way to do this is to make Evaluator recognize two
expressions separated by a comma and terminated with a newline.
Because we built Evaluator with lex
and
yacc
, this change is easy to make and is
confined to a single file, grammar.y
.
Launch Project Builder, choose File → New Project, and double-click “Cocoa Application”.
Type “GraphPaper” in the Project Name field, hit the Tab key so that the project is saved in the folder
~/GraphPaper
, and then click Finish.Create a second target called Evaluator in the GraphPaper project by choosing PB’s Project → New Target menu command, double-clicking Tool at the bottom of the list in the resulting sheet, typing “Evaluator”, and clicking Finish in the second sheet in the project window.
Click the Files vertical tab in PB’s main window and disclose the Resources group.
Activate the Finder, open your
~/MathPaper
folder, single-clickgrammar.y,
and then Command-clickrules.l
to select these two files. We’ll add them to the GraphPaper project in the next step.Drag the two-file selection from the Finder and drop it ...
Get Building Cocoa Applications: A Step by Step Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.