KU Compilerbau - Programming Assignment

Size: px
Start display at page:

Download "KU Compilerbau - Programming Assignment"

Transcription

1 KU Compilerbau - Programming Assignment Univ.-Prof. Dr. Franz Wotawa, Birgit Hofer Institute for Software Technology, Graz University of Technology April 20, 2011 Introduction During this semester you will build a simple C compiler in Java using ANTLR 3.3. You can to this together with 3 of your colleagues (4 students per group at maximum). Your compiler should be able to translate a program written in the simplified C language described below to Java bytecode. Figure 1(b) illustrates the different phases of a compiler. The phases which will be part of your exercise are highlighted in Grey. (a) Language processing system (b) Compiler phases Figure 1: Compiler 1

2 The following table gives an overview of your tasks and the delivery deadlines of them. Task Reachable Points Deadline 0 Group Registration Lexical Analysis Syntax Analysis Type Checking Intermediate Code Code Generation General rules You have to deliver tasks 1-5 via SVN. You must always hand in something, since the tasks build on the previous tasks. If you are not able to solve one of the tasks you will get the source code of another group on request so that you are able to finish the other tasks. You must document the percentage of participation of each team member for each task in the README file. You will get the points reached for each task via . There are mandatory interviews at the end of task 5. File/folder hierarchy Your SVN repository must have a branch for each task. The branches must have the name task {number} where {number} is replaced by the actual task number. Each branch must have the following structure. Please take care that the required documents are in the correct folders. task {number}/ build.xml doc/ lib/ src/ test/ readme.txt readme.txt **/*.java NEW: SimpleC.g The file readme.txt must contain the table with the percentage of participation all changes made (e.g. bug correction) with respect to the previous tasks in clear and short sentences known limitations / bugs implemented additional tasks 2

3 lib The directory lib should contain the ANTLR and the JUnit.jar files. build.xml The file build.xml must define an ant task compile which compiles the grammar-file to Java files and compiles all Java files from src. an ant task run-junit which depends on compile, compiles all Java files from test, runs all JUnit tests and creates an xml file in the output folder. You can use the BUILD file from the framework. Framework You can download a simple framework from course web site. This framework contains all required libraries (ANTLR, JUnit ), skeletons of the required classes, JUnit test files, example input and output files, an example README file and an example BUILD file. Upload these files to your repository and modify and extend them. 3

4 The Grammar Syntax program declarations function declarations declarations declarations type identifier-list; declarations function head; ɛ identifier list identifier identifier-list, identifier identifier id * identifier type int char void function declarations function declaration function declarations ɛ function declaration function head function body function head type identifier arguments arguments ( parameter-list ) ( ) parameter list type identifier parameter list, type identifier function body { declarations optional statements } compound statement { optional statements } optional statements statement list ɛ statement list statement statement list statement statement compound statement if (assignment expr) statement else statement for (expr stmt expr stmt assignment expr) statement expr stmt return assignment expr ; expr stmt ; assignment expr ; assignment expr identifier assignop expression identifier assignop & identifier expression expression simple expression simple expression relop assign simple expression simple expression term sign term simple expression sign term simple expression or term term factor term mulop factor factor identifier function call NEW: int ( assignment expr ) not factor literal string function call identifier ( extend assignment expr list ) identifier ( ) extend assignment expr list assignment expr & identifier extend assignment expr list, assignment expr extend assignment expr list, & identifier relop assign relop 4

5 assignop Operators relop < <= > >= == sign + - mulop * / % && assignop = or not! Identifiers id letter ( letter digit )* letter [a-za-z] digit [0-9] String literals literal string ( [ 0-9a-zA-Z ]! % escape sequence relop sign mulop assignop )* Numerical literals int decint octint hexint decint 0 digit digit0* hexint 0 (x X) hexdigit+ octint 0 octdigit+ digit [1-9] digit0 [0-9] hexdigit [0-9a-fA-F] octdigit [0-7] Escape sequences \ n newline \ t horizontal tab \ b backspace \ r carriage return \ f form feed \ single quote \ double quote \\ backslash Comments Comments may appear after any token and are surrounded by /* and */. White spaces White spaces between tokens are optional, with one exception: keywords must be surrounded by white spaces, newlines or the beginning of the program. 5

