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

Size: px
Start display at page:

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

Transcription

1 Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 4 This project is due at 11:59pm on Friday, October Introduction In this project, you will do the following: 1. Implement functions that recognize expressions from text, where the expressions include numbers, variables, arithmetic operators, function calls, and array references. This recognition process, called parsing or syntax analysis, will include checking for syntax errors. 2. Implement a type, called SymExpr, that represents these expressions in such a way that one can perform operations on them. In this project, the only such operation will be conversion of an expression to a string for display. 2 Files Before beginning this project, you will need to download the source and header files from the Assignments page on the course web site: symtab.h contains preprocessor definitions that are used by several other files. You do not need to edit this file. parse expr.h contains the declaration of the functions that are is used to recognize complete expressions from text. You do not need to edit this file. parse expr.cpp contains the implementation of the parsing functions, which you will provide. symexpr.h contains the declaration of the SymExpr type, which is used to store expressions and support operations on them. You do not need to edit this file. symexpr.cpp contains the implementation of functions that operate on SymExpr objects, which you will provide. main.cpp, the main application file in which the code in the other source files is to be tested. You do not need to edit this file, except to comment out usages of functions that have not yet been implemented. 1

2 Makefile, for compiling your code on UNIX/Linux/Mac OS X. You do not need to edit this file. input4.txt and output4.txt, sample input on which you can run your program, and the output your program should generate, provided that you have not yet modified main.cpp. In addition, you will need the files scan expr.h and scan expr.cpp from Project 2. You will not need to make any changes to these files, unless you have bugs to fix from Project 2. We will assist you in fixing these bugs, if necessary. 3 Expression Language This section describes the language of expressions that your program will recognize. 3.1 Syntax In Project 2, you implemented a scanner, or lexical analyzer, that recognizes the tokens of our expression language. In this project, you must write a program that will group the language s words, or tokens, into sentences, which are individual expressions. To prescribe how expressions are built up from tokens, we use a context-free grammar. Such a grammar consists of grammar symbols, which fall into two categories: terminal symbols, which are simply tokens nonterminal symbols, which are defined recursively in terms of other grammar symbols. They correspond to either a complete sentence or components of a sentence, such as a phrase or clause. A grammar also includes rules, called productions, which describes how each nonterminal symbol is defined in terms of other symbols. One nonterminal symbol is designated the start symbol, which corresponds to a complete sentence. In our grammar, Stmt is the start symbol. The following table lists the productions of the grammar. 2

