K Reference Card. Complete example

Similar documents
Operators. Java operators are classified into three categories:

The Warhol Language Reference Manual

Lecture 19: Functions, Types and Data Structures in Haskell

Scheme Quick Reference

Scheme Quick Reference

Data types for mcrl2

BoredGames Language Reference Manual A Language for Board Games. Brandon Kessler (bpk2107) and Kristen Wise (kew2132)

egrapher Language Reference Manual

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Java Primer 1: Types, Classes and Operators

A Short Summary of Javali

SMURF Language Reference Manual Serial MUsic Represented as Functions

Lexical Considerations

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

PLT Fall Shoo. Language Reference Manual

SSOL Language Reference Manual

Lexical Considerations

1 Lexical Considerations

3. Java - Language Constructs I

Functional Programming Languages (FPL)

Language Reference Manual

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010

Typed Racket: Racket with Static Types

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

CSE 142 Su 04 Computer Programming 1 - Java. Objects

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1

11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT

Typescript on LLVM Language Reference Manual

Visual C# Instructor s Manual Table of Contents

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27

Haskell 98 in short! CPSC 449 Principles of Programming Languages

(Not Quite) Minijava

GraphQuil Language Reference Manual COMS W4115

Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

GeoCode Language Reference Manual

Chapter 15. Functional Programming Languages

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Overloading, Type Classes, and Algebraic Datatypes

CPS 506 Comparative Programming Languages. Programming Language Paradigm

Decaf Language Reference Manual

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

Introduction to Programming Using Java (98-388)

SML A F unctional Functional Language Language Lecture 19

XQ: An XML Query Language Language Reference Manual

The SPL Programming Language Reference Manual

RSL Reference Manual

Twister: Language Reference Manual

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics

IFAD. VDMTools Validated. Design through Modelling. Overview of VDM -SL/++ IFAD. IFAD A/S Forskerparken 10 DK-5230 Odense M Denmark.

UNIT- 3 Introduction to C++

Language Reference Manual simplicity

A quick introduction to SML

CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016

A LISP Interpreter in ML

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

VENTURE. Section 1. Lexical Elements. 1.1 Identifiers. 1.2 Keywords. 1.3 Literals

The Typed Racket Guide

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

The pixelman Language Reference Manual. Anthony Chan, Teresa Choe, Gabriel Kramer-Garcia, Brian Tsau

CMPT 125: Lecture 3 Data and Expressions

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

Operators and Expressions

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Review of the C Programming Language for Principles of Operating Systems

Decaf Language Reference

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

Project 2: Scheme Interpreter

ARG! Language Reference Manual

Advanced Algorithms and Computational Models (module A)

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Language Reference Manual

JME Language Reference Manual

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

The PCAT Programming Language Reference Manual

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

Units 0 to 4 Groovy: Introduction upto Arrays Revision Guide

Learning Language. Reference Manual. George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104)

Data Types The ML Type System

Reference Grammar Meta-notation: hfooi means foo is a nonterminal. foo (in bold font) means that foo is a terminal i.e., a token or a part of a token.

CHPSIM. Version 2.0. A Simulator and Debugger for the CHP Language. User Manual. Written by Marcel van der Goot and Chris Moore

ASML Language Reference Manual

Recursion and Induction: Haskell; Primitive Data Types; Writing Function Definitions

Z Notation. June 21, 2018

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Sketchpad Graphics Language Reference Manual. Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321

CS109A ML Notes for the Week of 1/16/96. Using ML. ML can be used as an interactive language. We. shall use a version running under UNIX, called

C++ Programming: From Problem Analysis to Program Design, Third Edition

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1

FRAC: Language Reference Manual

Chapter 2: Using Data

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

DaMPL. Language Reference Manual. Henrique Grando

Sprite an animation manipulation language Language Reference Manual

3. Java - Language Constructs I

CHAD Language Reference Manual

Transcription:

K Reference Card Complete example package examples.example1 annotation doc : String class Date class Person { name : String age : Int ssnr : Int @doc("employee inherits from Person") class Employee extends Person { hoursalary : Int @doc("type Date is abstract") hired : Date req hoursalary >= 15 class Company { employees : Set[Employee] Three classes are defined: Person, Employee, which extends Person, and Company. The example shows the two ways in which a class can be used to define another class: (1) class Employee extends class Person, inheriting from Person all the properties, functions and constraints defined in Person; and (2) class Company contains a property which is a set of Employees. fun hasemployer(e : Employee): Bool { e isin employees req forall e : Employee :- e isin employees => e.age >= 18 Packages package example Package declarations should occur at the top. package examples.example1 Package names can be composed corresponding to folder structure. Imports import util.* Import declarations should occur right after the package declaration. One can import all contents from a different pakage using the.* notation.

import util.date One can import a specific class from a diffrent package. import examples.example1.* Package names in import statements can be composed. Annotations annotation doc : String annotation id : Int @doc("employee inherits from Person") @id(42) class Employee extends Person {... Annnotations occur right after import declarations and before any property, function, constraint or class declarations. Annotations must be declared before used. Here two annotations are declared, one with the name doc of type String and one with the name id of type Int (integers). Annotations are applied using @name(arguments) notation before the declaration they annotate. In this example the class Employee is annotated with two annotations, one documenting the class and one providing an id for the class. Annotations are not translated to SMT. @doc("type Date is imported") hired : Date @doc("following minimum Wage ") req hoursalary >= 10 Annotations can also be applied to properties, functions, and constraints. Class declarations class Person class Person { name : String ssnr : Int class Employee extends Person {... A class can defined without a body. This just introduces a type, the contents of which has not been decided upon yet. A class can contain declararations, such as properties, functions and constraints. In this example the class Person contains the property name of type String and a social security number ssnr of type Int. A class can extend another class, which means that the former class inherits all the properties, functions and constraints from the class it is extending. In this case an Employee inherits from Person,

which for example means that an employee has a social security number ssnr. class SelfEmployed extends Employee, Employer {... Multiple inheritance is allowed. Here class SelfEmployed extends Employee as well as Employer. If both class Employee and Employer extend class Person, class Person is inherited from twice. However, only one copy will be included. Keyword class declarations class <requirement> Requirement {... requirement R1 {... requirement R2 {... A class can be declared with a userprovided keyword in addition to the class name, using the <user-providedkeyword> notation in front of the class name. This allows to write class declarations extending this class using this user-provided keyword instead of using the K keywords class... extends... The declarations to the left have the same semantics as the following: class Requirement {... class R1 extends Requirement {... class R2 extends Requirement {... Top level declarations package tryouterdeclarations minwage : Int req minwage >= 10 fun ok(a: Int):Bool { a >= minwage class Employee extends Person { hoursalary : Int req ok(hoursalary) Properties, functions, and constraints can be declared at the outermost level. Such declarations introduce global entities that can be referred to in for example classes. This example illustrates the declaration of the global property minwage and the global function ok, used in class Employee. Property declarations name : String hoursalary : Int A basic property declaration introduces a name of the property and its type after

taxable : Bool the colon. taxable : Bool = true A property can be given an exact value following the equals symbol (=). Such a property declaration has the exact same semantics as a basic property declaration and a constraint: taxable : Bool req taxable = true employees : Set[Employee] tasks : Seq[Task] class Car { part transmission : Transmission... Properties can have collection types, such as sets and sequences. The property employees is a set of Employees for example. Properties can be annotated with the part modifier. This corresponds to the black diamond ( ) in SysML diagrams, reflecting in this case that a transmission can only be part of one car. Functions fun min(x:int,y:int):int { if x < y then x else y fun taxable(employees: Set[Employee]): Bool { forall e : Employee :- e isin employees => e.taxable fun wellformed(x:real):bool A function is declared by a name, a sequence of typed arguments, a result type and a body, which is an expression in between curly brackets. The min function takes two integer arguments and returns the smallest value. The taxable function takes a set of employees as argument, and returns true if they are all taxable. The wellformed function is declared without a body provided, reflecting that we have not decided how to define it. Constraints req forall e : Employee :- e isin employees => e.hoursalary <= boss.hoursalary req thebossrules : forall e : Employee :- A constraint consists of an optional name (the second requirement is named thebossrules) and a Boolean value expression (of type Bool).

e isin employees => e.hoursalary <= boss.hoursalary Types Bool : true, false Int :..., -2, -1, 0, 1, 2,... Real :..., 0, 3, 0.1, 5.,.5, 1.5E5, 1.5E-5,... String : N/A There are four primitive types, Booleans, integers, reals and strings. For each type possible values are shown after the colon. Although strings can be declared in classes, string values are not currently supported. Employee Set[Employee] A type can in addition be the name of a class (Employee), or a type constructor (for example Set) applied to a type between square brackets, as in Set[Employee], which denotes the type of all sets of employees. Expressions -1, 42 Integer numbers of type Int. 3.4, 3.2E5 Real numbers of type Real. false, true Boolean values of type Bool. 1 + 2 (1 + 2) * 3 Binary expressions consisting of an infix-operator applied to two sub expressions (see operators below.). Parentheses are used to mark to what sub-expressions an operator should be applied. Leaving out the parentheses in this case would cause the expression to evaluate as: 1 + (2 * 3). null Any property the type of which is a class name may denote null. this This pre-defined name refers to the current object, and can be referred to inside a class. It has the same sort of meaning as in Java.

hoursalary An identifier denoting a property declared in scope. e.age ok(hoursalary) min(x,y) Given an object (in this case e), a property (in this case age) of that object can be accessed using dot-notation, similar to Java. Functions are applied with standard notation: function name followed by comma separated arguments in between paretheses.!ok Boolean negation (not ok). if x < y then x else y Conditional expression returning x if x < y is true, and else returning y. person is Employee Testing whether an object (in this case person) has a particular type (in this case Employee). An object x of type S is also of type T (x is T) if S is a subtype of (extends, either directly or indirectly) the type T. -x Negative x. Any integer or real valued expression can be negated. forall e : Employee :- e isin employees => e.age >= 18 exists e : Employee :- e isin employees && e.age >= 18 Universal quantification: for all values e in the type Employee, it holds that if e is a member of the set employees, it implies that the age of e is greather than or equal to 18. Existential quantification: there exists a value e in the type Employee, such that e is a member of the set employees, and the age of e is greather than or equal to 18. {x : Int = 2 y : Int = 3 x + y Block expression: this form of expression allows to build up an expression in steps by binding values to local names that are referred to later in the expression. This particular expression should be read as follows: let x be equal to 2 and let y be equal to 3, then return x + y. Hence the value of

the expression is x + y. Set{ The empty set. Set{1,2,3,4,5 Set enumeration: the set containing the numbers 1 to 5, explicitly enumerated. Set{1.. 5 Set range: the set containing the numbers 1 to 5, given by the lower bound and the upper bound. The resulting set is the same as the one above. Set{ x + 1 x : Int :- 0 <= x && x <= 4 Set comprehension: the set of numbers x + 1, where x is of type Int, and such that x is between 0 and 4. The resulting set is the same as the two above. Operators (Operator precedences provided as numbers, lower number means higher precedence: binds tighter) = (3)!= (3) * (1) + (2) - (2) / (1) % (1) <= (3) >= (3) < (3) > (3) inter (1) union (2) Equality: equal, not equal. Arithmetic operators: multiplication, addition, subtraction, division, modulo (the remainder after division). Arithmetic relational operators: less than or equal, greater than or equal, less than, greater than. Set operators: intersection, union. Set relational operators: isin (3) set membership,

!isin (3) subset (3) psubset (3) negated set membership (not member of), subset (is a subset of), proper subset (s1 proper s2 = s1 subset s2 && s1!= s2). && (4) (5) => (6) <=> (6) Comments Logical operators: and, or, implies, bi-implication. === This is a comment occupying multiple lines. === Multi line comments begin and end with ===. =========================== This is a comment occupying multiple lines. =========================== The begin-comment and end-comment === symbols can be extended. They should just include at least three = symbols. -- This is a single line comment. Single line comments begin with --.