6 0 Group Registration Groups up to 4 students are allowed. In order to get access to an SVN repository you have to register your group with help of the Web-Interface. The link to the Web-Interface will be posted on Wednesday, March 16 th to the newsgroup. 1 Lexical Analysis Write a lexical analyzer for the subset of the C language described above in Java with ANTLR version 3.3. Name your grammar file NEW: SimpleC.g. Create the class LexicalAnalyzer.java in the package at.tugraz.ist.compilerbau in the directory src with the method public static int lexer(string file path). This method returns 0 if the lexical analysis was successful, otherwise it returns the number of errors found. In addition write the following information to the standard output: Input program abstracted to lexemes and keywords with the same line separations as the original program, line numbers added, all comments and unnecessary white spaces removed, Summary or errors Number of errors found in the source file You can find an example input and output in the framework. Create your own example programs (at least one error-free program and one program which leads to lexical errors) and add them to the test-folder. Extend the JUnit test to test those programs. Create the README file as descripted above and extend the BUILD file if necessary. Task Summary 1. Define an ANTLR grammar file for the shown grammar 2. Implement the requested method for the class LexicalAnalyzer 3. Create example programs and extend the JUnit tests 4. Create a README file 5. Adapt the BUILD file if necessary 6

7 2 Syntax Analysis Write a syntactical analyzer for the grammar described above in Java with ANTLR version 3.3. Extend the file NEW: SimpleC.g. Please note: the grammar above must be transformed into an LL grammar. Create the class SyntaxAnalyzer.java in the package at.tugraz.ist.compilerbau in the directory src with the method public static int checksyntax(string file path). This method returns 0 if the syntax analysis was successful, otherwise it returns the number of errors found. If there exist lexer errors, no syntactical analysis have to be performed. Instead the number of lexical errors should be returned. In addition write the following information to the standard output: Input program abstracted to function definitions a line for every definition of a function/procedure (name + signature) an output for the end of every function/procedure line numbers added Summary or errors Number of errors found in the source file You can find an example input and output in the framework. Create your own example programs (at least one error-free program and one program which leads to syntactical errors) and add them to the test-folder. Extend the JUnit test to test those programs. It makes sense to build an abstract syntax tree, since you need it for the next task. Be careful with left and right associativity and precedence. An operator like + is left-associative: a + b + c is equal to (a + b) + c, but assignment is right-associative: a = b = c means a = (b = c). Update the your README file. Don t forget to document any changes in the lexer you made in this task. Bonus Task Your are allowed to extend the given grammar, e.g., you can add in-line comments. If you extend the language, please make sure that your grammar stays downward compatible, and document your changes in the README file. You can get up to 3 points for extensions. Task Summary 1. Extend your ANTLR grammar file 2. Implement the requested method for the class SyntaxAnalyzer 3. Create example programs and extend the JUnit tests 4. Adapt the README file 7