3 Grammar Symbol Production Description Stmt Expr = Expr Assignment statement (left side must be identifier or array reference) Stmt Expr Expression statement Expr Expr + T erm Addition of term Expr Expr - T erm Subtraction of term Expr T erm Single-term expression T erm T erm * F actor Multiplication by factor T erm T erm / F actor Division by factor T erm F actor Single-factor term F actor - F actor Negated factor F actor Base F actor Exponentiation F actor Base Factor consisting of base expression Base num Floating-point literal Base id Variable Base id ArrayRef s Array reference Base func ( Arglist ) Function call with arguments Base ( Expr ) Parenthesized expression Arglist Expr, Arglist Comma-separated arguments Arglist Expr Last argument in list ArrayRef s ArrayRef s [ Expr ] List of array subscripts ArrayRef s [ Expr ] Single array reference 3.2 Recursive-Descent Parsing To parse the text of an expression, we will use an approach called recursive-descent parsing, which, while more limited than other approaches in terms of the grammars it can implement, is easier to implement. The basic idea is to associate each nonterminal symbol with a function that recognizes that nonterminal, and implements each of the productions associated with the nonterminal. The appropriate production is selected by examining the tokens as they are read. For example, the function for Base can select the correct production based on whether the next token from the input is a num, id, func or (. If it is none of these, the input contains a syntax error. If it is an id, there are two productions that can apply, but the correct one can be determined by examining the next token. Typically, the function for a given nonterminal calls some of the functions for other nonterminals. For example, the function for Factor begins by calling the one for Base, and if the next token is, it will also call the function for Factor. The nonterminals Expr, Term and ArrayRefs are unusual in that their productions include left recursion, because each nonterminal has a production that begins with itself. Therefore, it can t simply call itself recursively, because the recursion has no 3

4 way of ending. The easiest way to work around this is to use a loop. For example, by viewing an Expr as a sequence of one or more terms that are added or subtracted, the associated function can call the function for Term, and then check if the next token is a + or -. If it is, then Term is called again, and if not, then the function for Expr should exit. 4 The Parser The parsing functions, assisted by nexttoken from Project 2, construct a SymExpr object (see the next section) that represents, in a hierarchical data structure, an expression given as input. 4.1 Functions GetFunctionCode( const std::string& s ); This function returns an integer code corresponding to the name of the function stored in the string s. The table below lists the function names and corresponding codes, which are defined in symtab.h. Function name "exp" "sin" "cos" "sqrt" "log" "diff" "clear" Symbol table code SYMTAB EXP SYMTAB SIN SYMTAB COS SYMTAB SQRT SYMTAB LOG SYMTAB DIFF SYMTAB CLEAR SymExpr Parse( std::istream& in ); This is the main function for the parser. It reads text from the input stream in and recognizes a single Stmt from the text. It initiates the parsing process by calling nexttoken to read the first token, and then calling Stmt (see below) to continue parsing. After Stmt finishes parsing the statement and returns, Parse must check whether the next token is TOKEN EOS, since each input string must contain only one statement and nothing else. If this is not the case, then an exception must be thrown with error message "end-of-string expected". int Stmt( std::istream& in, int token, std::string& tok str, SymExpr& S ); This function recognizes a single Stmt from text read from the input stream in. The second argument token is the code of the last token that was read. The third argument tok str is an input and output argument. Initially, it contains the text of the last token that was read before this function was called. When the function exits, it contains the text of the token 4

5 that has been most recently read, which is the first token that follows the Stmt. The numeric code for this token is to be returned. The last argument, S, is the SymExpr object that stores the expression corresponding to the Stmt that has been parsed. A Stmt consists of an Expr, followed by an optional = and another Expr. If there is an =, then the Expr on the left-hand side must be a single id, or an array reference, or an exception must be thrown, with the error message "invalid lhs". int Expr( std::istream& in, int token, std::string& tok str, SymExpr& E ); This function recognizes a single Expr from text read from the input stream in. The second argument token is the code of the last token that was read. The third argument tok str is an input and output argument. Initially, it contains the text of the last token that was read before this function was called. When the function exits, it contains the text of the token that has been most recently read, which is the first token that follows the Expr. The numeric code for this token is to be returned. The last argument, E, is the SymExpr object that stores the expression corresponding to the Expr that has been parsed. An Expr consists of a sequence of one or more T erms, connected by addition or subtraction operators. int Term( std::istream& in, int token, std::string& tok str, SymExpr& T ); This function recognizes a single T erm from text read from the input stream in. The second argument token is the code of the last token that was read. The third argument tok str is an input and output argument. Initially, it contains the text of the last token that was read before this function was called. When the function exits, it contains the text of the token that has been most recently read, which is the first token that follows the T erm. The numeric code for this token is to be returned. The last argument, T, is the SymExpr object that stores the expression corresponding to the T erm that has been parsed. A T erm consists of a sequence of one or more F actors, connected by multiplication or division operators. int Factor( std::istream& in, int token, std::string& tok str, SymExpr& F ); This function recognizes a single F actor from text read from the input stream in. The second argument token is the code of the last token that was read. The third argument tok str is an input and output argument. Initially, it contains the text of the last token that was read before this function was called. When the function exits, it contains the text of the token that has been most recently read, which is the first token that follows the F actor. The numeric code for this token is to be returned. The last argument, F, is the SymExpr object that stores the expression corresponding to the F actor that has been parsed. A F actor is either the negation of another F actor, or a Base raised to an exponent that is another F actor. int Base( std::istream& in, int token, std::string& tok str, SymExpr& B ); This function recognizes a single Base from text read from the input stream in. The second argument token is the code of the last token that was read. The third argument tok str is 5

6 an input and output argument. Initially, it contains the text of the last token that was read before this function was called. When the function exits, it contains the text of the token that has been most recently read, which is the first token that follows the Base. The numeric code for this token is to be returned. The last argument, B, is the SymExpr object that stores the expression corresponding to the Base that has been parsed. A Base is either a number, a variable, an array reference consisting of a variable and indices enclosed in square brackets, a function call consisting of a function name followed by a commaseparated argument list enclosed in parentheses, or a parenthesized Expr. If it is none of these, an exception must be thrown with the error message "base expression expected". If an Expr that is used as an array index is not followed by a ], than an exception must be thrown with the error message "] expected". If an argument in a function call is not followed by a comma or a ), then an exception must be thrown with the error message ", or ) expected". If the function name is not followed by a (, then an exception must be thrown with the error message "( expected". Finally, if the Base is a parenthesized Expr, then if the Expr is not followed by a ), then an exception must be thrown with the error message ") expected". 4.2 Exceptions The table below summarizes all of the errors that must be reported by functions in the parser. Message Situation "end-of-string expected" Stmt not followed by null terminator "invalid lhs" Expr on left side of = is not id or array reference "] expected" Expr used as array index not followed by ] ", or ) expected" Expr in Arglist not followed by, or ) "( expected" No ( after func ") expected" No ) after parenthesized Expr "base expression expected" Invalid token at beginning of Base 5 The SymExpr type This type is used to represent expressions in such a way that they can have operations performed on them, using recursion. A SymExpr object can represent a number, a variable, an array reference, an application of a function to another SymExpr object, or a sum, product, difference, quotient, exponentiation, or negation of other SymExpr objects. Because of the hierarchical structure of these expressions, we can easily implement operations on expressions by implementing them for each basic type of expression, and letting recursion handle the rest. 6

