do fifty-two: An Introductory Programming Language

Similar documents
do fifty two: Language Reference Manual

Full file at

Introduction to Programming Using Java (98-388)

CS106X Handout 03 Autumn 2012 September 24 th, 2012 Getting Started

Chapter 2 Working with Data Types and Operators

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

1007 Imperative Programming Part II

JME Language Reference Manual

SECTION II: LANGUAGE BASICS

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

Text Input and Conditionals

CPS122 Lecture: From Python to Java

Full file at

Basics of Java Programming

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output

Lecture 2 Tao Wang 1

Intro. Scheme Basics. scm> 5 5. scm>

Language Proposal: tail

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

Operators. Java operators are classified into three categories:

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

GOLD Language Reference Manual

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Variables One More (but not the last) Time with feeling

PHP. Interactive Web Systems

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

3. Simple Types, Variables, and Constants

GridLang: Grid Based Game Development Language Language Reference Manual. Programming Language and Translators - Spring 2017 Prof.

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2 Getting Started with Python

Flow Control. So Far: Writing simple statements that get executed one after another.

COMP 202 Java in one week

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

CS50 Supersection (for those less comfortable)

CS 231 Data Structures and Algorithms, Fall 2016

CGS 3066: Spring 2015 JavaScript Reference

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

Classwork 7: Craps. N. Duong & R. Rodriguez, Java Crash Course January 6, 2015

Chapter 2: Programming Concepts

4 Programming Fundamentals. Introduction to Programming 1 1

If Statements, For Loops, Functions

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Chapter 3: Operators, Expressions and Type Conversion

2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C

Java+- Language Reference Manual

These are notes for the third lecture; if statements and loops.

Variables, Constants, and Data Types

easel LANGUAGE REFERENCE MANUAL

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

Language Reference Manual

egrapher Language Reference Manual

Chapter 2. C++ Basics

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

Java Bytecode (binary file)

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:

Variables and Constants

(Not Quite) Minijava

EMBEDDED SYSTEMS PROGRAMMING Language Basics

6.001 Notes: Section 15.1

CS 251 Intermediate Programming Java Basics

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Sprite an animation manipulation language Language Reference Manual

Programming Problems 15th Annual Computer Science Programming Contest

Glossary. (Very) Simple Java Reference (draft, v0.2)

CS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style

Introduction to C++ General Rules, Conventions and Styles CS 16: Solving Problems with Computers I Lecture #2

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

Computer Programming IA

5 The Control Structure Diagram (CSD)

4. Java Project Design, Input Methods

CS112 Lecture: Working with Numbers

CSCE 120: Learning To Code

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal

Introduction to C++ with content from

Java Primer 1: Types, Classes and Operators