8 3 Type Checking Create data structures to hold the type information for the identifiers. You will have (at least) int, void, pointers to (pointers to pointers to... ) int or void, and functions with argument and return types. Implement the code to fill the data structures, and to perform type checking. Create the class TypeChecker.java in the package at.tugraz.ist.compilerbau in the directory src with the method public static int checktypes(string file path). This method returns 0 if the type checking analysis was successful, otherwise it returns the number of errors found. If there exist lexical or syntactical errors, no type checking have to be performed. Instead the number of lexical or syntactical errors should be returned. In addition write the following information to the standard output: Type errors Use of undeclared identifiers Use of incorrect type Double declarations (Note: It is allowed to declare a variable in the global scope and in each local scope. But it is an error to declare a variable more than once in any given scope.) Type coercions All type coercions. (For example: cast expression 4 * a from int to real in line 27. ) The type of any operator. (For example, real-real addition * a in line 27.) Definitions of variables, including type and scope. defined in function f with type integer ). (For example: variable a Keep your output readable, e.g., in the form of a table. You can find an example input and output in the framework. The examples shown here do not prescribe the exact form of your output. Define printf and scanf now. Note that printf may have one or two arguments. Create your own example programs (at least one type-correct and one type-incorrect program) and add them to the test-folder. Extend the JUnit test to test those programs. Scopes Note that there are two scopes: a global one for the program and a local one for the current function. Nested scoping is not required, but you can get bonus points for implementing it. NEW: Forward declarations In C it is not allowed to use a variable before it is defined. For instance, if you define a function a, and then a global variable q, you can not use q in a. For functions, the situation is more complicated. If you define a function a, and then a function b, and you use b in a, you are creating an implicit declaration, which assumes, that b returns value of a certain type, e.g., an int. This problem is avoided in C by forward declarations. Don t forget to include forward declarations in your type checking. Type Coercion A coercion occurs if the type of an operand is automatically converted to the type expected by the operator. 1. A conversion to void is always allowed and results in the result being thrown away. For instance, printf returns an int, but (void) printf("hallo") (not allowed in our grammar), or more succinctly printf("hallo") are legal C statements. 8

9 2. A conversion from void is never possible. A void type may not participate in an operation (such as +). A void variable can not be defined. 3. A binary operator (such as + or <, but not && or ) takes either two int, or a char and an int (in either order). In the latter case, the char is converted to int before the operation is performed. (You can not do arbitrary arithmetic on pointers. In C, adding pointer and int is allowed, but you do not need to support it. Comparison of pointers (a<b) is allowed!) 4. A char can be assigned to an int and is converted automatically. An int can also be converted to a char automatically; this may lead to loss of information. 5. int, char and pointers can be used in Boolean expressions. An int or char with the value 0 is false, any other value is true. Pointers are NULL (false) or non-null (true). Boolean operators (&&,, <, >, etc.) return an int. 6. Any pointer conversion is allowed, and never leads to an error. A warning of an invalid cast is appreciated, and if you implement such warnings consequently, you ll get bonus points. Conversions between pointers and ints are not supported. Bonus Tasks Warnings for invalid pointer casts: 2 points Implementation of nested scopes: 2 points Extend the type system to include more types. Note: coercion rules in C are not quite trivial. Points depend on your exact plans. Don t forget to clearly document the implemented bonus taks in the README file. Task Summary 1. Implement the requested method for the class TypeChecker 2. Define printf and scanf 3. Create example programs and extend the JUnit tests 4. Adapt the README file 9

10 4 Intermediate Code Build an Intermediate Code Generator which is able to build the intermediate code for any program written in our grammar. Create the class IntermediateCode.java in the package at.tugraz.ist.compilerbau in the directory src with the method public static int createintermediatecode(string file path). This method returns 0 if the intermediate code generation was successful, otherwise it returns the number of (lexical, syntactical or type) errors found. In addition it writes the ASCII representation of the intermediate code to the standard output. Use comments to clarify which part of the C code corresponds to the intermediate code. Three-Address Code The three address code should support the following commands: Assigments of the form x := y op z, where op is one of int+, int-, int*, int/, int%, which take two integers and return the corresponding result. int&&, int, which take two integers and return 0 or 1. int<, int<=, int>=, int>, int==, which take two integers and return 0 or 1. Assignments of the form x := op y, where op is one of intminus intnot and y is a variable. op is one of address, dereference and y is a variable. op is one of intconst, pointerconst, and y is an integer constant or a label, respectively. The assignment x *= y, stating that y should be assigned to the location that x points to. (Translates the C statement *x = y.) A constant declaration string a, where a is a quoted string ( hello!\ 0 ). Copy statements: x := y. Jumps The label label L. The unconditional jump goto L, where L is a label Conditional jump ifint x goto L, where x is an int and L a label. For functions The statement param x, which says that x is a parameter to the next function call. Parameters should be listed from right to left. The statement call f n, where f is the name of a function and n is the number of parameters. The statement function f n, where f is a function, and n is the number of local variables, including temporary ones. The statements return and return x, which return from the function, possibly returning the value in x.if you want your compiler to be gcc compatible, you need to distinguish between int and char returns. This is not part of the assignment. The statement local x i, where x is a local variable, a temporary variable, or an argument, and i is a number to reserve space. For locals and temps, i should be negative and run from -1 down. 10

11 For arguments, i should be positive and run from 0 up (the left argument has number 0). The statement getresult x, which stores the return value of the last function call (if any) in x. The statement global x i, where x is a variable name, and i is a number, starting at 0, running up. The statement comment x, which is ignored. This list might be incomplete. Your are allowed to add additional commands. Post your additions to the newsgroup so that others can benefit from them. Don t forget to document your extensions in the README file. You do not have to pay attention to efficiency of time or space. In the intermediate code (but not in C ), every function has to end with a return. Boolean values Truth values are represented by integers: 0 is false, anything else is true. generated by a comparison, &&, or may only be 0 or 1. A truth value Pointers Pointers are treated like ints. Implementation Suggestion Create an inheritance hierarchy, with the class Statement on top. Other Statements inherit from this class. Your intermediate code program is a vector of Statements, each Statement can print itself. Later, each Statement will know how to translate itself to e.g. assembler code or Java bytecode. Use an attributed grammar on the abstract syntax tree to generate the code. A function node, for example, should get the intermediate code from its children (declarations, statements), plus the number of temp variables, so that it can construct the function name number statement. The intermediate code for the function node consists of this statement and the intermediate code for the body. Bonus Task You need not to implement short-circuit evaluation for Boolean expressions. You will get 2 bonus points for implementing short circuiting. Task Summary 1. Implement the requested method for the class IntermediateCode 2. Update your README file 11

12 5 Code Generation Implement the translation of the intermediate code to Java bytecode. Create the class CodeGeneration.java in the package at.tugraz.ist.compilerbau in the directory src with the method public static int createcode(string file path). This method creates the output file <file>.class, where <file>.c is the name of the input file. The method returns 0 if the code generation was successful, otherwise it returns the number of (lexical, syntactical or type) errors found. Your program must be executable by the Java Virtual machine. Printf and scanf must work. NEW: Option Instead of directly producing bytecode, you are allowed to produce code in an assembler-like syntax (Jasmin). In this case your output files must end with.j. It must be possible to translate the generated output files to bytecode by using Jasmin 2.4. Don t forget to add jasmin.jar to your libs-folder. Task Summary 1. Implement the requested method for the class CodeGeneration 2. Update your README file 12

KU Compilerbau - Programming Assignment

KU Compilerbau - Programming Assignment 716.077 KU Compilerbau - Programming Assignment Dr. Birgit Hofer, Univ.-Prof. Dr. Franz Wotawa Institute for Software Technology, Graz University of Technology March 11, 2014 Introduction During this semester

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

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

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

A Short Summary of Javali

A Short Summary of Javali A Short Summary of Javali October 15, 2015 1 Introduction Javali is a simple language based on ideas found in languages like C++ or Java. Its purpose is to serve as the source language for a simple compiler

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

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

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Contents 1 Introduction...2 2 Lexical Conventions...2 3 Types...3 4 Syntax...3 5 Expressions...4 6 Declarations...8 7 Statements...9

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking CSE450 Translation of Programming Languages Lecture 11: Semantic Analysis: Types & Type Checking Structure Project 1 - of a Project 2 - Compiler Today! Project 3 - Source Language Lexical Analyzer Syntax

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

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

CS /534 Compiler Construction University of Massachusetts Lowell. NOTHING: A Language for Practice Implementation CS 91.406/534 Compiler Construction University of Massachusetts Lowell Professor Li Xu Fall 2004 NOTHING: A Language for Practice Implementation 1 Introduction NOTHING is a programming language designed

More information

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Language Reference Manual simplicity

Language Reference Manual simplicity Language Reference Manual simplicity Course: COMS S4115 Professor: Dr. Stephen Edwards TA: Graham Gobieski Date: July 20, 2016 Group members Rui Gu rg2970 Adam Hadar anh2130 Zachary Moffitt znm2104 Suzanna

More information

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer Assigned: Thursday, September 16, 2004 Due: Tuesday, September 28, 2004, at 11:59pm September 16, 2004 1 Introduction Overview In this

More information

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

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010 IPCoreL Programming Language Reference Manual Phillip Duane Douglas, Jr. 11/3/2010 The IPCoreL Programming Language Reference Manual provides concise information about the grammar, syntax, semantics, and

More information

SFU CMPT 379 Compilers Spring 2018 Milestone 1. Milestone due Friday, January 26, by 11:59 pm.

SFU CMPT 379 Compilers Spring 2018 Milestone 1. Milestone due Friday, January 26, by 11:59 pm. SFU CMPT 379 Compilers Spring 2018 Milestone 1 Milestone due Friday, January 26, by 11:59 pm. For this assignment, you are to convert a compiler I have provided into a compiler that works for an expanded

More information

Decaf Language Reference

Decaf Language Reference Decaf Language Reference Mike Lam, James Madison University Fall 2016 1 Introduction Decaf is an imperative language similar to Java or C, but is greatly simplified compared to those languages. It will

More information

Java Notes. 10th ICSE. Saravanan Ganesh

Java Notes. 10th ICSE. Saravanan Ganesh Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses

More information

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

Crayon (.cry) Language Reference Manual. Naman Agrawal (na2603) Vaidehi Dalmia (vd2302) Ganesh Ravichandran (gr2483) David Smart (ds3361) Crayon (.cry) Language Reference Manual Naman Agrawal (na2603) Vaidehi Dalmia (vd2302) Ganesh Ravichandran (gr2483) David Smart (ds3361) 1 Lexical Elements 1.1 Identifiers Identifiers are strings used

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

IC Language Specification

IC Language Specification CS 301 Spring 2016 IC Language Specification The IC Language For the implementation project, you will build a compiler for an object-oriented language called IC (for Irish Coffee 1 ), which is essentially

More information

Sprite an animation manipulation language Language Reference Manual

Sprite an animation manipulation language Language Reference Manual Sprite an animation manipulation language Language Reference Manual Team Leader Dave Smith Team Members Dan Benamy John Morales Monica Ranadive Table of Contents A. Introduction...3 B. Lexical Conventions...3

More information

Time : 1 Hour Max Marks : 30

Time : 1 Hour Max Marks : 30 Total No. of Questions : 6 P4890 B.E/ Insem.- 74 B.E ( Computer Engg) PRINCIPLES OF MODERN COMPILER DESIGN (2012 Pattern) (Semester I) Time : 1 Hour Max Marks : 30 Q.1 a) Explain need of symbol table with

