CA4003 Compiler Construction Assignment Language Definition

Similar documents
Decaf Language Reference Manual

Lexical Considerations

1 Lexical Considerations

Lexical Considerations

The PCAT Programming Language Reference Manual

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

Decaf Language Reference

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

Typescript on LLVM Language Reference Manual

Operators. Java operators are classified into three categories:

SMURF Language Reference Manual Serial MUsic Represented as Functions

(Not Quite) Minijava

UNIT- 3 Introduction to C++

CHIL CSS HTML Integrated Language

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Basics of Java Programming

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

The SPL Programming Language Reference Manual

Expr Language Reference

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

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

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

M/s. Managing distributed workloads. Language Reference Manual. Miranda Li (mjl2206) Benjamin Hanser (bwh2124) Mengdi Lin (ml3567)

Sprite an animation manipulation language Language Reference Manual

ASML Language Reference Manual

IC Language Specification

Operators & Expressions

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

YOLOP Language Reference Manual

3. Java - Language Constructs I

A Simple Syntax-Directed Translator

do fifty two: Language Reference Manual

COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts

The Decaf Language. 1 Lexical considerations

More Assigned Reading and Exercises on Syntax (for Exam 2)

JME Language Reference Manual

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

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

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

The Arithmetic Operators

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

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG

CHAD Language Reference Manual

Programming Lecture 3

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 4

JAVA OPERATORS GENERAL

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

CSC 1214: Object-Oriented Programming

Declaration and Memory

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

ARG! Language Reference Manual

X Language Definition

Motivating Examples (1.1) Selections. Motivating Examples (1.2) Learning Outcomes. EECS1022: Programming for Mobile Computing Winter 2018

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

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

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

COMP520 - GoLite Type Checking Specification

Introduction to Computer Science Midterm 3 Fall, Points

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

SML A F unctional Functional Language Language Lecture 19

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

Principles of Programming Languages COMP251: Syntax and Grammars

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

Funk Programming Language Reference Manual

PieNum Language Reference Manual

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

SMPL - A Simplified Modeling Language for Mathematical Programming

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

Full file at

UNIVERSITY OF COLUMBIA ADL++ Architecture Description Language. Alan Khara 5/14/2014

GAWK Language Reference Manual

C Programs: Simple Statements and Expressions

egrapher Language Reference Manual

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

MATLIP: MATLAB-Like Language for Image Processing

Operators. Lecture 3 COP 3014 Spring January 16, 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

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

Compilers. Compiler Construction Tutorial The Front-end

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

BASIC ELEMENTS OF A COMPUTER PROGRAM

Petros: A Multi-purpose Text File Manipulation Language

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

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

VARIABLES & ASSIGNMENTS

Quick Reference Guide

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Turtle Tango (TT) Language Reference Manual

Creating a C++ Program

Here n is a variable name. The value of that variable is 176.

COMS W4115 Programming Languages & Translators GIRAPHE. Language Reference Manual

A First Program - Greeting.cpp

Chapter 3: Describing Syntax and Semantics. Introduction Formal methods of describing syntax (BNF)

Variables and Operators 2/20/01 Lecture #

GraphQuil Language Reference Manual COMS W4115

COMP Primitive and Class Types. Yi Hong May 14, 2015

Transcription:

CA4003 Compiler Construction Assignment Language Definition David Sinclair 2017-2018 1 Overview The language is not case sensitive. A nonterminal, X, is represented by enclosing it in angle brackets, e.g. X. A terminal is represented without angle brackets. A bold typeface is used to represent terminal symbols in the language and reserved words, whereas a non-bold typeface is used for symbols that are used to group terminals and nonterminals together. Source code is kept in files with the.ccl extension, e.g. hello world.ccl. 2 Syntax The reserved words in the language are var, const, return, integer, boolean, void, main, if,, true, false, while,,, is and skip. The following are tokens in the language:, ; : = ( ) + - && ==!= < <= > >= Integers are represented by a string of one or more digits ( 0-9 ) and may start with a minus sign ( - ), e.g. 123, -456. Unless it is the number 0, numbers may not start with leading 0 s. For example, 0012 is illegal. Identifiers are represented by a string of letters, digits or underscore character ( ) ning with a letter. Identifiers cannot be reserved words. Comments can appear between any two tokens. There are two forms of comment: one is delimited by /* and */ and can be nested; the other s with // and is delimited by the of line and this type of comments may not be nested. 1

program = decl list function list main (1) decl list = ( decl ; decl list ǫ) (2) decl = var decl const decl (3) var decl = var identifier: type (4) const decl = const identifier: type = expression (5) function list = ( function function list ǫ) (6) function = type identifier ( parameter list ) is (7) decl list statement bock return ( expression ǫ ) ; type = integer boolean void (8) parameter list = nemp parameter list ǫ (9) nemp parameter list = identifier: type identifier: type, nemp parameter list main = main (10) decl list statement block statement block = ( statement statement block ) ǫ (11) statement = identifier = expression ; (12) identifier ( arg list ) ; statement block if condition statement block statement block while condition statement block skip ; expression = fragment binary arith op fragment (13) ( expression ) identifier ( arg list ) 2

fragment binary arith op = + - (14) fragment = identifier - identifier number true false (15) expression condition = condition (16) ( condition ) expression comp op expression condition ( && ) condition comp op = ==!= < <= > >= (17) arg list = nemp arg list ǫ (18) nemp arg list = identifier identifier, nemp arg list (19) 3 Semantics Declaration made outside a function (including main) are global in scope. Declarations inside a function are local in scope to that function. Function arguments are passed-by-value. Variables or constants cannot be declared using the void type. The skip statement does nothing. The operators in the language are: Operator Arity Description = binary assignment + binary arithmetic addition - binary arithmetic subtraction - unary arithmetic negation unary logical negation binary logical disjunction (logical or) && binary logical conjunction (logical and) == binary is equal to (arithmetic and logical)!= binary is not equal to (arithmetic and logical) < binary is less than (arithmetic) <= binary is less than or equal to (arithmetic) > binary is greater than (arithmetic) >= binary is greater than or equal to (arithmetic) The following table gives the precedence (from highest to lowest) and associativity of these operators. 3

Operator(s) Associativity Notes right to left logical negation - right to left arithmetic negation + - left to right addition & subtraction < <= > >= left to right arithmetic comparison operators ==!= left to right equality & inequality operators && left to right logical conjunction left to right logical disjunction = right to left assignment 4 Examples Three versions of the simplest non-empty file demonstrating that the language is case insensitive. main Main MAIN A simple file demonstrating comments. main // a simple comment / a comment / with / several / nested / comments / The simplest program that uses functions. void func () is return (); 4

main func (); A simple file demonstrating the different scopes. var i : integer ; integer test fn (x: integer) is var i : integer ; i = 2; return (x); main var i : integer ; i = 1; i = test fn ( i ); A file demonstrating the use of functions. integer multiply (x: integer, y: integer) is var result : integer ; var minus sign : boolean ; // figure out sign of result and convert args to absolute values if (x < 0 && y >= 0) minus sign = true ; x = x; 5

if y < 0 && x >= 0 minus sign = true ; y = y; if (x < 0) && y < 0 minus sign = false ; x = x; y = y; minus sign = false ; result = 0; while (y > 0) result = result + x; y = y 1; if minus sign == true result = result ; skip ; return ( result ); 6

main var arg 1 : integer ; var arg 2 : integer ; var result : integer ; const five : integer = 5; arg 1 = 6; arg 2 = five ; result = multiply (arg 1, arg 2 ); 7