Reference Manual – Outline, also some rough info filled in



The Cupcake Programming Language

Language Reference Manual

Project Manager Jeansun Lee

Language and Project Editor Alan Yeung

System Architect Dave Coulthart

System Integrator Jennifer Lee

Validation and Test Engineer Russell Klopfer

Programming Languages and Translators

Professor Aho

31 March 2004

I. Lexical Conventions

A. Tokens

Tokens are the basic building blocks of the language. The following types of tokens are discussed in this section:

• identifiers

• keywords

• constants

• string literals

• operators

B. Comments

To comment out a line, simply precede it with a double forward slash: //.

For example,

// This is a comment.

Block commenting is not permitted, and cannot occur in string literals.

comment ( '//' (~linebreak)* linebreak

C. Identifiers

An identifier is string of letters and numbers that does not start with a number. Our language is not case sensitive, which means that uppercase and lowercase letters are considered the same.

id ( alpha (alpha | digit)*

D. Keywords

The following identifiers are reserved as keywords which may not be used otherwise, and are discussed in detail in following sections:

if

else

for

to

while

string

int

true

false

and

or

not

E. Character Constants

Character constants include alphanumeric characters as well as the following special symbols:

newline \n

tab \t

backslash \\

double quote \”

F. String Literals

A string literal is a sequence of characters enclosed in double quotes, such as, “I’m coocoo for coco puffs.” String literals are inherently sequences of characters; therefore character constants can be enclosed in the double quotations.

string ( '”' ( ~( '”' ) | ( '\”' ) ) '”'

II. Types of Identifiers

These are discussed in detail in later sections.

A. Basic types: int, string

B. Derived types: arrays

C. Reserved objects

Some objects are considered to be standard to any programs programmable by Cupcake. Therefore, we have created some reserved objects that the programmer can (and probably will) use in his game.

D. Internal functions

These are functions that are intrinsic to the language that the programmer can call at any time.

III. Expressions

A. Array References

Array reference is restricted to one or two dimensional set of numbers (all of type ‘integer’). An array is represented by an identifier, declared with a lower and upper bound for each dimension.

B. Multiplicative Operators

Multiplicative operator * produces a value that is the product of its operands (two or more integers).

arith-term ( arith-factor ( ( '*' | '/' | '%' ) arith-factor )*

C. Additive Operators

Additive operators in Cupcake are used as arithmetic operators or string concatenation operators.

arith-factor ( ( '+' | '-' )? r-value

D. Relational Operators

There are several relational operators that are used to build logic-factors. In Cupcake they are used to compare expressions. The relational operators available in Cupcake are the following: >, =, =’|’’|’ |op1 > op2 |Op1 is greater than op2 |

|>= |op1 >= op2 |Op1 is greater than or equal to op2 |

|< |op1 < op2 |Op1 is less than op2 |

|= Board.End) {

if (CurrentPlayer.Points >= 20) {

Say “You won”;

} else {

MoveTo CurrentPlayer.PreviousPosition;

}

}

Sample Code 2

// First, the programmer sets some parameters for game objects.

Setup {

// programmer-declared arrays

string Trivias[] = { “How many months have 28 days?”,

“How many states in the continental US?” };

string Answers[] = { “12”, “48” };

Board.Spaces = 100; // 100 spaces on the board

Dice.Sides = 6; // A die has six faces

Dice.Number = 1; // There is 1 die.

}

// Things the game has to address at the beginning. Some of it

// will be default, but the programmer can change it.

Start {

int i;

Ask “How many players will there be?”, Players.Number;

for i= 1 to Players.Number {

Ask “Please enter player “ + i + “’s name.”, Players[i].Name;

}

}

// Specify what happens in a 'turn.'

Turn {

string Answer;

RollDice;

MoveAhead Dice.Value;

if( CurrentPlayer.Space == 11 ) {

Ask Trivias[1], Answer;

if ( Answer == Answers[1] ) {

Say “Nice job! You got 15 points.”;

CurrentPlayer.Points += 15;

} else {

Say “Nice try. YOU LOST 5 POINTS.”;

CurrentPlayer.Points -= 5;

}

}

if( CurrentPlayer.Space == 38 ) {

Ask Trivias[2], Answer;

if ( Answer == Answers[2] ) {

Say “Nice job! You got 5 points.”;

CurrentPlayer.Points += 5;

} else {

Say “Nice try. YOU LOST 1 POINT.”;

CurrentPlayer.Points -= 1;

}

}

Say “You have “ + CurrentPlayer.Points + “ points.”;

}

// Specify what happens when you check to see if someone wins.

Win {

if (CurrentPlayer.Position >= Board.End) {

if (CurrentPlayer.Points >= 10) {

Say “You won”;

} else {

MoveTo Board.Start;

}

}

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download