More information

ARG! Language Reference Manual

ARG! Language Reference Manual ARG! Language Reference Manual Ryan Eagan, Mike Goldin, River Keefer, Shivangi Saxena 1. Introduction ARG is a language to be used to make programming a less frustrating experience. It is similar to C

More information

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

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance. 2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

More information

Program Fundamentals

Program Fundamentals Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

More information

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

GBIL: Generic Binary Instrumentation Language. Language Reference Manual. By: Andrew Calvano. COMS W4115 Fall 2015 CVN GBIL: Generic Binary Instrumentation Language Language Reference Manual By: Andrew Calvano COMS W4115 Fall 2015 CVN Table of Contents 1) Introduction 2) Lexical Conventions 1. Tokens 2. Whitespace 3. Comments

More information

SFPL Reference Manual

SFPL Reference Manual 1 SFPL Reference Manual By: Huang-Hsu Chen (hc2237) Xiao Song Lu(xl2144) Natasha Nezhdanova(nin2001) Ling Zhu(lz2153) 2 1. Lexical Conventions 1.1 Tokens There are six classes of tokes: identifiers, keywords,

More information

B.V. Patel Institute of BMC & IT, UTU 2014

B.V. Patel Institute of BMC & IT, UTU 2014 BCA 3 rd Semester 030010301 - Java Programming Unit-1(Java Platform and Programming Elements) Q-1 Answer the following question in short. [1 Mark each] 1. Who is known as creator of JAVA? 2. Why do we

