CLIP - A Crytographic Language with Irritating Parentheses

Similar documents
CLIP - A Crytographic Language with Irritating Parentheses

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

Typescript on LLVM Language Reference Manual

JME Language Reference Manual

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

The PCAT Programming Language Reference Manual

The Warhol Language Reference Manual

The SPL Programming Language Reference Manual

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

SMURF Language Reference Manual Serial MUsic Represented as Functions

Lexical Considerations

Sprite an animation manipulation language Language Reference Manual

GAWK Language Reference Manual

Spoke. Language Reference Manual* CS4118 PROGRAMMING LANGUAGES AND TRANSLATORS. William Yang Wang, Chia-che Tsai, Zhou Yu, Xin Chen 2010/11/03

Mirage. Language Reference Manual. Image drawn using Mirage 1.1. Columbia University COMS W4115 Programming Languages and Translators Fall 2006

Language Reference Manual simplicity

DINO. Language Reference Manual. Author: Manu Jain

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

Angela Z: A Language that facilitate the Matrix wise operations Language Reference Manual

L-System Fractal Generator: Language Reference Manual

Twister: Language Reference Manual

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

1 Lexical Considerations

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

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

Lexical Considerations

Decaf Language Reference Manual

A Simple Syntax-Directed Translator

Scheme Quick Reference

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

CHIL CSS HTML Integrated Language

Scheme Quick Reference

YOLOP Language Reference Manual

Review of the C Programming Language for Principles of Operating Systems

Crayon (.cry) Language Reference Manual. Naman Agrawal (na2603) Vaidehi Dalmia (vd2302) Ganesh Ravichandran (gr2483) David Smart (ds3361)

X Language Definition

B E C Y. Reference Manual

Language Reference Manual

TML Language Reference Manual

Triangle Manipulation Language TrML Language Reference Manual

Full file at C How to Program, 6/e Multiple Choice Test Bank

easel LANGUAGE REFERENCE MANUAL

MELODY. Language Reference Manual. Music Programming Language

Petros: A Multi-purpose Text File Manipulation Language

DaMPL. Language Reference Manual. Henrique Grando

Functional Programming. Pure Functional Programming

SFPL Reference Manual

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

CS /534 Compiler Construction University of Massachusetts Lowell. NOTHING: A Language for Practice Implementation

CMAT Language - Language Reference Manual COMS 4115

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

FRAC: Language Reference Manual

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

GBL Language Reference Manual

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

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

YAGL: Yet Another Graphing Language Language Reference Manual

Language Reference Manual

Template Language and Syntax Reference

Review of the C Programming Language

EZ- ASCII: Language Reference Manual

PieNum Language Reference Manual

UNIT- 3 Introduction to C++

CHAD Language Reference Manual

GBIL: Generic Binary Instrumentation Language. Language Reference Manual. By: Andrew Calvano. COMS W4115 Fall 2015 CVN

Language Design COMS W4115. Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

Organization of Programming Languages CS3200/5200N. Lecture 11

SMPL - A Simplified Modeling Language for Mathematical Programming

String Computation Program

VLC : Language Reference Manual

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

Operators. Java operators are classified into three categories:

SIPL: Simple Image Processing Language

Unit 3. Operators. School of Science and Technology INTRODUCTION

MR Language Reference Manual. Siyang Dai (sd2694) Jinxiong Tan (jt2649) Zhi Zhang (zz2219) Zeyang Yu (zy2156) Shuai Yuan (sy2420)

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

GraphQuil Language Reference Manual COMS W4115

DEPARTMENT OF MATHS, MJ COLLEGE

Ruby: Introduction, Basics

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

PHPoC vs PHP > Overview. Overview

Language Reference Manual

2.2 Syntax Definition

LCSL Reference Manual

Introduction to Programming Using Java (98-388)

Senet. Language Reference Manual. 26 th October Lilia Nikolova Maxim Sigalov Dhruvkumar Motwani Srihari Sridhar Richard Muñoz

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

BASIC ELEMENTS OF A COMPUTER PROGRAM

COMS W4115 Programming Languages & Translators FALL2008. Reference Manual. VideO Processing Language (VOPL) Oct.19 th, 2008

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

Logisimple. Language Reference Manual. October 16, Introduction 3

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

MatchaScript: Language Reference Manual Programming Languages & Translators Spring 2017

COLOGO A Graph Language Reference Manual

SSOL Language Reference Manual

Project 2 Interpreter for Snail. 2 The Snail Programming Language

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

4. Inputting data or messages to a function is called passing data to the function.

Transcription:

CLIP - A Crytographic Language with Irritating Parentheses Author: Duan Wei wd2114@columbia.edu Yi-Hsiu Chen yc2796@columbia.edu Instructor: Prof. Stephen A. Edwards July 24, 2013