7 5.1 Structure Members The following members store the properties of an SymExpr object. int m type; This is the only member that is always needed. It indicates the type of the expression, using the values given in the description of CreateSymExpr (see below). int m symbol; If the SymExpr object represents a function call, this variable stores the numeric code of the function, using the values listed in symtab.h. double m num; If the SymExpr object represents a number, its value is stored in this variable. bool m ispar; This variable is set to true if the expression, when converted to a string by tostring(), is to be enclosed in parentheses. std::string m var; If the SymExpr object represents a variable, its name is stored in this member variable. std::vector<symexpr> m operands; If the SymExpr object represents an expression that has operands, they are stored in this vector. The order of the elements in the vector corresponds to the order in which the operands appear in the expression, from left to right. 5.2 Functions CreateSymExpr( int type = ETYPE NONE, int symbol = -1 ); This function initializes a SymExpr object with the given type. The allowed types, defined in sym expr.h, are as follows: 7

8 Type ETYPE NONE ETYPE NUM ETYPE VAR ETYPE ADD ETYPE SUB ETYPE MUL ETYPE DIV ETYPE EXP ETYPE NEG ETYPE FUNC ETYPE ASN ETYPE ARRAY Description Empty expression Number Variable Sum of expressions Difference of expressions Product of expressions Quotient of expressions Exponentiation of expressions Negation of expression Function applied to expression Assignment of expression to another Array reference The second argument, symbol, is only needed if the type is ETYPE FUNC. It indicates which function is to be applied, using its code as defined in symtab.h. CreateSymExpr( double num ); This function initializes a SymExpr object that is equal to the number num by setting its type accordingly and storing num inside the object. CreateSymExpr( const std::string& var ); This function initializes a SymExpr object that is equal to a variable named var by setting its type accordingly and storing var inside the object. SymExpr Add( const SymExpr& e1, const SymExpr& e2 ); This operator returns a new SymExpr object that represents the sum of e1 (the left operand) and e2 (the right operand). SymExpr Subtract( const SymExpr& e1, const SymExpr& e2 ); This operator returns a new SymExpr object that represents the difference of e1 (the left operand) and e2 (the right operand). SymExpr Multiply( const SymExpr& e1, const SymExpr& e2 ); This operator returns a new SymExpr object that represents the product of e1 (the left operand) and e2 (the right operand). SymExpr Divide( const SymExpr& e1, const SymExpr& e2 ); This operator returns a new SymExpr object that represents the quotient of e1 (the left operand) and e2 (the right operand). 8

9 SymExpr Power( const SymExpr& e1, const SymExpr& e2 ); This operator returns a new SymExpr object that represents the exponentiation of e1 (the base) and e2 (the exponent). SymExpr Negate( const SymExpr& e ); This operator returns a new SymExpr object that represents the negation of its operand, e. SymExpr ApplyFunc( int func, std::vector<symexpr>& arglist ); This function returns a new SymExpr object that represents a Base expression that is a function call the arguments stored in Arglist. The numeric code of the function is given by func. The arguments must be stored in the m operands vector of the new SymExpr object. SymExpr Assign( const SymExpr& e1, const SymExpr& e2 ); This function returns a new SymExpr object that represents an assignment Stmt, in which the left-hand side is represented by e1, and the right-hand side is represented by e2. Both expressions must be stored in the m operands vector of the new SymExpr object. SymExpr ArrayRef( const SymExpr& e, std::vector<symexpr>& arglist ); This function returns a new SymExpr object that represents a Base expression that is an array reference, where e is the array and arglist contains the indices. The variable represented by e and the indices stored in arglist must be stored in the m operands vector of the new SymExpr object. std::string tostring( const SymExpr& e ) const; This function returns a std::string describing the expression stored in e. If e is a variable, tostring( e ) simply returns the variable name. If e is a number, tostring( e ) simply returns a string containing the number s value. Most other expressions are handled by simply calling tostring() recursively on the operands of e and combining the resulting strings with the appropriate operators such as + or *, with the following exceptions: If e is a function call, and the function is not diff, then the string to be returned consists of the name of the function, followed by its arguments, separated by commas, and enclosed in parentheses. If e is a function call and the function is diff, then the string to be returned consists of the first argument, the expression to be differentiated, enclosed in square brackets, and preceded by a string describing the differentiation operator that is applied. If the differentiation is with respect to only a single variable, the differentiation operator is described by the string d/d followed by the name of that variable. If differentiating with respect to n variables where n > 1, the differentiation operator is described by the string 9