Computer Components. Software{ User Programs. Operating System. Hardware

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Onion Language Reference Manual. By: Andrew Aday, (aza2112) Amol Kapoor (ajk2227), Jonathan Zhang (jz2814)

Introduction to Python Part 1. Brian Gregor Research Computing Services Information Services & Technology

EXPRESSIONS AND ASSIGNMENT CITS1001

Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

LECTURE 17. Expressions and Assignment

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

Total Test Questions: 43 Levels: Grades Units of Credit:.50

PIC 10A Flow control. Ernest Ryu UCLA Mathematics

Transcription:

do fifty-two: An Introductory Programming Language Sinclair Target Yichi Liu Josephine Tirtanata Jayson K Ng Yunfei Wang September 23, 2014 Project Group Sinclair Target / wst2109 / Language Guru Yichi Liu / yl3057 / System Integrator Josephine Tirtanata / jt2706 / System Architect Jayson K Ng / jkn2121 / Verification & Validation Yunfei Wang / yw2577 / Manager Motivation Card game languages have been a popular choice among past PLT students. In 2008, one group created a language called PCGSL, for Playing Card Game Simulation Language. In 2009, another group created a language called AIC, for All In the Cards. And in 2012, a third group created a language called Cardigan, which may or may not have been well implemented relative to the others but certainly has the best name of the three. Each of these teams tried to simplify the process of programming a card game by creating a domain-specific language that abstracts away the details common to all card games. But the problem, as this team sees it, is that these languages have in most cases hewed too closely to traditional C-style syntax to be useful. Only people who have already done some programming in a language like C or Java could learn the language in a reasonable amount of time, yet those same people are also capable of programming a card game quite easily by themselves, because programming a card game isnt that difficult. If youre using an objectoriented language, all you really need is a Card class with an integer for rank 1

and maybe a string for suit. Put some instances of that class in an array and youre ready to go. The effort that a language like PCGSL or Cardigan might save is small, and that saved effort is likely going to be offset by the effort required to learn the language in the first place. Proposal We propose a card game language targeted not at proficient programmers but at people who have never programmed before. For these people, programming a card game in something like C or Java would be prohibitively difficult, so it makes sense to give them an alternative language tailored to their inexperience and to the problem of creating a card game. The time they invest in learning this language is not time they might otherwise have spent coding, but rather an opportunity for them to grow more comfortable with the idiosyncrasies of computer programming. Therefore our language will be first and foremost a pedagogical tool. It will not try to compete as an easy option for a programmer who could code a card game in dozens of different ways. It will instead be a way to introduce students to programming as gently as possible in a familiar domain. Our goals for the language then are as follows: do fifty-two, as weve chosen to call it, must be intuitive and high-level, so that students can grasp it without feelings of frustration or despair. But it must also be sufficiently related to more traditional programming languages to serve as a good stepping-stone to them. Specification do fifty-two is an imperative, procedural, statically typed language. In that sense, it is like C and its many progeny in the fundamentals of how it works; a do program consists of a series of statements organized into procedures that act upon variables. But the syntax of the language attempts to be less cryptic and more intuitive to the average non-programmer, while simultaneously incorporating several elements that make programming card games a breeze. operators do includes most of the standard operators found in any programming language, but changes a few so that their meaning is more obvious, and adds two specific 2

Operator Meaning Standard arithmetic operators. Integer +.-. *,/ arithmetic only. Standard precedence. Standard relational operators, =!= <>>= <= except that the equivalence operator is = not ==. Standard precedence. Logical operators and the unary NOT &! operator. No bitwise operators. : Assignment operator. Equivalent to the dot operator in many languages. Accesses a field within an object. Prepend and append operators. Take a Set (see below) and a Card and either adds the >><< card to the front or the back of the Set. If card is null, does nothing. + String Concatenation Operator to card games. In particular, the assignment operator is not an equals sign, because assignment and tests for equality are distinct concepts in programming, yet that fact is often lost on beginner programmers who and quite rightly get confused by the equals sign. An added benefit here is that the actual equality operator can be a single equals sign as opposed to two. 3

Built-in Types Type Number String Boolean Card Set Player Meaning Integer String Boolean A data type representing a card. Fields: Number rank Number suit String desc A data type representing an ordered collection of cards, whether that collection is supposed to be a deck, hand, or something else. Fields: Number size String desc Card top Card bottom A data type representing a player, or possibly a dealer. Fields: Set hand String desc There are really only three primitive types in do, along with a few composite data types meant to facilitate the creation of card games. There are no floating-point numbers, because the rules of card games don t ever as far as we know call for fractional parts. Each of the composite data types has a field called desc, which contains a string description of the data it contains. When an instance of a composite data type is passed as an argument to the output function (see below), the desc field is what gets printed. New data types cannot be created, but the existing data types can be extended. New fields can be added to an existing type like so: typename has typename called variablename A type extension is global and must not appear inside a function. It means that all instances of the first data type have a field of the second data type with the given name. For example, Player has Number called score would make the field Player score available throughout a program. 4

Control Flow Control-flow Statement if, else if, else while, for { } * N Meaning Standard conditional statements. Standard loop statements. Simple loop, executes the statement(s) within the curly braces N times. { } until B Conditional loop. Like a negative do-while. break, continue Standard control statements. do incorporates most of the common control-flow statements with the exception of switch. In addition, it incorporates an intuitive shorthand for expressing simple loops, which can be though of as multiplying a series of statements by a number. The shorthand is redundant, because it could be replaced with a for loop. But in our experience many algorithms can be expressed using only the shorthand, so it might be introduced as a simpler form of looping to students not ready for the intimidating syntax of a for loop, or for the bizarreness that is zero based numbering. Blocks in do are organized according to the indentation rule, like in Python. Multiline statements can be written by using a backslash. Curly braces are used only for the shorthand loop syntax discussed above. Procedure Syntax In do, functions are called procedures. They are not called functions for reasons that will shortly become clear. They might have been called methods, except they are not associated with objects, and they might have been called subroutines, but the term subroutine is intimidating and stuffy. In do, a function is declared like this: do procedurename with Type parametername Additional parameters can be added by using the and keyword. is called like this: A function do procedurename with argumentname Again, arguments can be added by using the and keyword. If a procedure takes no arguments, the procedure declaration and call consists only of the do keyword and the procedure name. Procedures do not have to be declared before 5

they are used. A quick of do is that procedures cannot return a value. This is why they are not functions ; they don t map input to output. All arguments are passed by reference, and the procedure must change those arguments if it is to return anything. Procedures therefore cannot be used as expressions. Conceptually, a procedure can only do something it can only act on certain data to produce a change in state. We believe that this is easier to understand than a function that can return a value and change its arguments. The alternative would have been to disallow pass by reference, but then no procedure could return more than a single value. do is thus a hyper-imperative language. A do program consists mostly of statements with only a few expressions here and there. For large programs, this would become a nightmare. But while the programs remain simple, we believe that using procedures instead of functions is a good thingit better conforms to the laypersons understanding of programming as telling the computer to do things. Remaining Keywords and the do Environment Variable are declared in do according to the following syntax: new typename variablename: value Declared variables are not automatically initialized to anything you must assign a value to a variable when you declare it. Variables are either local to a function or global. The compiler automatically initializes a small set of environmental variables that define properties of the game being played like the number of players or whether aces are high. There is also a variable that represents the deck and one for every participating player. These variables can be reassigned using the configure keyword, like so: configure variablename: value You cannot have a configure assign- A configure assignment is also global. ment within a function. Finally, the functions input and output can be called anywhere in a program. Input reads until a newline character and interprets what it reads according to the type of its argument, where it then stores the input data. Output takes a string and prints it to the console. 6

An Example Program: War! War! is a simple card game often played between children. The rules can be found here. What follows is an implementation of War! in do that showcases most of the features of the language. // war in do configure playercount: 2 configure aceshigh: false new Number warcount: 0 Player has Set called table // player table available setup: // deal cards { player1 hand << deck top } * (deck size / 2) // loop { player2 hand << deck top } * (deck size / 2) // loop round: do turn with player: player1 do turn with player: player2 do output with "Player 1 played: do output with "Player 2 played: do evaluate " + player1 table top " + player2 table top turn with Player player: do output with player + " s turn." if (player hand size = 0) if (player = player1) do output player + " has lost. do quit else do output player + " has lost. do quit Player2 wins!" Player1 wins!" do output with "Play card?" do input with new String in if (in = "y") player hand top >> player table else do output with player + " has decided not to play anymore." // no backslash needed here do quit 7

evaluate: if (player1 table top > player2 table top) do output with "Player 1 s card is higher." { player1 hand << player1 table top } \ * player1 table size { player1 hand << player2 table top} \ * player2 table size else if (player1 table top < player2 table top) do output with "Player 2 s card is higher." { player2 hand << player1 table top } \ * player1 table size { player2 hand << player2 table top } \ * player2 table size else do output with "It s a tie. That means WAR!" warcount: warcount + 1 // if a set runs out of cards >> and << won t do anything { player1 hand top >> player1 table } * 4 { player2 hand top >> player2 table } * 4 do output with "Player 1 and 2 put down 4 cards." do evaluate 8