Contents 1 Introduction 3 2 Lexical Conventions 4 2.1 Notation Conventions............................... 4 2.2 Comments..................................... 4 2.3 Identifiers..................................... 4 2.4 Keywords..................................... 4 3 Type 4 3.1 Basic Data Types................................. 4 3.2 Derived Data Types............................... 5 4 Syntax 5 4.1 Variable Declaration............................... 5 4.2 Function Declaration............................... 6 4.3 Function Evaluation............................... 6 5 Expressions and Functions 6 5.1 Binding Functions................................. 7 5.1.1 let.................................... 7 5.1.2 set.................................... 7 5.2 If-Else....................................... 7 5.3 Arithmetic Functions............................... 8 5.3.1 +...................................... 8 5.3.2 *...................................... 8 5.3.3 -, /, mod, power, inverse...................... 8 5.4 Logic functions.................................. 9 5.4.1 and, or.................................. 9 5.4.2 not.................................... 9 5.5 Comparison Functions.............................. 9 5.5.1 less, greater, leq, geq....................... 9 5.5.2 eq, neq.................................. 9 5.6 Bit Functions................................... 9 5.6.1 &...................................... 9 5.6.2...................................... 10 5.6.3 ˆ...................................... 10 5.6.4 parity.................................. 10 5.7 Shift and Rotation................................ 10 5.7.1 <<, >>................................... 10 5.7.2 <<<, >>>................................. 10 5.8 Vector Function.................................. 11 5.8.1 group................................... 11 5.8.2 merge................................... 11 1

5.8.3 make-vector.............................. 11 5.8.4 map.................................... 12 5.8.5 reduce.................................. 12 5.8.6 transpose................................ 12 5.9 Miscellaneous Functions............................. 12 5.9.1 lambda.................................. 12 5.9.2 zero.................................... 13 5.9.3 rand.................................... 13 5.9.4 int-of-bits.............................. 13 5.9.5 print................................... 13 6 Grammar 14 2

1 Introduction This manual describes CLIP, which is a programming language designed specifically for cryptographers. The purpose of CLIP is to provide users with an efficient and simple programming language to manipulate cryptographic operations, create innovative cryptographic algorithms and implement existing cryptographic protocols. As inheriting the mathematical nature of cryptography, CLIP is designed as a functional language. Its syntax is inspired by the classical functional language Lisp, but with more special types and operations to implement cryptographic algorithms. Essentially, CLIP allows cryptographers to build programs with more convenience than many other popular programming languages. 3

2 Lexical Conventions CLIP has five classes of tokens: identifiers, keywords, constants, functions and other separators. Blanks, horizontal and vertical tabs, newlines and comments are ignored except as they separate tokens. Some whitespace is required to separate otherwise adjacent identifiers, keywords and constants. 2.1 Notation Conventions Through the document, keywords are in magenta monospace, and built-in functions are in cyan monospace. Regular expression-like constructs are used to present the grammar. 2.2 Comments A single line comment should begin with, and ends till the end of that line is encountered. A multi-line comment should start with and end with. Comments can nest, but they do not occur within a string or character literals. 2.3 Identifiers An identifier is a sequence of alphabetic letters, digits and hyphens, with the first one being an alphabetic letter. 2.4 Keywords The following identifiers are reserved as keywords and build-in functions. They should not be used as identifiers. int, bit#, string, defun, defvar let, set, if, mod, pow, inverse, and, or, not less, greater, leq, geq, eq, neq parity, group, merge, make-vector, map, reduce, transpose zero, lambda, rand, int-of-bit, print 3 Type 3.1 Basic Data Types In CLIP, there are three non-function basic data types int: An integer with unlimited precision. bit#n: A bit sequence consist of n bits. 4

string: A series of characters. Note that, specially, the type bit#1 is also used as boolean value, which is the return type of logic functions. 0 means false and 1 means true. 3.2 Derived Data Types In addition, there is a derived type which is denoted as: type[index-1][index-2]...[index-n] This suggests a vector, with type being the type of elements consist of vector, and [index-1] [index-2]...[index-n] being a series of positive whole numbers enclosed in square brackets, indicates the dimensionality of the vector. The element in the vector should be in the same type. The number of square brackets suggests the dimension of vector. For examples, bit#2[5][5] is a vector with two dimensions, while each dimension is five, and the elements in the vector are all 2-bit sequences. The following construct: vector-name[index-1][index-2]...[index-n] is used to access a particular element in a vector. While index-1 indicates that the element is at position index-1 in the first dimension, index-2 indicates that the element is at position index-2 in the second dimension, etc. All index start with 0. 4 Syntax 4.1 Variable Declaration In general, when we define a non-function data type, we use the keyword devar as following defvar identifier:type value The scope of the identifier defined by defvar begins directly after declaration and exists throughout the whole program. Here are some examples of binding global variables to different types of values defvar n:int = 17 defvar b:bit#3 = 001 defvar s:string = "ThisIsAString" defvar v:bit#8[2][3] = {{ 000 010 010} { 100 000 101}} 5