10 d n/ followed by each variable in the argument list, in reverse order, preceded by a d. For example, the string returned for the expression diff(sin(x),x) is d/dx[sin(x)], and the string returned for the expression diff(x 2+y 2,x,y) is d 2/dydx[x 2+y 2]. If e is an array reference, the string to be returned consists of the variable name, which is the first operand of e, followed by each of the other operands, which are the indices, with each operand enclosed in square brackets. If e is marked as being parenthesized, then the resulting string must be enclosed in parentheses before it is returned. void Parenthesize( const SymExpr& e ); This function, which is already implemented, is used to indicate that the expression in the current object, when converted to a string by tostring(), is to be enclosed in parentheses. This function must be called when creating the SymExpr object from an Expr that is enclosed in parentheses in the original text. It must also be called for various reasons when combining expressions; Section 6 discusses these scenarios. bool isempty( const SymExpr& e ); This function, which is already implemented, returns true if e does not contain an expression; that is, its type is ETYPE NONE. bool IsZero( const SymExpr& e ); This function, which is already implemented, returns true if e represents the number zero. bool IsOne( const SymExpr& e ); This function, which is already implemented, returns true if e represents the number one. bool IsNum( const SymExpr& e ); This function, which is already implemented, returns true if e represents a number. bool IsVar( const SymExpr& e ); This function, which is already implemented, returns true if e represents a Variable. bool IsArray( const SymExpr& e ); This function, which is already implemented, returns true if e represents an array reference. std::ostream& operator<<( std::ostream& out, const SymExpr& e ); This operator uses tostring() to write an expression to the output stream out. It does not need to be implemented. 10

11 6 Parenthesizing The following simple rules will help ensure that expressions are properly parenthesized, without introducing unnnecessary parentheses. If an expression is required by the grammar to be enclosed in parentheses, then the SymExpr object representing that expression should be parenthesized by calling the Parenthesize() member function. When building a SymExpr object from other SymExpr objects that serve as operands, parenthesize the operands using the Parenthesize() member function if their m type corresponds to an operator of lower precedence than the operator that corresponds to the value of m type in the newly built SymExpr object. For example, in Multiply, a SymExpr object of type ETYPE MUL is being built from two operands. If either of those operands is of type ETYPE ADD or ETYPE SUB, then they should be parenthesized. If the denominator of a newly formed quotient is of type ETYPE MUL or ETYPE DIV, then it should be parenthesized using the Parenthesize() member function. Similarly, if the right operand of a subtraction is of type ETYPE ADD or ETYPE SUB, then it should be parenthesized. This is due to the left associativity, and non-commutativity, of subtraction and division. If the base of a newly formed exponentiation is of type ETYPE EXP, then it should be parenthesized. This is due to the right associativity, and non-commutativity, of exponentiation. The types of SymExpr objects, listed in order of precedence, from highest to lowest, are 1. ETYPE FUNC, ETYPE NUM, ETYPE VAR, ETYPE ARRAY 2. ETYPE ExP 3. ETYPE NEG 4. ETYPE MUL, ETYPE DIV 5. ETYPE ADD, ETYPE SUB 6. ETYPE ASN Note that the higher an operator s precedence, the lower its level in the hierarchy of expressions described by the grammar. Based on these rules, numbers, variables, function calls, and array references never need to be parenthesized, because they have the highest precedence. 11

12 7 The Driver The main function is implemented for you, and serves as a driver. This means that it s only intended to aid in testing your parsing code; it does not actually do anything with the expressions that are parsed, except to display them. It also catches exceptions, so that parsing can continue. It is worth noting how it processes input. It uses getline to read a line from std::cin into a std::string, and then associates a std::istringstream with this string. This stream is then passed to Parse, so your code is only processing a single line of text. When running your program, you will test your code by entering expressions, one per line. The syntax requires that each line consists of only a single statement and nothing else. Your Parse function should create an empty SymExpr object before calling Stmt, so that if there is no input (i.e., the std::istringstream object is associated with an empty string, or a string containing only white space), Parse will return a SymExpr object of ETYPE NONE, and then main will exit. Therefore, you can end your program simply by hitting enter twice in a row after your last statement. 8 Suggested Approach The code from the Lecture 15 example eval expr contains code that is very similar to that which you will need to write for parsing, so that should be used as a starting point. Then, it is recommended that you build your project in stages: 1. When writing the parsing functions, begin with simpler, lower-level expressions like numbers and variables, and then proceeding to higher-level expressions like products and sums. You don t have to implement every production before you can test anything. For example, you can begin by only implementing the productions Stmt Expr, Expr T erm, T erm F actor, and then implementing Base. This corresponds to simply having Stmt call Expr, Expr call Term, Term call Factor, and Factor call Base. You can fill in the other productions for Stmt, Expr, T erm, and F actor later. 2. Implement the tostring() function as soon as possible, at least for the simplest expressions, so that SymExpr objects can be output at any time, to aid with debugging. 9 Testing Your Code In the file main.cpp, you can write any code you like to test your member functions. However, make sure you test them thoroughly, because when we grade your project, we will replace your main.cpp with one of our own and expect your code to work! Be sure to test both valid and invalid input, because we will too. 12