More information

These are reserved words of the C language. For example int, float, if, else, for, while etc.

These are reserved words of the C language. For example int, float, if, else, for, while etc. Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.

More information

Typescript on LLVM Language Reference Manual

Typescript on LLVM Language Reference Manual Typescript on LLVM Language Reference Manual Ratheet Pandya UNI: rp2707 COMS 4115 H01 (CVN) 1. Introduction 2. Lexical Conventions 2.1 Tokens 2.2 Comments 2.3 Identifiers 2.4 Reserved Keywords 2.5 String

More information

Compiler Construction. (1 Design practical)

Compiler Construction. (1 Design practical) S C I E N C E n P A S S I O N n T E C H N O L O G Y (1 ) 716.077 SS 2017 Univ.-Prof. Dr. Franz Wotawa, DI Roxane Koitz Martin Zimmermann, Christopher Liebmann, Stephan Frühwirt Institute for Software Technology

More information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points) Standard 11 Lesson 9 Introduction to C++( Up to Operators) 2MARKS 1. Why C++ is called hybrid language? C++ supports both procedural and Object Oriented Programming paradigms. Thus, C++ is called as a

More information

1.1 Introduction to C Language. Department of CSE

1.1 Introduction to C Language. Department of CSE 1.1 Introduction to C Language 1 Department of CSE Objectives To understand the structure of a C-Language Program To write a minimal C program To introduce the include preprocessor command To be able to

More information

COMS W4115 Programming Languages & Translators GIRAPHE. Language Reference Manual

COMS W4115 Programming Languages & Translators GIRAPHE. Language Reference Manual COMS W4115 Programming Languages & Translators GIRAPHE Language Reference Manual Name UNI Dianya Jiang dj2459 Vince Pallone vgp2105 Minh Truong mt3077 Tongyun Wu tw2568 Yoki Yuan yy2738 1 Lexical Elements

More information

Decaf Language Reference Manual

Decaf Language Reference Manual Decaf Language Reference Manual C. R. Ramakrishnan Department of Computer Science SUNY at Stony Brook Stony Brook, NY 11794-4400 cram@cs.stonybrook.edu February 12, 2012 Decaf is a small object oriented

More information

Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O

Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O Overview of C Basic Data Types Constants Variables Identifiers Keywords Basic I/O NOTE: There are six classes of tokens: identifiers, keywords, constants, string literals, operators, and other separators.