4.2 Function Declaration defun function-name:return-type argument-1:type-1... = expression; The scope of the function defined by defun begins directly after declaration and exists throughout the whole program. Here is an example of calculating Fibonacci number defun Fib:int n:int = (if (< n 1) 1 (+ (Fib (- n 1)) (Fib (- n 2))); (- n 1) means calling function - with n and 1 as parameters, so it will return n-1. More details about function evaluation are discussed in next sub-section 4.3 Function Evaluation Functions are evaluated with the following construct: (function-name expression-1 expression-2... expression-n) where expression-1 expression-2... expression-n are arguments passed into the function. The arguments must match the number and type of the arguments in the declared function being called. Functions are evaluated when they are called. (merge a) 5 Expressions and Functions There are three kinds of primary expressions as belows. identifier: Its type is specified by its declaration. constant: Its type is int, bits or string. identifier[expression]: An identifier followed by an expression in square brackets is a primary expression that yields the value at the int index of a vector. There are two ways to create a compound expression. function call: The format is (expression-1 expression-2... expression-n) The first expression should be an identifier of a function call or a function call expression which returns a function. 6

special expression: The format is <expr-or-type... > This kind of compound expression is only used in some build-in function (like let, lambda and make-vector), several arguments will be grouped as single expression as an argument. Below, we will introduce the build-in functions of CLIP 5.1 Binding Functions 5.1.1 let Values are bound to names through the construct (let <identifier-1:type-1 value-1>... <identifier-n:type-n value-2> expression) which evaluates expression and binds the value-i to the identifier-i specified in the angle brackets. The scope of the value bound to the identifier through let begins directly after declaration and diminishes when the effect of let ends. $ (let <n 1> (+ n 1)) -> 2 5.1.2 set The set function changes the value of variable that already binded and returns the value. (set identifier value) $ defvar a:int 17; $ a -> 17 $ (set a 23); -> 23 $ a -> 23 The first expression returns 17, the next two expression returns 23. 5.2 If-Else The conditional expression evaluates to the second expression if the first is true, otherwise it evaluates to the third expression. If-else statement could be nested. (if bit#1 expression-1 expression-2) 7

5.3 Arithmetic Functions 5.3.1 + Addition function can have many arguments. It will return the sum of all arguments. The arguments can be an integer or the bit sequence. But the bit sequence need to have same length. Otherwise, it causes error. If all inputs are integers, the return type is also integer. If there is a bit sequence, then the return type is the bit vector with the same length. And the overflow part will be cut off. (+ int-or-bits-1 int-or-bits-2... int-or-bits-n) $ (+ 9 "abc"); -> error: the input type of function + is invalid $ (+ 0011 19 0001) -> 0111 5.3.2 * Multiplication function can have many arguments. Every input should be an integer. The type return value is also an integer. (* int-1 int-2... int-n) 5.3.3 -, /, mod, power, inverse The subtraction, divide, module, power and inverse functions can only take two integer as arguments and returns another integer. (- int-1 int-2) (/ int-1 int-2) (mod int-1 int-2) (pow int-1 int-2) (inverse int-1 int-2) $ (- 23 17) -> 6 $ (/ 9 4); -> 2 $ (mod 23 17) -> 6 $ (pow 3 5) -> 243 $ (inverse 17 23); return a value x such that 17 * x = 1 (mod 23) -> 19 8

5.4 Logic functions 5.4.1 and, or The logic function and, or takes a number of arguments of the type bit#1 and yields a value of true, if the specified relation is true, or a value of false otherwise. (and bit#1-1 bit#1-2... bit#1-n) (or bit#1-1 bit#1-2... bit#1-n) 5.4.2 not The logic function not takes only one argument of the type bit#1 and returns the opposite value. (not bit#1) 5.5 Comparison Functions 5.5.1 less, greater, leq, geq The comparison function less, greater, leq and geq take only two integers as arguments and compares expressions from left to right. Their return value is either true ( 1), if the specified relation is true, or false( 0) otherwise. leq means less than or equal with, while geq means greater than or equal with. The type of both arguments should be integers. (less int-1 int-2) (greater int-1 int-2) (leq int-1 int-2) (geq int-1 int-2) 5.5.2 eq, neq The comparison function eq and neq takes only two arguments and compares expressions from left to right. The return value is true, if the specified relation is true, or false otherwise. eqmeans two arguments compared are equal while neq means not equal. Both arguments can be any types. (eq expression-1 expression-2) (neq expression-1 expression-2) 5.6 Bit Functions 5.6.1 & The bitwise function & takes arguments of the same length bit sequences and yields a bit sequence which is the bitwise sum of all the inputs. (& bit-sequence-1 bit-sequence-2... bit-sequence-n) 9

5.6.2 The bitwise function takes arguments of the same length bits sequences and yields a bit sequence value which is the bitwise or of all the inputs. ( bit-sequence-1 bit-sequence-2... bit-sequence-n) 5.6.3 ˆ The bitwise function ˆ takes arguments of the same length bits sequences and yields a bit sequence value which is the bitwise xor of all the inputs. (ˆ bit-sequence-1 bit-sequence-2... bit-sequence-n) 5.6.4 parity The input of parity function is a bit sequence. It will return one bit to indicate the parity of input. (parity bit-sequence) $ (parity 110101101) -> 0 5.7 Shift and Rotation 5.7.1 <<, >> The shift operators << (left shift) and >> (right shift) are binary operators. The first expression is the bit type value to be shifted, and the second expression is an integer which indicates the number of bits to be shifted. Zeros will be added into those empty bits result from shifting. (<< bit-sequence-1 bit-sequence-2) (>> bit-sequence-1 bit-sequence-2) $ (<< 1111 2) -> 1100 5.7.2 <<<, >>> The rotation operators <<< (left rotate) and >>> (right rotate) are binary operators. The first expression is the bit type value to be rotated, and the second expression is an integer which indicates the number of bits to be rotated. 10

(<<< bit-sequence-1 bit-sequence-2) (>>> bit-sequence-1 bit-sequence-2) $ (<<< 11110000 3) -> 10000111 5.8 Vector Function 5.8.1 group The group function operates on a bit sequence, it cuts the bit sequence into pieces whose lengths are indicated by another integer parameter, then returns those pieces as a bits vector. (group bit-sequence-1 bit-sequence-2) $ (group 001011110010 4) -> { 0010 1111 0010} 5.8.2 merge The merge operator is the opposite of group operator. It operates on a bits vector and merge the elements sequentially into a single large bit sequence. (merge bits-vector) $ (merge { 0010 1111 0010}) -> 001011110010 5.8.3 make-vector The make-vector function creates an arbitrary dimension vector and returns it. The first expression after make-vector indicates the return type. The second expression generally would be a function indicates the specific elements in the vector. @i suggests the i-th index of the vector. (make-vector <type> expression) $ (make-vector <int[3][3]> (* (+ 1 @1) @2)) -> {{0 1 2} {0 2 4} {0 3 6}} 11

5.8.4 map A map function applies a given function to each element of a vector. (map function vector) $ defun plus2:int x:int = (+ x 2); $ (map plus2 {1 3 7}) -> {3 5 9} 5.8.5 reduce The reduce function combines all the elements of a vector using a binary operation. (reduce funtion vector) $ (reduce + 2 {1 3 7}) -> 13 5.8.6 transpose The transpose function operates on a matrix, it returns the matrix whose rows as columns and columns as rows of the original matrix. (transpose 2-dimension-vector) $ (transpose {{ 00 01 10} { 11 11 11}}) -> {{ 00 11} { 01 11} { 10 11}} 5.9 Miscellaneous Functions 5.9.1 lambda The lambda function creates a function without binding to any identifier. The first parameter is the arguments of the output function, which are enclosed by angle bracket. The second parameter is an expression which indicate how the function work. (lambda <var-1, var-2,... var-n> expression) $ ((lambda <x> (+ x 2)) 3) -> 5 12

5.9.2 zero The zero function takes an integer as the parameter and returns a bit sequence with all zeros and its size is the parameter. (zero int) $ (zero 5) -> 00000 5.9.3 rand The rand generate a bit sequence randomly whose length is indicated by the integer parameter. (rand int) $ (rand 9) -> 010011011 5.9.4 int-of-bits The int-of-bits function transforms a bit sequence into an integer. The conversion is in little-endian sense. (int-of-bits bit-sequence) $ (int-of-bits 1011) -> 13 5.9.5 print The print function prints a sequence of expressions and returns a single bit 1 after succeeded in printing. The expressions can be any type. (print expression-1... expression-n) 13

6 Grammar Below is a recapitulation of the grammar that was given above. The precedence of expressions is the same order as they are presented below. Expressions in the same group (indicates by ; ) are given the same precedence. expr = constant; identifier (expr) ;<expr-or-type>; (function expr) type-declaration = identifier:type value-binding = defvar type_declaration = expr function-binding = defun type-declaration argument-list= expr argument-list = identifier:type type = basic-type type[ ] 14