13 10 Submission To submit your project, you must do the following: 1. Transfer your source files to your account on elaine.stanford.edu. This can be done using SecureFX on Windows, or Fetch on Mac OS X. 2. Place all of your source files and the Makefile in the same directory. 3. Use the make command to build the executable project2, so that you can ensure that it runs on elaine. 4. Log in to elaine using an SSH client and execute the following command from the directory containing your code and Makefile: /usr/class/energy211/submit 4 This command runs a script that will build your executable, even if you didn t earlier, to make sure that your code compiles. If it does, then it will submit your source files for grading. 11 Grading Your grade will be determined using the following criteria: Correctness (70%) Your code must be able to parse valid expressions and display them as prescribed. Errors must be reported in the situations described in Section 4.2. When an error is reported, the remainder of the current expression must be skipped, and the next expression is read and parsed. Efficiency (10%) Your code must implement the operations with reasonable efficiency. Points may be deducted for unnecessary operations, particularly comparisons or data movements. Style (10%) Sound coding practices should be observed, or points may be deducted. Avoid the use of global variables, and avoid declaring variables outside of the scope in which they are used. Write modular code, using functions to perform individual tasks. Documentation (10%) Your code must be documented. In each function that you implement, add comments to explain what you are doing so that your code can be readily understood by a reader. Points may be deducted for code that is difficult to decipher. 13

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

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 2 Jim Lambers ENERGY 211 / CME 211 Autumn Quarter 2007-08 Programming Project 2 This project is due at 11:59pm on Friday, October 17. 1 Introduction In this project, you will implement functions in order

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 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

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

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

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

Syntax. In Text: Chapter 3

Syntax. In Text: Chapter 3 Syntax In Text: Chapter 3 1 Outline Syntax: Recognizer vs. generator BNF EBNF Chapter 3: Syntax and Semantics 2 Basic Definitions Syntax the form or structure of the expressions, statements, and program

More information

CA4003 Compiler Construction Assignment Language Definition

CA4003 Compiler Construction Assignment Language Definition CA4003 Compiler Construction Assignment Language Definition David Sinclair 2017-2018 1 Overview The language is not case sensitive. A nonterminal, X, is represented by enclosing it in angle brackets, e.g.

More information

LECTURE 3. Compiler Phases

LECTURE 3. Compiler Phases LECTURE 3 Compiler Phases COMPILER PHASES Compilation of a program proceeds through a fixed series of phases. Each phase uses an (intermediate) form of the program produced by an earlier phase. Subsequent

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

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

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

Defining Program Syntax. Chapter Two Modern Programming Languages, 2nd ed. 1

Defining Program Syntax. Chapter Two Modern Programming Languages, 2nd ed. 1 Defining Program Syntax Chapter Two Modern Programming Languages, 2nd ed. 1 Syntax And Semantics Programming language syntax: how programs look, their form and structure Syntax is defined using a kind

More information

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

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 STUDENT ID: INSTRUCTIONS Please write your student ID on this page. Do not write it or your name

More information

Compiler principles, PS1

Compiler principles, PS1 Compiler principles, PS1 1 Compiler structure A compiler is a computer program that transforms source code written in a programming language into another computer language. Structure of a compiler: Scanner

More information

Programming Project II

Programming Project II Programming Project II CS 322 Compiler Construction Winter Quarter 2006 Due: Saturday, January 28, at 11:59pm START EARLY! Description In this phase, you will produce a parser for our version of Pascal.

More information

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

Angela Z: A Language that facilitate the Matrix wise operations Language Reference Manual Angela Z: A Language that facilitate the Matrix wise operations Language Reference Manual Contents Fei Liu, Mengdi Zhang, Taikun Liu, Jiayi Yan 1. Language definition 3 1.1. Usage 3 1.2. What special feature

More information

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017 Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls

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

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

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

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

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

More information

Programming Language Syntax and Analysis

