KU Compilerbau - Programming Assignment

Size: px
Start display at page:

Download "KU Compilerbau - Programming Assignment"

Transcription

1 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 you will build a simple Calculator compiler in Java using ANTLR 3. Calculator knows basic arithmetic as well as if and for statements and function calls, please see Listing 1 for an example program written in this language. Your compiler should be able to translate a program written in the Calculator grammar 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 Listing 1: Example Calculator program 1 int main ( ) { 2 int n, r e t v a l ; 3 n = 5 ; 4 r e t v a l = print ( n th f i b o n a c c i number : ) ; 5 return print ( f i b o ( n ) ) ; 6 } 7 int f i b o ( int n ) { 8 int a, b, tmp, i, r e t v a l ; 9 n = n 2 ; a = 1 ; b = 1 ; 10 for ( i = 0 ; i < n ; i = i + 1) { 11 tmp = a + b ; 12 a = b ; 13 b = tmp ; 14 } 15 return b ; 16 } Schedule The following table provides an overview of your tasks and the individual delivery deadlines. Task Points Deadline Question Time 1 Lexical and Syntax Analysis 17.5 April, 2 nd March, 31 st 2 Type Checking 17.5 May, 7 th May, 5 th 3 Intermediate Code 17.5 May, 28 th May, 26 th 4 Code Generation 17.5 June, 18 th June, 16 th General rules You have to deliver tasks 1-4 via SVN. Deliveries are mandatory, as further tasks build upon your previous solutions. If you fail to solve one of the tasks, you may request a sample solution to build the further tasks upon. Please note that there are multiple valid approaches for most tasks and the approach chosen for the sample solution may differ significantly from your previously chosen approach. You must document the percentage of participation of each team member for each task in the README file. For tasks 1, 2, and 3 you will receive a notification about your score and comments regarding your solution via . In case you have any questions regarding the points or comments, make use of the office hour (Wednesday, 1 pm) as well as the appointed question time. For general questions, please use the newsgroup (tu-graz.lv.cb) and for personal questions you may reach us via the mailing list (cb@ist.tugraz.at). There is a mandatory interview after completion of task 4, where you will receive your final score. Group Registration Groups of up to four students are allowed. Due to the effort we recommend a size of four students. In order to get access to a SVN repository you have to register your group using the Web-Interface. The link to the Web-Interface will be posted in the newsgroup. 2