More information

Programming for Engineers Introduction to C

Programming for Engineers Introduction to C Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

More information

Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

More information

Programming Assignment I Due Thursday, October 7, 2010 at 11:59pm

Programming Assignment I Due Thursday, October 7, 2010 at 11:59pm Programming Assignment I Due Thursday, October 7, 2010 at 11:59pm 1 Overview of the Programming Project Programming assignments I IV will direct you to design and build a compiler for Cool. Each assignment

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer. The Compiler So Far CSC 4181 Compiler Construction Scanner - Lexical analysis Detects inputs with illegal tokens e.g.: main 5 (); Parser - Syntactic analysis Detects inputs with ill-formed parse trees

More information

Programming in C++ 4. The lexical basis of C++

Programming in C++ 4. The lexical basis of C++ Programming in C++ 4. The lexical basis of C++! Characters and tokens! Permissible characters! Comments & white spaces! Identifiers! Keywords! Constants! Operators! Summary 1 Characters and tokens A C++

More information

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

Full file at   C How to Program, 6/e Multiple Choice Test Bank 2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)

More information

Programming Assignment I Due Thursday, October 9, 2008 at 11:59pm

Programming Assignment I Due Thursday, October 9, 2008 at 11:59pm Programming Assignment I Due Thursday, October 9, 2008 at 11:59pm 1 Overview Programming assignments I IV will direct you to design and build a compiler for Cool. Each assignment will cover one component

More information

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

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are

More information

Project 1: Scheme Pretty-Printer

Project 1: Scheme Pretty-Printer Project 1: Scheme Pretty-Printer CSC 4101, Fall 2017 Due: 7 October 2017 For this programming assignment, you will implement a pretty-printer for a subset of Scheme in either C++ or Java. The code should

More information

C: How to Program. Week /Mar/05

C: How to Program. Week /Mar/05 1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

More information

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation Assigned: Sunday, November 14, 2004 Due: Thursday, Dec 9, 2004, at 11:59pm No solution will be accepted after Sunday, Dec 12,

More information

ASML Language Reference Manual

ASML Language Reference Manual ASML Language Reference Manual Tim Favorite (tuf1) & Frank Smith (fas2114) - Team SoundHammer Columbia University COMS W4115 - Programming Languages & Translators 1. Introduction The purpose of Atomic

More information

GraphQuil Language Reference Manual COMS W4115

GraphQuil Language Reference Manual COMS W4115 GraphQuil Language Reference Manual COMS W4115 Steven Weiner (Systems Architect), Jon Paul (Manager), John Heizelman (Language Guru), Gemma Ragozzine (Tester) Chapter 1 - Introduction Chapter 2 - Types

More information

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

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

Programming Assignment II

Programming Assignment II Programming Assignment II 1 Overview of the Programming Project Programming assignments II V will direct you to design and build a compiler for Cool. Each assignment will cover one component of the compiler:

More information

YOLOP Language Reference Manual

YOLOP Language Reference Manual YOLOP Language Reference Manual Sasha McIntosh, Jonathan Liu & Lisa Li sam2270, jl3516 and ll2768 1. Introduction YOLOP (Your Octothorpean Language for Optical Processing) is an image manipulation language

More information

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All rights reserved. Java application A computer program that executes when you use the java command to launch the Java Virtual Machine

More information

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan Language Processing Systems Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan Semantic Analysis Compiler Architecture Front End Back End Source language Scanner (lexical analysis)

More information

Compiler Techniques MN1 The nano-c Language

Compiler Techniques MN1 The nano-c Language Compiler Techniques MN1 The nano-c Language February 8, 2005 1 Overview nano-c is a small subset of C, corresponding to a typical imperative, procedural language. The following sections describe in more

More information

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

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C Overview The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments

More information

The Warhol Language Reference Manual

The Warhol Language Reference Manual The Warhol Language Reference Manual Martina Atabong maa2247 Charvinia Neblett cdn2118 Samuel Nnodim son2105 Catherine Wes ciw2109 Sarina Xie sx2166 Introduction Warhol is a functional and imperative programming

More information

DEMO A Language for Practice Implementation Comp 506, Spring 2018

DEMO A Language for Practice Implementation Comp 506, Spring 2018 DEMO A Language for Practice Implementation Comp 506, Spring 2018 1 Purpose This document describes the Demo programming language. Demo was invented for instructional purposes; it has no real use aside

More information

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

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science) The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) 1 Overview Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments

More information