Programming Language Syntax and Analysis Programming Language Syntax and Analysis 2017 Kwangman Ko (http://compiler.sangji.ac.kr, kkman@sangji.ac.kr) Dept. of Computer Engineering, Sangji University Introduction Syntax the form or structure of

More information

Syntax/semantics. Program <> program execution Compiler/interpreter Syntax Grammars Syntax diagrams Automata/State Machines Scanning/Parsing

Syntax/semantics. Program <> program execution Compiler/interpreter Syntax Grammars Syntax diagrams Automata/State Machines Scanning/Parsing Syntax/semantics Program program execution Compiler/interpreter Syntax Grammars Syntax diagrams Automata/State Machines Scanning/Parsing Meta-models 8/27/10 1 Program program execution Syntax Semantics

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

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

Chapter 3. Describing Syntax and Semantics ISBN

Chapter 3. Describing Syntax and Semantics ISBN Chapter 3 Describing Syntax and Semantics ISBN 0-321-49362-1 Chapter 3 Topics Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax Copyright 2009 Addison-Wesley. All

More information

Specifying Syntax. An English Grammar. Components of a Grammar. Language Specification. Types of Grammars. 1. Terminal symbols or terminals, Σ

Specifying Syntax. An English Grammar. Components of a Grammar. Language Specification. Types of Grammars. 1. Terminal symbols or terminals, Σ Specifying Syntax Language Specification Components of a Grammar 1. Terminal symbols or terminals, Σ Syntax Form of phrases Physical arrangement of symbols 2. Nonterminal symbols or syntactic categories,

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

COMPILER CONSTRUCTION LAB 2 THE SYMBOL TABLE. Tutorial 2 LABS. PHASES OF A COMPILER Source Program. Lab 2 Symbol table

COMPILER CONSTRUCTION LAB 2 THE SYMBOL TABLE. Tutorial 2 LABS. PHASES OF A COMPILER Source Program. Lab 2 Symbol table COMPILER CONSTRUCTION Lab 2 Symbol table LABS Lab 3 LR parsing and abstract syntax tree construction using ''bison' Lab 4 Semantic analysis (type checking) PHASES OF A COMPILER Source Program Lab 2 Symtab

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

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d. Chapter 4: Control Structures I (Selection) In this chapter, you will: Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate logical (Boolean)

More information

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

Sketchpad Graphics Language Reference Manual. Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321 Sketchpad Graphics Language Reference Manual Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321 October 20, 2013 1. Introduction This manual provides reference information for using the SKL (Sketchpad

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

Lecture 09: Data Abstraction ++ Parsing is the process of translating a sequence of characters (a string) into an abstract syntax tree.

Lecture 09: Data Abstraction ++ Parsing is the process of translating a sequence of characters (a string) into an abstract syntax tree. Lecture 09: Data Abstraction ++ Parsing Parsing is the process of translating a sequence of characters (a string) into an abstract syntax tree. program text Parser AST Processor Compilers (and some interpreters)

More information

Fundamentals: Expressions and Assignment

Fundamentals: Expressions and Assignment Fundamentals: Expressions and Assignment A typical Python program is made up of one or more statements, which are executed, or run, by a Python console (also known as a shell) for their side effects e.g,

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

SMPL - A Simplified Modeling Language for Mathematical Programming

SMPL - A Simplified Modeling Language for Mathematical Programming SMPL - A Simplified Modeling Language for Mathematical Programming Mihály Csaba Markót November 3, 2008 1 Purpose and Scope This working paper describes SMPL, an initiative of a Simplified Modeling Language

More information

Context-free grammars (CFG s)

Context-free grammars (CFG s) Syntax Analysis/Parsing Purpose: determine if tokens have the right form for the language (right syntactic structure) stream of tokens abstract syntax tree (AST) AST: captures hierarchical structure of

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

Objectives. In this chapter, you will:

Objectives. In this chapter, you will: Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

More information

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

Chapter 3: Describing Syntax and Semantics. Introduction Formal methods of describing syntax (BNF) Chapter 3: Describing Syntax and Semantics Introduction Formal methods of describing syntax (BNF) We can analyze syntax of a computer program on two levels: 1. Lexical level 2. Syntactic level Lexical

More information

COP Programming Assignment #7

COP Programming Assignment #7 1 of 5 03/13/07 12:36 COP 3330 - Programming Assignment #7 Due: Mon, Nov 21 (revised) Objective: Upon completion of this program, you should gain experience with operator overloading, as well as further

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

ASTs, Objective CAML, and Ocamlyacc

ASTs, Objective CAML, and Ocamlyacc ASTs, Objective CAML, and Ocamlyacc Stephen A. Edwards Columbia University Fall 2012 Parsing and Syntax Trees Parsing decides if the program is part of the language. Not that useful: we want more than

More information

PLT 4115 LRM: JaTesté

PLT 4115 LRM: JaTesté PLT 4115 LRM: JaTesté Andrew Grant amg2215@columbia.edu Jemma Losh jal2285@columbia.edu Jake Weissman jdw2159@columbia.edu March 7, 2016 Jared Weiss jbw2140@columbia.edu 1 Contents 1 Introduction 4 2 Lexical

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

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

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

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

Left to right design 1

Left to right design 1 Left to right design 1 Left to right design The left to right design method suggests that the structure of the program should closely follow the structure of the input. The method is effective when the

More information

afewadminnotes CSC324 Formal Language Theory Dealing with Ambiguity: Precedence Example Office Hours: (in BA 4237) Monday 3 4pm Wednesdays 1 2pm

afewadminnotes CSC324 Formal Language Theory Dealing with Ambiguity: Precedence Example Office Hours: (in BA 4237) Monday 3 4pm Wednesdays 1 2pm afewadminnotes CSC324 Formal Language Theory Afsaneh Fazly 1 Office Hours: (in BA 4237) Monday 3 4pm Wednesdays 1 2pm January 16, 2013 There will be a lecture Friday January 18, 2013 @2pm. 1 Thanks to

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

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

Language Reference Manual

Language Reference Manual TAPE: A File Handling Language Language Reference Manual Tianhua Fang (tf2377) Alexander Sato (as4628) Priscilla Wang (pyw2102) Edwin Chan (cc3919) Programming Languages and Translators COMSW 4115 Fall

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

PieNum Language Reference Manual

PieNum Language Reference Manual PieNum Language Reference Manual October 2017 Hadiah Venner (hkv2001) Hana Fusman (hbf2113) Ogochukwu Nwodoh( ocn2000) Index Introduction 1. Lexical Convention 1.1. Comments 1.2. Identifiers 1.3. Keywords

More information

Programming Lecture 3

Programming Lecture 3 Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements

More information

TML Language Reference Manual

TML Language Reference Manual TML Language Reference Manual Jiabin Hu (jh3240) Akash Sharma (as4122) Shuai Sun (ss4088) Yan Zou (yz2437) Columbia University October 31, 2011 1 Contents 1 Introduction 4 2 Lexical Conventions 4 2.1 Character

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

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

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output? Arithmetic Operators Section 2.15 & 3.2 p 60-63, 81-89 1 Today Arithmetic Operators & Expressions o Computation o Precedence o Associativity o Algebra vs C++ o Exponents 2 Assigning floats to ints int

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

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

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

Variables and Operators 2/20/01 Lecture #

Variables and Operators 2/20/01 Lecture # Variables and Operators 2/20/01 Lecture #6 16.070 Variables, their characteristics and their uses Operators, their characteristics and their uses Fesq, 2/20/01 1 16.070 Variables Variables enable you to

More information

TDDD55 - Compilers and Interpreters Lesson 3

TDDD55 - Compilers and Interpreters Lesson 3 TDDD55 - Compilers and Interpreters Lesson 3 November 22 2011 Kristian Stavåker (kristian.stavaker@liu.se) Department of Computer and Information Science Linköping University LESSON SCHEDULE November 1,

More information

L-System Fractal Generator: Language Reference Manual

L-System Fractal Generator: Language Reference Manual L-System Fractal Generator: Language Reference Manual Michael Eng, Jervis Muindi, Timothy Sun Contents 1 Program Definition 3 2 Lexical Conventions 3 2.1 Comments...............................................

More information

Assignment 5. Introduction

Assignment 5. Introduction Assignment 5 Introduction The objectives of this assignment are to exercise a few advanced object oriented programming and basic data structures concepts. The first mini-goal is to understand that objects

More information

Syntax Analysis/Parsing. Context-free grammars (CFG s) Context-free grammars vs. Regular Expressions. BNF description of PL/0 syntax

Syntax Analysis/Parsing. Context-free grammars (CFG s) Context-free grammars vs. Regular Expressions. BNF description of PL/0 syntax Susan Eggers 1 CSE 401 Syntax Analysis/Parsing Context-free grammars (CFG s) Purpose: determine if tokens have the right form for the language (right syntactic structure) stream of tokens abstract syntax

More information

syntax tree - * * * - * * * * * 2 1 * * 2 * (2 * 1) - (1 + 0)

syntax tree - * * * - * * * * * 2 1 * * 2 * (2 * 1) - (1 + 0) 0//7 xpression rees rom last time: we can draw a syntax tree for the Java expression ( 0). 0 ASS, GRAMMARS, PARSING, R RAVRSALS Lecture 3 CS0 all 07 Preorder, Postorder, and Inorder Preorder, Postorder,

More information

COMPILERS BASIC COMPILER FUNCTIONS

COMPILERS BASIC COMPILER FUNCTIONS COMPILERS BASIC COMPILER FUNCTIONS A compiler accepts a program written in a high level language as input and produces its machine language equivalent as output. For the purpose of compiler construction,

More information

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

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 97 INSTRUCTIONS

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 97 INSTRUCTIONS RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 97 STUDENT ID: INSTRUCTIONS Please write your student ID on this page. Do not write it or your name

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

CSE 413 Final Exam Spring 2011 Sample Solution. Strings of alternating 0 s and 1 s that begin and end with the same character, either 0 or 1.

CSE 413 Final Exam Spring 2011 Sample Solution. Strings of alternating 0 s and 1 s that begin and end with the same character, either 0 or 1. Question 1. (10 points) Regular expressions I. Describe the set of strings generated by each of the following regular expressions. For full credit, give a description of the sets like all sets of strings

More information

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

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information

Week 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.

Week 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5. Week 2: Console I/O and Operators Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.1) CS 1428 Fall 2014 Jill Seaman 1 2.14 Arithmetic Operators An operator is a symbol that tells the computer to perform specific

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

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

GAWK Language Reference Manual

GAWK Language Reference Manual GAWK Language Reference Manual Albert Cui, Karen Nan, Mei-Vern Then, & Michael Raimi So good, you re gonna GAWK. 1.0 Introduction This manual describes the GAWK language and is meant to be used as a reliable

More information

CMPS Programming Languages. Dr. Chengwei Lei CEECS California State University, Bakersfield

CMPS Programming Languages. Dr. Chengwei Lei CEECS California State University, Bakersfield CMPS 3500 Programming Languages Dr. Chengwei Lei CEECS California State University, Bakersfield Chapter 3 Describing Syntax and Semantics Chapter 3 Topics Introduction The General Problem of Describing

More information

Postfix Notation is a notation in which the operator follows its operands in the expression (e.g ).

Postfix Notation is a notation in which the operator follows its operands in the expression (e.g ). Assignment 5 Introduction For this assignment, you will write classes to evaluate arithmetic expressions represented as text. For example, the string "1 2 ( * 4)" would evaluate to 15. This process will

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

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators Objectives Chapter 4: Control Structures I (Selection) In this chapter, you will: Learn about control structures Examine relational and logical operators Explore how to form and evaluate logical (Boolean)

More information

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

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

Related Course Objec6ves

Related Course Objec6ves Syntax 9/18/17 1 Related Course Objec6ves Develop grammars and parsers of programming languages 9/18/17 2 Syntax And Seman6cs Programming language syntax: how programs look, their form and structure Syntax

More information

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an  . Michigan State University CSE 231, Fall 2013 CSE 231, Rich Enbody Office Hours After class By appointment send an email 2 1 Project 1 Python arithmetic Do with pencil, paper and calculator first Idle Handin Help room 3 What is a Computer Program?

More information

Chapter 7 Arithmetic

Chapter 7 Arithmetic Chapter 7 Arithmetic 7-1 Arithmetic in C++ Arithmetic expressions are made up of constants, variables, operators and parentheses. The arithmetic operators in C++ are as follows + (addition) - (subtraction)

More information

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING Friday 20 th December 2013 14:30 to 16:30 INSTRUCTIONS TO CANDIDATES 1.

More information

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

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards Language Reference Manual Introduction The purpose of

More information

CSE 413 Final Exam. June 7, 2011

CSE 413 Final Exam. June 7, 2011 CSE 413 Final Exam June 7, 2011 Name The exam is closed book, except that you may have a single page of hand-written notes for reference plus the page of notes you had for the midterm (although you are

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

3.5 Practical Issues PRACTICAL ISSUES Error Recovery

3.5 Practical Issues PRACTICAL ISSUES Error Recovery 3.5 Practical Issues 141 3.5 PRACTICAL ISSUES Even with automatic parser generators, the compiler writer must manage several issues to produce a robust, efficient parser for a real programming language.

More information

COP4020 Programming Assignment 2 - Fall 2016

COP4020 Programming Assignment 2 - Fall 2016 COP4020 Programming Assignment 2 - Fall 2016 To goal of this project is to implement in C or C++ (your choice) an interpreter that evaluates arithmetic expressions with variables in local scopes. The local

More information

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

Mirage. Language Reference Manual. Image drawn using Mirage 1.1. Columbia University COMS W4115 Programming Languages and Translators Fall 2006 Mirage Language Reference Manual Image drawn using Mirage 1.1 Columbia University COMS W4115 Programming Languages and Translators Fall 2006 Prof. Stephen Edwards Team Members: Abhilash I ai2160@columbia.edu

More information

Syntax and Grammars 1 / 21

Syntax and Grammars 1 / 21 Syntax and Grammars 1 / 21 Outline What is a language? Abstract syntax and grammars Abstract syntax vs. concrete syntax Encoding grammars as Haskell data types What is a language? 2 / 21 What is a language?

More information

XQ: An XML Query Language Language Reference Manual

XQ: An XML Query Language Language Reference Manual XQ: An XML Query Language Language Reference Manual Kin Ng kn2006@columbia.edu 1. Introduction XQ is a query language for XML documents. This language enables programmers to express queries in a few simple

More information

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

VENTURE. Section 1. Lexical Elements. 1.1 Identifiers. 1.2 Keywords. 1.3 Literals VENTURE COMS 4115 - Language Reference Manual Zach Adler (zpa2001), Ben Carlin (bc2620), Naina Sahrawat (ns3001), James Sands (js4597) Section 1. Lexical Elements 1.1 Identifiers An identifier in VENTURE

More information

LECTURE 7. Lex and Intro to Parsing

LECTURE 7. Lex and Intro to Parsing LECTURE 7 Lex and Intro to Parsing LEX Last lecture, we learned a little bit about how we can take our regular expressions (which specify our valid tokens) and create real programs that can recognize them.

More information

Unit 7. Functions. Need of User Defined Functions

Unit 7. Functions. Need of User Defined Functions Unit 7 Functions Functions are the building blocks where every program activity occurs. They are self contained program segments that carry out some specific, well defined task. Every C program must have

More information