3 File/folder hierarchy Your SVN repository must have a folder for each task. The folders must be named task {number}, where {number} is replaced by the actual task number. Each folder must contain the following structure: (Please take care that the required documents are in the correct folders!) task {number}/ build.xml readme.txt lib/ src/ test/ readme.txt junit-4.10.jar antlr-3.5-complete.jar jasmin.jar **/*.java Calculator.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 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. You can use the BUILD file from the framework. It defines an additional ant task run-junit which runs all JUnit tests and creates an xml file in the output folder. Make use of this task for testing purposes! Please note that you have to adopt your build file if you use for example an additional grammar (.g) file. Framework You can download a simple framework from the course web site. This framework contains all required libraries (ANTLR, JUnit, Jasmin), 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, modify and extend them. 3

4 1 Lexical and Syntax Analysis Tasks 1. Write a lexical and syntactical analyzer for the Calculator language described below in Java with ANTLR version 3.5. You have to rewrite the provided grammar into LL(1) using the methods described in the lecture. Modify the provided grammar file Calculator.g in the framework to contain your solution. Do not modify the header with the options of the grammar file, as they are set to only compile LL(1) grammars (backtrack = false;k = 1;). Implement the following methods of the class LexicalAndSyntaxAnalyzer.java in the package at.tugraz.ist.cc in the directory src: public int lexer(string file path, boolean debug) This method returns 0 if the lexical analysis was successful, otherwise it returns the number of errors found. Write a summary of errors you have found to the standard output. This is how the output could look like: Number of lexical errors: 3 #1: line 6:2 no viable alternative at character ï 1 2 #2: line 6:3 no viable alternative at character ï 1 2 #3: line 7:1 no viable alternative at character # If the flag debug is set write the input program abstracted to lexemes and keywords to the standard output. You can find an example input and output in the framework. Note: This output should help you when you are debugging your compiler. (5 points) public int checksyntax(string file path, boolean debug) This method returns 0 if the syntax analysis was successful, otherwise it returns the number of errors found. If there exist lexical errors, no syntactical analysis has to be performed. Instead the number of lexical errors should be returned. Write a summary of the syntactical errors to the standard output. This is how the output could look like: Number of parser errors: 2 #1: line 2:0 mismatched input ; expecting return #2: line 3:0 missing } at int If the flag debug is set write the input program abstracted to function definitions to the standard output. It should contain a line for every definition of a function/procedure (name + signature) an output for the end of every function/procedure line numbers You can find example input and output in the framework. (9 points) 2. Create your own example programs - at least one error-free program, one program which leads to lexical errors and one program which leads to syntactical errors - and add them to the test-folder. Extend the JUnit test to test those programs.(3 points) 3. Create the README file as described above. (0.5 points) 4. Adapt the existing BUILD file or create your own BUILD file. (no points, but mandatory) Hints It makes sense to build an abstract syntax tree, since you need it for the next task. Be careful to properly handle left and right associativity and precedence: All used binary operators are left-associative: a + b + c is equal to (a + b) + c. Operators abide to the following precedence: NOT / unary SIGN > MULOP > SIGN > RELOP > AND > OR > ASSIGNOP Whereby NOT and unary SIGN will be resolved first and ASSIGNOP last. 4

5 Bonus Task You 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. Make suggestions for bonus tasks in the newsgroup. We will answer to your posts if these extensions make sense and how many bonus points you can get for implementing them. The Grammar Operators ASSIGNOP = OR AND && RELOP < <= > >= ==! = SIGN + - MULOP * / % NOT! fragment OPERATORS < > = + / % & Numerical literals INT 0 DIGIT DIGIT0* fragment DIGIT [1-9] fragment DIGIT0 [0-9] Boolean literals BOOLEAN true false Identifiers ID LETTER ( LETTER DIGIT0 )* fragment LETTER [a-za-z] Punctuation PUNCT., ; :! White spaces WS \n \t \r String literals LITERAL ( [ 0-9a-zA-Z ] \\ OPERATORS PUNCT WS )* Terminals are displayed in green, lexemes in uppercase and parser rules in lower case letters. 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 Syntax program functions type int boolean String functions function declaration functions ɛ function declaration function head function body function head type ID arguments arguments ( parameter list ) ( ) parameter list type ID parameter list, type ID function body { declarations optional stmt return stmt } declarations declarations type idlist; ɛ idlist ID idlist, ID optional stmt stmt list ɛ stmt list statement stmt list statement return stmt return expression ; statement compound stmt if(expression) statement else statement for(assignment; expression; assignment) statement assignment ; compound stmt { optional stmt } assignment ID ASSIGNOP expression expression expression OR factor expression AND factor expression RELOP factor expression SIGN factor expression MULOP factor factor factor ID INT BOOLEAN LITERAL NOT factor SIGN factor function call ( expression ) function call ID ( extend assign expr list ) ID ( ) extend assign expr list expression extend assign expr list, expression 6

7 2 Type Checking Tasks 1. Implement the method public int checktypes(string file path, boolean debug) within the class TypeChecker.java in the package at.tugraz.ist.cc in the directory src. 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 has to be performed. Instead, the number of lexical or syntactical errors should be returned. Write a summary of the type errors you have found to the standard output. The output should contain: Use of undeclared identifiers. This includes access of undefined variables as well as calls to undefined functions. Use of incorrect operand types. Double declarations of variables and functions. This is how the output could look like: Number of type checking errors: 2 #1: Usage of undefined identifier x (line 3) #2: Call to undefined function test (line 26) You do not need to implement statement-level error recovery. Thus, the remainder of the statement can be skipped after discovery of a type error within it. If the flag debug is set write all type coercions to the standard output. Your output should contain: Definitions of variables, including type and scope The type of any operator All type coercions Keep your output readable, e.g., in the form of tables like these: Variable definitions: name type scope line a int int main () 9 b int int main () 10 a int int wrongreturntype (int a) 1 b boolean int wrongreturntype (int a) 2 c int int wrongreturntype (int a) 3 Operators: operator left right result line operator return int int int 11 return b / int boolean int 4 2 / b - int int int int int int 4 b - 4 = int int int 4 a = 1 return int boolean int 5 return b 7

8 Type Coercions: from to line operator boolean int 4 2 / b boolean int 5 return b Note, that this example does not prescribe the exact form of your output. (12 points) 2. Enable support of predefined print functions. See section: Print. (3 points) 3. Create your own example programs - at least one type-correct program and one typeincorrect program - and add them to the test-folder. Extend the JUnit test to test those programs.(2 points) 4. Adapt the README file. (0.5 points) 5. Adapt your BUILD file if necessary. (no points, but mandatory) Variables and Scopes Note that there is only one scope type: the scope of each function. A global scope as well as nested scoping is not supported by the grammar. It is allowed to declare a variable with the same name in each local scope. But it is an error to declare a variable more than once in any given scope. It is also not allowed to define a variable of the same name as a function parameter of the current function. Function declarations Multiple declarations of the same function name, expecting a different number of parameters or varying parameter types should be supported. Whereas multiple declarations using the exact same combination of these factors should be reported as an error. Note that the return type does not need to be taken into consideration in this case. Implicit function declarations do not need to be supported. For this programming assignment, you can assume the following: If a function call to an undefined function occurs, this function will not be declared at a later point in the program and can be treated as an error. Type Checking Type checking involves the task of determining the validity of each combination of operator and operands occuring in the source program. Depending on the types of the operator and the supplied operands, either the expression is deemed valid, a typechecking error is issued, or a type coercion occurs, ensuring the validity of the expression. During a coercion, the type of an operand is automatically converted to the type expected by the operator. Typechecking reference by operator tokens: RELOP: Expected type: Coerced type: Rejected type: Result type: int boolean String boolean 8

9 SIGN, MULOP: Expected type: Coerced type: Rejected type: Result type: int boolean String int OR, AND, NOT: Expected type: Coerced type: Rejected type: Result type: boolean int String int ASSIGNOP (and return statements): Valid assignments: Coerced assignments: Rejected assignments: Result type: int = int; boolean = boolean; String = String; int = boolean; boolean = int; int = String; boolean = String; String = int; String = boolean; type of left operand (or return type of function) Assignments and return statements use the same set of coercion rules. Additionally, left associativity and operator precedence needs to be ensured as well: Print Every used binary operator is left-associative: a + b + c is equal to (a + b) + c. Thus, left hand operators within a chain of operators of the same precedence shall be computed first. Operators abide to the following precedence: NOT / unary SIGN > MULOP > SIGN > RELOP > AND > OR > ASSIGNOP Whereby NOT and unary SIGN will be resolved first and ASSIGNOP last. We want to test your compiler after Task 4 Code Generation as to whether it computes the correct results. To that end, we need a built-in mechanism for output: the print function. Since you are translating Calculator programs to Java byte code you have to use the I/O functions available in byte code. Thus, in Task 4 you will have to map the function calls to print to the corresponding byte code statements. At present, you only have to warrant that print is a predefined function and that a function call to print will not lead to an error. The exact signatures you will need to add are Hints int print (String) int print (int) int print (boolean) Create data structures to hold the type information for the identifiers. You will have (at least) int, boolean, String, and functions with argument- and return types. Implement the code to fill the data structures, and to perform type checking. The use of additional grammar files (e.g. TreeWalker.g) is recommended, but not mandatory. 9

10 Suggested Bonus Tasks Implementation of nested scopes (2 points) Implementation of forward declarations (2 points) Implementation of statement-level error recovery (2 points) Extend the type system to include more types. (points depend on your exact plans) If you intend to alter your grammar in favour of a bonus task, be sure to ascertain that the basic Calculator language is still matched. Don t forget to clearly document the implemented bonus tasks in the README file and add JUnit test cases, demonstrating the implemented features. 10

11 3 Intermediate Code Tasks 1. Build an Intermediate Code Generator which is able to build the intermediate code (Three- Address Code) for any program written in our grammar. Create the class IntermediateCode.java in the package at.tugraz.ist.cc with the method public int createintermediatecode(string file path, OutputStream stream, boolean debug). This method returns 0 if the intermediate code generation was successful. Otherwise, no intermediate code processing has to be done, and it returns the number of (lexical, syntactical or type) errors found. In addition, it writes the ASCII representation of the intermediate code to the given output stream. Use comments to clarify which part of the Calculator code corresponds to the intermediate code. If the debug-flag is not set, no comments should be printed to the stream. You can find an example input and output in the framework. (17 points) 2. Adapt the README file. (0.5 points) 3. Adapt your BUILD file if necessary. (no points, but mandatory) Three-Address-Code The three address code should support the following commands: Assignments of the form x := y op z, where x is a temporary variable and 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==, int!= which take two integers and return 0 or 1. Assignments of the form x := op y, where x is a temporary variable and op is one of intun- int! and y is a variable. op is one of intconst,stringconst, and y is an integer constant or a constant string, respectively. 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. Function Calls The statement param x, which says that x is a parameter to the next function call. Parameters should be listed from left to right. The statement call f rettype typelist, where f is the name of a function, rettype is the return type of the function and typelist is a list of all parameter types starting from left to right. The statement function f n rettype typelist, where f is a function, and n is the number of local variables including parameters and temporary variables. The rettype and typelist are the same as in the function call. The statement return x, which returns from the function, storing the value in x. The statement local x, where x is a local variable, a temporary variable, or a parameter. Start by listing the parameters from left to right, as seen in the example. 11

12 The statement getresult x, which stores the return value of the last function call in x. The statement comment x, which is ignored but should be used for debugging purposes. 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 need not to optimize your code concerning time or space. IF Statement Example (comments are for easier understanding only): To implement if statements, you will need to utilize jumps and customly added labels to jump to. One label will need to be added at the beginning of the else-part and one at the end of the whole statement. If the condition of the statement computes to true, skip the first jump, process the then-part and jump to the end-label. Otherwise jump to the beginning of the else-part and just continue there. 1 i f ( a == b ) 2 c = 1 0 ; 3 else 4 c = 2 0 ; comment --- cond --- comment Operator == [line: 5, col: 7, context: "( a ###==### b ) "] _t1 := a int== b comment inverting if condition _t2 := intnot _t1 comment conditional jump to else part ifint _t2 goto _L1 comment --- then comment ---END then --- comment jump to end of if goto _L2 comment label for else part label _L1 comment --- else comment --- END else --- comment label for end of if label _L2 comment #### -- IF END -- #### FOR Statement Example (comments are for easier understanding only): To implement for statements, you will, again, need to utilize jumps and customly added labels to jump to. One label will need to be added at the beginning of the condition evaluation part and one at the end of the whole statement. The initialization part should be put at the beginning, followed by the condition evaluation. If the condition of the statement computes to false, jump to the end of the statement. Otherwise, skip the jump, process the body- and update-parts and finally jump back to the condition evaluation. 1 for ( a = 0 ; a < b ; a = a + 1) 2 b = a 2 4 ; 12

13 comment -- begin init code FOR comment -- end init code FOR --- comment label for FOR loop label _L1 comment -- begin eval of condition FOR --- _t2 := a int< b comment -- end eval of condition FOR --- comment inverting condition _t3 := intnot _t2 comment jump to end of for if condition broken ifint _t3 goto _L2 comment -- begin body of FOR comment -- end body of FOR --- comment -- begin update of FOR comment -- end update of FOR --- comment jump to begin of loop goto _L1 comment label for end of for label _L2 comment #### END FOR #### Boolean values All boolean types are converted to integers in the Three-Address-Code. Truth values are represented by integers: 0 is false, anything else is true. A truth value generated by a comparison, &&, or may only be 0 or 1. You can assume, that this conversion will not lead to conflicting function definitions. Hints 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. For the comments, we display the Token context. You may get this by retaining the Tokenindex for each element and looking it (and its surrounding tokens) up in the CommonTokenStream from the Lexer. Bonus Task Implementation of short-circuit evaluation for Boolean expressions (2 points) Don t forget to clearly document the implemented bonus task in the README file. 13

14 4 Code Generation Tasks 1. Implement the translation of the intermediate code to Java bytecode. Implement the method public int createcode(string file path) of the class CodeGeneration.java in the package at.tugraz.ist.cc in the directory src. This method creates the output file <file>.j, where <file>.calc is the name of the input file. No code generation needs to be processed of either lexical, syntactical or type errors have been found. If this is the case, return number of reported errors. The method returns 0 if the code generation was successful. It must be possible to translate the generated output files to byte code by using the provided Jasmin binary. The files, generated by Jasmin based on your output, must be executable by the Java Virtual machine. In addition, calls to the print functions must work as intended. (17 points) 2. Adapt the README file. (0.5 points) 3. Adapt your BUILD file if necessary. (no points, but mandatory) Jasmin Jasmin is an assembler-language which produces Java bytecode. A small tutorial (description of how Jasmin operates and the statements you will need) and additional helpful links are available on the course web page. Convert a Jasmin *.j file into *.class Java bytecode: java -jar <path to jasmin.jar> <source.j> Execute the created source.class file: java <source> Example of a conversion Input: simple.calc 1 int main ( ) { 2 S t r i n g a ; 3 a = t e s t ; 4 return t e s t ( a ) ; 5 } 6 7 int t e s t ( S t r i n g a ) { 8 return print ( a ) ; 9 } Result: simple.j 1. s o u r c e simple. c a l c 2. class public s t a t i c simple 3. super java / lang / Object 4 5. method public s t a t i c main ( [ Ljava / lang / S t r i n g ; )V 6. l i m i t s t a c k l i m i t l o c a l s 4 8 l d c t e s t 9 a s t o r e 1 10 aload 1 11 a s t o r e 0 12 aload 0 13 i n v o k e s t a t i c simple. t e s t ( Ljava / lang / S t r i n g ; ) I 14 i s t o r e 2 14

15 15 i l o a d 2 16 return 17. end method method public s t a t i c t e s t ( Ljava / lang / S t r i n g ; ) I 20. l i m i t s t a c k l i m i t l o c a l s 2 22 aload 0 23 g e t s t a t i c java / lang /System/ out Ljava / i o / PrintStream ; 24 swap 25 i n v o k e v i r t u a l java / i o / PrintStream / p r i n t l n ( Ljava / lang / S t r i n g ; )V 26 bipush 0 27 i s t o r e 1 28 i l o a d 1 29 i r e t u r n 30. end method Main As we need to test your resulting bytecode assemblies, for this task each of our.calc testfiles will contain a main function with the signature int main(). You need to convert the signature of this function to the Java standard main method signature: public static void main(string[] args) within your assembly. Print Calls to the predefined print functions will need to be redirected as well. A call to int print(int) should invoke the method: void java.io.printstream.println(int) A call to int print(string) should invoke the method: void java.io.printstream.println(string) Calls to int print(boolean) will have been converted to int print(int) within the intermediate code. Both calls will need to be invoked using the invokevirtual Jasmin-statement after pushing a reference to java/lang/system/out and the desired parameter onto the stack. As the Java implementation of println(var) does not provide a return value you will need to provide a workaround in your assembly which supports each call to this function with a default return value of 0. Hints Comments within your assembly relating the assembly statements to the intermediate code can be useful for debugging. It will not be sufficient to generate Jasmin statements solely based on the current intermediate code statement. Information like the currently processed function, the result type of the current function and more will need to be memorized. Jasmin does not directly provide relation operators like > or ==. Instead you will have to utilize conditional jump statements like if icmpgt < label name > and if icmpeq < label name > in combination with custom labels to jump to and commands to put the desired outcome onto the operand stack. 15

16 Bonus Tasks Implementation of String read() which reads a String from the standard input. (1 points) Implementation of int read() which reads an integer from the standard input. (2 points) Implementation of int printf(string, int) which prints an integer using a format string to the standard output. (2 points) Support int-return of main function (1 points) Don t forget to clearly document the implemented bonus tasks in the README file. 16

KU Compilerbau - Programming Assignment

KU Compilerbau - Programming Assignment 716.077 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

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

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

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

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

Compiler construction 2009

Compiler construction 2009 Compiler construction 2009 Lecture 2 Code generation 1: Generating Jasmin code JVM and Java bytecode Jasmin Naive code generation The Java Virtual Machine Data types Primitive types, including integer

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

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

Tutorial 3: Code Generation

Tutorial 3: Code Generation S C I E N C E P A S S I O N T E C H N O L O G Y Tutorial 3: Code Generation Univ.-Prof. Dr. Franz Wotawa, DI Roxane Koitz, Stephan Frühwirt, Christopher Liebmann, Martin Zimmermann Institute for Software

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

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

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

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

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

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

CS664 Compiler Theory and Design LIU 1 of 16 ANTLR. Christopher League* 17 February Figure 1: ANTLR plugin installer

CS664 Compiler Theory and Design LIU 1 of 16 ANTLR. Christopher League* 17 February Figure 1: ANTLR plugin installer CS664 Compiler Theory and Design LIU 1 of 16 ANTLR Christopher League* 17 February 2016 ANTLR is a parser generator. There are other similar tools, such as yacc, flex, bison, etc. We ll be using ANTLR

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

CPS 506 Comparative Programming Languages. Syntax Specification

CPS 506 Comparative Programming Languages. Syntax Specification CPS 506 Comparative Programming Languages Syntax Specification Compiling Process Steps Program Lexical Analysis Convert characters into a stream of tokens Lexical Analysis Syntactic Analysis Send tokens

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

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

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

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

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

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

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

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION EDIABAS Electronic Diagnostic Basic System BEST/2 LANGUAGE DESCRIPTION VERSION 6b Copyright BMW AG, created by Softing AG BEST2SPC.DOC CONTENTS CONTENTS...2 1. INTRODUCTION TO BEST/2...5 2. TEXT CONVENTIONS...6

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

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

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

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

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

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

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours: CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall alphonce@buffalo.edu Office hours: Tuesday 10:00 AM 12:00 PM * Wednesday 4:00 PM 5:00 PM Friday 11:00 AM 12:00 PM OR

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

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

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode STUDENT OUTLINE Lesson 8: Structured Programming, Control Structures, if- Statements, Pseudocode INTRODUCTION: This lesson is the first of four covering the standard control structures of a high-level

More information

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! Any questions about the syllabus?! Course Material available at www.cs.unic.ac.cy/ioanna! Next time reading assignment [ALSU07]

More information

Compiling Techniques

Compiling Techniques Lecture 10: Introduction to 10 November 2015 Coursework: Block and Procedure Table of contents Introduction 1 Introduction Overview Java Virtual Machine Frames and Function Call 2 JVM Types and Mnemonics

More information

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

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

Lab 2. Lexing and Parsing with ANTLR4

Lab 2. Lexing and Parsing with ANTLR4 Lab 2 Lexing and Parsing with ANTLR4 Objective Understand the software architecture of ANTLR4. Be able to write simple grammars and correct grammar issues in ANTLR4. Todo in this lab: Install and play

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

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

CS 211 Programming Practicum Fall 2018

CS 211 Programming Practicum Fall 2018 Due: Wednesday, 11/7/18 at 11:59 pm Infix Expression Evaluator Programming Project 5 For this lab, write a C++ program that will evaluate an infix expression. The algorithm REQUIRED for this program will

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 Project 1: Lexical Analyzer (Scanner)

Programming Project 1: Lexical Analyzer (Scanner) CS 331 Compilers Fall 2017 Programming Project 1: Lexical Analyzer (Scanner) Prof. Szajda Due Thursday, September 21, 11:59:59 pm 1 Overview of the Programming Project Programming projects I IV will direct

More information

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

M/s. Managing distributed workloads. Language Reference Manual. Miranda Li (mjl2206) Benjamin Hanser (bwh2124) Mengdi Lin (ml3567) 1 M/s Managing distributed workloads Language Reference Manual Miranda Li (mjl2206) Benjamin Hanser (bwh2124) Mengdi Lin (ml3567) Table of Contents 1. Introduction 2. Lexical elements 2.1 Comments 2.2

More information

Concepts Introduced in Chapter 6

Concepts Introduced in Chapter 6 Concepts Introduced in Chapter 6 types of intermediate code representations translation of declarations arithmetic expressions boolean expressions flow-of-control statements backpatching EECS 665 Compiler

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

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

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

SEMANTIC ANALYSIS TYPES AND DECLARATIONS SEMANTIC ANALYSIS CS 403: Type Checking Stefan D. Bruda Winter 2015 Parsing only verifies that the program consists of tokens arranged in a syntactically valid combination now we move to check whether

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

Ch. 12: Operator Overloading

Ch. 12: Operator Overloading Ch. 12: Operator Overloading Operator overloading is just syntactic sugar, i.e. another way to make a function call: shift_left(42, 3); 42

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

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis Hall http://www.cse.buffalo.edu/faculty/alphonce/sp17/cse443/index.php https://piazza.com/class/iybn4ndqa1s3ei shift/reduce conflict with

More information

PART 3 - SYNTAX ANALYSIS. F. Wotawa TU Graz) Compiler Construction Summer term / 309

PART 3 - SYNTAX ANALYSIS. F. Wotawa TU Graz) Compiler Construction Summer term / 309 PART 3 - SYNTAX ANALYSIS F. Wotawa (IST @ TU Graz) Compiler Construction Summer term 2016 64 / 309 Goals Definition of the syntax of a programming language using context free grammars Methods for parsing

More information

Assignment 1 (Lexical Analyzer)

Assignment 1 (Lexical Analyzer) Assignment 1 (Lexical Analyzer) Compiler Construction CS4435 (Spring 2015) University of Lahore Maryam Bashir Assigned: Saturday, March 14, 2015. Due: Monday 23rd March 2015 11:59 PM Lexical analysis Lexical

More information

Syntax Intro and Overview. Syntax

Syntax Intro and Overview. Syntax Syntax Intro and Overview CS331 Syntax Syntax defines what is grammatically valid in a programming language Set of grammatical rules E.g. in English, a sentence cannot begin with a period Must be formal

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

More information

Parser Tools: lex and yacc-style Parsing

Parser Tools: lex and yacc-style Parsing Parser Tools: lex and yacc-style Parsing Version 5.0 Scott Owens June 6, 2010 This documentation assumes familiarity with lex and yacc style lexer and parser generators. 1 Contents 1 Lexers 3 1.1 Creating

More information

Writing a Lexer. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 6, Glenn G.

Writing a Lexer. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 6, Glenn G. Writing a Lexer CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 6, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks

More information

A programming language requires two major definitions A simple one pass compiler

A programming language requires two major definitions A simple one pass compiler A programming language requires two major definitions A simple one pass compiler [Syntax: what the language looks like A context-free grammar written in BNF (Backus-Naur Form) usually suffices. [Semantics:

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

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

Stating the obvious, people and computers do not speak the same language.

Stating the obvious, people and computers do not speak the same language. 3.4 SYSTEM SOFTWARE 3.4.3 TRANSLATION SOFTWARE INTRODUCTION Stating the obvious, people and computers do not speak the same language. People have to write programs in order to instruct a computer what

More information

B The SLLGEN Parsing System

B The SLLGEN Parsing System B The SLLGEN Parsing System Programs are just strings of characters. In order to process a program, we need to group these characters into meaningful units. This grouping is usually divided into two stages:

More information

CS 426 Fall Machine Problem 1. Machine Problem 1. CS 426 Compiler Construction Fall Semester 2017

CS 426 Fall Machine Problem 1. Machine Problem 1. CS 426 Compiler Construction Fall Semester 2017 CS 426 Fall 2017 1 Machine Problem 1 Machine Problem 1 CS 426 Compiler Construction Fall Semester 2017 Handed Out: September 6, 2017. Due: September 21, 2017, 5:00 p.m. The machine problems for this semester

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

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

Compiler, Assembler, and Linker

Compiler, Assembler, and Linker Compiler, Assembler, and Linker Minsoo Ryu Department of Computer Science and Engineering Hanyang University msryu@hanyang.ac.kr What is a Compilation? Preprocessor Compiler Assembler Linker Loader Contents

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Rupesh Nasre. CS3300 Compiler Design IIT Madras July 2018 Character stream Lexical Analyzer Machine-Independent Code Code Optimizer F r o n t e n d Token stream Syntax Analyzer

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

TACi: Three-Address Code Interpreter (version 1.0)

TACi: Three-Address Code Interpreter (version 1.0) TACi: Three-Address Code Interpreter (version 1.0) David Sinclair September 23, 2018 1 Introduction TACi is an interpreter for Three-Address Code, the common intermediate representation (IR) used in compilers.

More information

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100 GATE- 2016-17 Postal Correspondence 1 Compiler Design Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts,

More information

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring

More information

A simple syntax-directed

A simple syntax-directed Syntax-directed is a grammaroriented compiling technique Programming languages: Syntax: what its programs look like? Semantic: what its programs mean? 1 A simple syntax-directed Lexical Syntax Character

More information

Building Compilers with Phoenix

Building Compilers with Phoenix Building Compilers with Phoenix Syntax-Directed Translation Structure of a Compiler Character Stream Intermediate Representation Lexical Analyzer Machine-Independent Optimizer token stream Intermediate

More information

CS5363 Final Review. cs5363 1

CS5363 Final Review. cs5363 1 CS5363 Final Review cs5363 1 Programming language implementation Programming languages Tools for describing data and algorithms Instructing machines what to do Communicate between computers and programmers

More information

Implementing a VSOP Compiler. March 12, 2018

Implementing a VSOP Compiler. March 12, 2018 Implementing a VSOP Compiler Cyril SOLDANI, Pr. Pierre GEURTS March 12, 2018 Part II Syntax Analysis 1 Introduction In this assignment, you will implement a parser for the VSOP language, according to the

More information

CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis

CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis Handout written by Julie Zelenski with edits by Keith Schwarz. The Goal In the first programming project, you will get

More information

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

4. Inputting data or messages to a function is called passing data to the function. Test Bank for A First Book of ANSI C 4th Edition by Bronson Link full download test bank: http://testbankcollection.com/download/test-bank-for-a-first-book-of-ansi-c-4th-edition -by-bronson/ Link full

More information

FRAC: Language Reference Manual

FRAC: Language Reference Manual FRAC: Language Reference Manual Justin Chiang jc4127 Kunal Kamath kak2211 Calvin Li ctl2124 Anne Zhang az2350 1. Introduction FRAC is a domain-specific programming language that enables the programmer

More information

CSE 431S Final Review. Washington University Spring 2013

CSE 431S Final Review. Washington University Spring 2013 CSE 431S Final Review Washington University Spring 2013 What You Should Know The six stages of a compiler and what each stage does. The input to and output of each compilation stage (especially the back-end).

More information

Concepts Introduced in Chapter 6

Concepts Introduced in Chapter 6 Concepts Introduced in Chapter 6 types of intermediate code representations translation of declarations arithmetic expressions boolean expressions flow-of-control statements backpatching EECS 665 Compiler

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

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

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

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

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Rupesh Nasre. CS3300 Compiler Design IIT Madras Aug 2015 Character stream Lexical Analyzer Machine-Independent Code Optimizer F r o n t e n d Token stream Syntax Analyzer Syntax

More information

Semantic analysis and intermediate representations. Which methods / formalisms are used in the various phases during the analysis?

Semantic analysis and intermediate representations. Which methods / formalisms are used in the various phases during the analysis? Semantic analysis and intermediate representations Which methods / formalisms are used in the various phases during the analysis? The task of this phase is to check the "static semantics" and generate

More information

Compiler Theory. (Intermediate Code Generation Abstract S yntax + 3 Address Code)

Compiler Theory. (Intermediate Code Generation Abstract S yntax + 3 Address Code) Compiler Theory (Intermediate Code Generation Abstract S yntax + 3 Address Code) 006 Why intermediate code? Details of the source language are confined to the frontend (analysis phase) of a compiler, while

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1 CSE P 501 Compilers Java Implementation JVMs, JITs &c Hal Perkins Winter 2008 3/11/2008 2002-08 Hal Perkins & UW CSE V-1 Agenda Java virtual machine architecture.class files Class loading Execution engines

More information

Programming Assignment 2 LALR Parsing and Building ASTs

Programming Assignment 2 LALR Parsing and Building ASTs Lund University Computer Science Jesper Öqvist, Görel Hedin, Niklas Fors, Christoff Bürger Compilers EDAN65 2016-09-05 Programming Assignment 2 LALR Parsing and Building ASTs The goal of this assignment

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

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

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

CS 415 Midterm Exam Fall 2003

CS 415 Midterm Exam Fall 2003 CS 415 Midterm Exam Fall 2003 Name KEY Email Address Student ID # Pledge: This exam is closed note, closed book. Questions will be graded on quality of answer. Please supply the best answer you can to

More information

Context-Free Grammar. Concepts Introduced in Chapter 2. Parse Trees. Example Grammar and Derivation

Context-Free Grammar. Concepts Introduced in Chapter 2. Parse Trees. Example Grammar and Derivation Concepts Introduced in Chapter 2 A more detailed overview of the compilation process. Parsing Scanning Semantic Analysis Syntax-Directed Translation Intermediate Code Generation Context-Free Grammar A

More information

CSE 452: Programming Languages. Outline of Today s Lecture. Expressions. Expressions and Control Flow

CSE 452: Programming Languages. Outline of Today s Lecture. Expressions. Expressions and Control Flow CSE 452: Programming Languages Expressions and Control Flow Outline of Today s Lecture Expressions and Assignment Statements Arithmetic Expressions Overloaded Operators Type Conversions Relational and

More information

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres dgriol@inf.uc3m.es Compiler Architecture Source language Scanner (lexical analysis) tokens Parser (syntax

More information

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

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 2 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) AGENDA

More information