Language Fundamentals Summary

Language Fundamentals Summary Language Fundamentals Summary Claudia Niederée, Joachim W. Schmidt, Michael Skusa Software Systems Institute Object-oriented Analysis and Design 1999/2000 c.niederee@tu-harburg.de http://www.sts.tu-harburg.de

More information

QUIZ: What value is stored in a after this

QUIZ: What value is stored in a after this QUIZ: What value is stored in a after this statement is executed? Why? a = 23/7; QUIZ evaluates to 16. Lesson 4 Statements, Expressions, Operators Statement = complete instruction that directs the computer

More information

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are: LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

More information

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Introduction to C Programming Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Printing texts Adding 2 integers Comparing 2 integers C.E.,

More information

University of Arizona, Department of Computer Science. CSc 453 Assignment 5 Due 23:59, Dec points. Christian Collberg November 19, 2002

University of Arizona, Department of Computer Science. CSc 453 Assignment 5 Due 23:59, Dec points. Christian Collberg November 19, 2002 University of Arizona, Department of Computer Science CSc 453 Assignment 5 Due 23:59, Dec 4 100 points Christian Collberg November 19, 2002 1 Introduction Your task is to write a code generator for the

More information

Exercise ANTLRv4. Patryk Kiepas. March 25, 2017

Exercise ANTLRv4. Patryk Kiepas. March 25, 2017 Exercise ANTLRv4 Patryk Kiepas March 25, 2017 Our task is to learn ANTLR a parser generator. This tool generates parser and lexer for any language described using a context-free grammar. With this parser

More information

4 Programming Fundamentals. Introduction to Programming 1 1

4 Programming Fundamentals. Introduction to Programming 1 1 4 Programming Fundamentals Introduction to Programming 1 1 Objectives At the end of the lesson, the student should be able to: Identify the basic parts of a Java program Differentiate among Java literals,

More information

Introduction to C# Applications

Introduction to C# Applications 1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

More information

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

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) Introduction This semester, through a project split into 3 phases, we are going

More information

ECE220: Computer Systems and Programming Spring 2018 Honors Section due: Saturday 14 April at 11:59:59 p.m. Code Generation for an LC-3 Compiler

ECE220: Computer Systems and Programming Spring 2018 Honors Section due: Saturday 14 April at 11:59:59 p.m. Code Generation for an LC-3 Compiler ECE220: Computer Systems and Programming Spring 2018 Honors Section Machine Problem 11 due: Saturday 14 April at 11:59:59 p.m. Code Generation for an LC-3 Compiler This assignment requires you to use recursion

More information

Basics of Java Programming

Basics of Java Programming Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement

More information

C-LANGUAGE CURRICULAM

C-LANGUAGE CURRICULAM C-LANGUAGE CURRICULAM Duration: 2 Months. 1. Introducing C 1.1 History of C Origin Standardization C-Based Languages 1.2 Strengths and Weaknesses Of C Strengths Weaknesses Effective Use of C 2. C Fundamentals

More information

CS 6353 Compiler Construction Project Assignments

CS 6353 Compiler Construction Project Assignments CS 6353 Compiler Construction Project Assignments In this project, you need to implement a compiler for a language defined in this handout. The programming language you need to use is C or C++ (and the

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Principle of Compilers Lecture VIII: Intermediate Code Generation. Alessandro Artale

Principle of Compilers Lecture VIII: Intermediate Code Generation. Alessandro Artale Free University of Bolzano Principles of Compilers. Lecture VIII, 2003/2004 A.Artale (1 Principle of Compilers Lecture VIII: Intermediate Code Generation Alessandro Artale Faculty of Computer Science Free

More information

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things. A Appendix Grammar There is no worse danger for a teacher than to teach words instead of things. Marc Block Introduction keywords lexical conventions programs expressions statements declarations declarators

More information

Syntactic Analysis. The Big Picture Again. Grammar. ICS312 Machine-Level and Systems Programming

Syntactic Analysis. The Big Picture Again. Grammar. ICS312 Machine-Level and Systems Programming The Big Picture Again Syntactic Analysis source code Scanner Parser Opt1 Opt2... Optn Instruction Selection Register Allocation Instruction Scheduling machine code ICS312 Machine-Level and Systems Programming

More information

Compiler Construction D7011E

Compiler Construction D7011E Compiler Construction D7011E Lecture 2: Lexical analysis Viktor Leijon Slides largely by Johan Nordlander with material generously provided by Mark P. Jones. 1 Basics of Lexical Analysis: 2 Some definitions:

More information

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic BIT 3383 Java Programming Sem 1 Session 2011/12 Chapter 2 JAVA basic Objective: After this lesson, you should be able to: declare, initialize and use variables according to Java programming language guidelines

More information

EECS483 D1: Project 1 Overview

EECS483 D1: Project 1 Overview EECS483 D1: Project 1 Overview Chun-Hung Hsiao Jan 11, 2013 Special thanks to Ashutosh 1 Course Websites http://www.eecs.umich.edu/courses/eecs483/ Schedule, lecture slides https://piazza.com/class#winter2013/

More information

Compilers. Compiler Construction Tutorial The Front-end

Compilers. Compiler Construction Tutorial The Front-end Compilers Compiler Construction Tutorial The Front-end Salahaddin University College of Engineering Software Engineering Department 2011-2012 Amanj Sherwany http://www.amanj.me/wiki/doku.php?id=teaching:su:compilers

More information

SMURF Language Reference Manual Serial MUsic Represented as Functions

SMURF Language Reference Manual Serial MUsic Represented as Functions SMURF Language Reference Manual Serial MUsic Represented as Functions Richard Townsend, Lianne Lairmore, Lindsay Neubauer, Van Bui, Kuangya Zhai {rt2515, lel2143, lan2135, vb2363, kz2219}@columbia.edu

More information

Introduction to Programming (Java) 2/12

Introduction to Programming (Java) 2/12 Introduction to Programming (Java) 2/12 Michal Krátký Department of Computer Science Technical University of Ostrava Introduction to Programming (Java) 2008/2009 c 2006 2008 Michal Krátký Introduction

More information

VLC : Language Reference Manual

VLC : Language Reference Manual VLC : Language Reference Manual Table Of Contents 1. Introduction 2. Types and Declarations 2a. Primitives 2b. Non-primitives - Strings - Arrays 3. Lexical conventions 3a. Whitespace 3b. Comments 3c. Identifiers

More information

A brief introduction to C programming for Java programmers

A brief introduction to C programming for Java programmers A brief introduction to C programming for Java programmers Sven Gestegård Robertz September 2017 There are many similarities between Java and C. The syntax in Java is basically

More information

Computer System and programming in C

Computer System and programming in C 1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

Language Reference Manual

Language Reference Manual Espresso Language Reference Manual 10.06.2016 Rohit Gunurath, rg2997 Somdeep Dey, sd2988 Jianfeng Qian, jq2252 Oliver Willens, oyw2103 1 Table of Contents Table of Contents 1 Overview 3 Types 4 Primitive

More information

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

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on: Data and Expressions Data and Expressions Let's explore some other fundamental programming concepts Chapter 2 focuses on: Character Strings Primitive Data The Declaration And Use Of Variables Expressions

More information

CSE 431S Type Checking. Washington University Spring 2013

CSE 431S Type Checking. Washington University Spring 2013 CSE 431S Type Checking Washington University Spring 2013 Type Checking When are types checked? Statically at compile time Compiler does type checking during compilation Ideally eliminate runtime checks

More information

A Simple Syntax-Directed Translator

A Simple Syntax-Directed Translator Chapter 2 A Simple Syntax-Directed Translator 1-1 Introduction The analysis phase of a compiler breaks up a source program into constituent pieces and produces an internal representation for it, called

More information

Homework #3: CMPT-379

Homework #3: CMPT-379 Only submit answers for questions marked with. Homework #3: CMPT-379 Download the files for this homework: wget http://www.cs.sfu.ca/ msiahban/personal/teaching/cmpt-379-spring-2016/hw3.tgz Put your solution

More information

Intermediate Representations

Intermediate Representations Intermediate Representations A variety of intermediate representations are used in compilers Most common intermediate representations are: Abstract Syntax Tree Directed Acyclic Graph (DAG) Three-Address

More information

Homework 1 Simple code genera/on. Luca Della Toffola Compiler Design HS15

Homework 1 Simple code genera/on. Luca Della Toffola Compiler Design HS15 Homework 1 Simple code genera/on Luca Della Toffola Compiler Design HS15 1 Administra1ve issues Has everyone found a team- mate? Mailing- list: cd1@lists.inf.ethz.ch Please subscribe if we forgot you 2

More information

Review for Test 1 (Chapter 1-5)

Review for Test 1 (Chapter 1-5) Review for Test 1 (Chapter 1-5) 1. Introduction to Computers, Programs, and Java a) What is a computer? b) What is a computer program? c) A bit is a binary digit 0 or 1. A byte is a sequence of 8 bits.

More information