Assignment 1: Lexer and tokenout utility
|
|
- Robert McKinney
- 5 years ago
- Views:
Transcription
1 Assignment 1: Lexer and tokenout utility Worth 10% of the Project grade Due: Tuesday, September 10th at 11:59 pm (just before Midnight) Overview Over the semester, you will be building pieces of a compiler for a simple C like language called C-like, (also known as clike, especially from the command line). C-like will not implement all of C, but much of C to gain an understanding of what is needed to put together a full implementation. This assignment contains most of the first part of the five piece project which makes up the semester long compiler project. To make this assignment at least nominally useful, we will be using the lexer (which you will be implementing in this assignment) as a tool to massage the input to remove certain kinds of input. As a reminder: each assignment in this class depends on the previous assignment. In other words, you will be reusing much of this code in your next assignment, so get it right NOW or you will be making more work for your future self. This Assigment This is the beginnings of a lexical processor for clike. Knowing how to write just a lexer can be useful for tranformations. In this portion, we implement the lexer for C-like and use it to do something moderately useful. We will implementing something called tokenout using the C-like lexer and the flex Unix tool. You are required to use flex and C for this assignment. If you don't use C and flex, you will get a 0.: Recall: When using Makefiles, all dependencies are checked using timestamps on files. EXAMPLE: If a timestamp on a file ex1.c is newer than file ex1.o, and file ex1.o depends on file ex1.c, ex1.o must be rebuilt to pick up the potential changes in 'ex1.c'). The problem, especially with C, is that this can cause major rebuilds even if all that changed was a comment. For example, if only a comment or whitespace in a.h file changes, there is no reason to rebuild everything that depends on that.h file. (Why do we have to recompile anything that include a.h file if it changes? Discuss on piazza.com) We can use a lexical stream of tokens to check whether or not the file has changed or JUST the comments/whitespace has changed. By outputting just the tokens of a file and no whitespace or comments, we can compare (say) an original file from a source code repository to the changed file and see if we need to rebuild. (This example may sound contrived, but is a technique that has been used in workplaces to try to mitigate rebuilding of an extremely large codebase where code was installed and running.) What does tokenout do? It will output a stream of tokens, discarding whitespace and comments. We will (more or less) use the definitions of the tokens and reserved words that come from "C: A Reference Manual" (5th Edition) by Harbison and Steele, Chapter 2: "Lexical Elements". When in doubt, do what C99 would do. When in doubt on what's a token, defer to the Harbison Steele book. If that is unclear, defer to the testcases (see below). If they are unclear, ask us on piazza. In general, though, the testcases will be the last authority on what is correct. Definitions These definitions all come from Harbison and Steele. We strongly recommend you pick up a copy of the book for the class and for a reference in real life. We will use the following definition of whitespace (derived from Section 2.1: "Character Set"):
2 space ' ' horizontal tab (or tab) '\t' vertical tab '\v', formfeed '\f' newline '\n' and return '\r' (optional elements) For comments, we will use both C-style and C++-style. See Section 2.2: "Comments": /* start comment - C-style */ end comment // starts a comment, ends at end of line Recall that comments in C DO NOT nest (i.e., you can't have a comment inside of another comment). Do not worry about implementing #if comments. The definition of tokens is given on page 29, Section 2.3: "Tokens". This gives a good definition of what a token is in C. The operators and separators are given on page 21 in Section 2.4: "Operators and Separators". Don't worry about the "alternate token spellings" (i.e., completely ignore them). Identifiers are described in Section 2.5, starting on page 21. The reserved words (keywords) of the language are given on page 23 of the C: A Reference Manual (5th Edition), Section 2.6 "Keywords". Use ONLY the keywords in the table (Table 2-4) and DO NOT worry about asm, fortran or others listed just below the table. Disregard Section 2.6.1: "Predefined Identifiers". Constants are described in Section 2.7. There are 4 types of contants: integer, float, character, and string constants. When in doubt, refer to the Harbison-Steele book for questions of ambiguity and prefer C99. DO NOT worry about trigraphs, token respellings, checking constant limits (at least for now), wide strings, additional C++ reserved words, or implementing the preprocessor (#, #define, etc). The basic rules for tokenout: If whitespace is encountered, it is ignored (normally C replaces it with a space) If an identifier is encountered, it is replaced on output by id:name-of-identifier If a keyword is encountered, it is replaced on output by kw:name-of-keyword If a string constant is encountered, it is replaced on output by str:"the-string-constant" If an int constant is encountered, it is replaced on output by int:int-const If a floating point constant is encountered, it is replaced on output by float:float-const If a char constant is is encountered, it is replaced on output by char:'char'
3 Any other token comes out as-as A space is inserted between every token EXAMPLES: Example 1: Consider the following hello.c file: // Example 1 # include "stdio.h" int main() { printf("hello there!\n"); exit(1); } The tokenout utility would output: # id:include str:"stdio.h" kw:int id:main ( ) { id:printf ( str:"hello there!\n" ) ; id:exit ( int:1 ) ; } Note that the comment was completely discarded, and a single space separates each token. Surprisingly, printf is not a keyword in the language: it is a function call into the standard library, so it just a plain identifier. The strings and ints also annotate what is there. Example 2: Consider the following simple input file: 1 +++a The tokenout utility would output: int: id:a Why? C follows the "maximal munch rule" and grabs the biggest token it can at the start of the +++, which is 2 plusses. The following 3 preprocessing directives should all have the same output: # include "stdio.h" #include "stdio.h" #include"stdio.h" should all output: # id:include str:"stdio.h" In other words, # is a token, include is a token, and the constant "stdio.h" is a token. (In a real C implementation, strictly speaking, #include wouldn't be seen by the tokenizer; the macro preprocessor would have inserted the contents of the file "stdio.h" instead. For the purposes of this compiler, we will simply see include as an identifier for this first assignment.)
4 Errors There's a few cases where you will output an error to standard error. If a /* comment is unfinished (i.e., no matching */ before the end of the file), you should output an error to stderr with the line number. For an input of /*/ The output would be empty, and the stderr would report something like: 2, Unterminated Comment Where the 2 is the line number that the end of file would be on. If you input a token that is unrecognized by the lexer, then you should report on stderr. See the test cases for more details on stderr. Similar, if a string is unterminated. Handling the unterminated string and char constant is usually left to the default rules (when a token doesn't match). Building We will building and running your code on lectura.cs.arizona.edu. You will turn in at least 2 files: a Makefile and a Flex file named 'tokenout.l'. The Makefile builds an executable named tokenout on lectura. Like most UNIX tools, tokenout reads from standard input and writes to standard output.: % make tokenout % tokenout < input.txt > output.txt # reads standard input and writes to standard output (We strongly suggest you support 'make clean', 'make test' in your Makefile as well to make your life easier). The file tokenout.l will be built using the UNIX command tool flex and create lex.yy.c which will be compiled and folded into the final executable. You will probably want your main routine in your tokenout.l. Grading We will giving you a bunch of sample inputs and expected outputs where we will compare (using the UNIX diff utility) the expected output with your output. If you match exactly, you will pass the test case, if you don't, you will fail. There are approximately 50 test cases on the class web page under: We reserve the right to add more test cases. Note that they check both the standard output and standard error. In the Testing dir is a README which describes how to run the testcases. You will also be graded on being valgrind clean: In other words, your program should have any memory leaks OR memory errors that valgrind finds. If time permits, we may may have trophies for 'cleanest code' and 'fastest code'. Hints: Do one class of tokens at a time (keywords, then integers, etc) at a time and test them fully before moving on to the next token type. That way you can keep your testing for all the other characters you have processed.
5 Start simple (the input doesn't HAVE to be a C program, just a string of tokens) and build from there. Real C programs make good final tests.
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 information2 Input and Output The input of your program is any file with text. The output of your program will be a description of the strings that the program r
CSCI 2400 Models of Computation Project 1: Lex Return Day: Tuesday, October 23. Teams: You must form teams of 2 or 3 persons. 1 Overview In this assignment you will use the lexical analyzer lex to write
More informationCS164: 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 informationChapter 2, Part I Introduction to C Programming
Chapter 2, Part I Introduction to C Programming C How to Program, 8/e, GE 2016 Pearson Education, Ltd. All rights reserved. 1 2016 Pearson Education, Ltd. All rights reserved. 2 2016 Pearson Education,
More informationNotes By: Shailesh Bdr. Pandey, TA, Computer Engineering Department, Nepal Engineering College
Preparing to Program You should take certain steps when you're solving a problem. First, you must define the problem. If you don't know what the problem is, you can't find a solution! Once you know what
More informationC Language, Token, Keywords, Constant, variable
C Language, Token, Keywords, Constant, variable A language written by Brian Kernighan and Dennis Ritchie. This was to be the language that UNIX was written in to become the first "portable" language. C
More informationCS 220: Introduction to Parallel Computing. Beginning C. Lecture 2
CS 220: Introduction to Parallel Computing Beginning C Lecture 2 Today s Schedule More C Background Differences: C vs Java/Python The C Compiler HW0 8/25/17 CS 220: Parallel Computing 2 Today s Schedule
More informationCompiler Construction D7011E
Compiler Construction D7011E Lecture 2: Lexical analysis Viktor Leijon Slides largely by Johan Nordlander with material generously provided by Mark P. Jones. 1 Basics of Lexical Analysis: 2 Some definitions:
More informationCSC 467 Lecture 3: Regular Expressions
CSC 467 Lecture 3: Regular Expressions Recall How we build a lexer by hand o Use fgetc/mmap to read input o Use a big switch to match patterns Homework exercise static TokenKind identifier( TokenKind token
More informationC: How to Program. Week /Mar/05
1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers
More informationAssignment 6: The Power of Caches
Assignment 6: The Power of Caches Due by: April 20, 2018 before 10:00 pm Collaboration: Individuals or Registered Pairs (see Piazza). It is mandatory for every student to register on Piazza. Grading: Packaging
More informationChapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic
More informationFlex and lexical analysis. October 25, 2016
Flex and lexical analysis October 25, 2016 Flex and lexical analysis From the area of compilers, we get a host of tools to convert text files into programs. The first part of that process is often called
More informationProgramming in C++ 4. The lexical basis of C++
Programming in C++ 4. The lexical basis of C++! Characters and tokens! Permissible characters! Comments & white spaces! Identifiers! Keywords! Constants! Operators! Summary 1 Characters and tokens A C++
More informationare all acceptable. With the right compiler flags, Java/C++ style comments are also acceptable.
CMPS 12M Introduction to Data Structures Lab Lab Assignment 3 The purpose of this lab assignment is to introduce the C programming language, including standard input-output functions, command line arguments,
More informationCSCI 4963/6963 Large-Scale Programming and Testing Homework 1 (document version 1.0) Regular Expressions and Pattern Matching in C
CSCI 4963/6963 Large-Scale Programming and Testing Homework 1 (document version 1.0) Regular Expressions and Pattern Matching in C Overview This homework is due by 11:59:59 PM on Tuesday, September 19,
More informationBLM2031 Structured Programming. Zeyneb KURT
BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help
More informationC Introduction. Comparison w/ Java, Memory Model, and Pointers
CS 261 Fall 2018 Mike Lam, Professor C Introduction Comparison w/ Java, Memory Model, and Pointers Please go to socrative.com on your phone or laptop, choose student login and join room LAMJMU The C Language
More informationCompiler Construction
Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-17/cc/ Recap: First-Longest-Match Analysis The Extended Matching
More informationCompiler Construction
Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-16/cc/ Recap: First-Longest-Match Analysis Outline of Lecture
More informationCS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor
CS 261 Fall 2017 Mike Lam, Professor C Introduction Variables, Memory Model, Pointers, and Debugging The C Language Systems language originally developed for Unix Imperative, compiled language with static
More informationCpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input
CpSc Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input Overview For this lab, you will use: one or more of the conditional statements explained below scanf() or fscanf() to read
More information2 Compiling a C program
2 Compiling a C program This chapter describes how to compile C programs using gcc. Programs can be compiled from a single source file or from multiple source files, and may use system libraries and header
More informationSome Computer Preliminaries
Some Computer Preliminaries Before we get started, let's look at some basic components that play a major role in a computer's ability to run programs: 1) Central Processing Unit: The "brains" of the computer
More informationMakefile Tutorial. Eric S. Missimer. December 6, 2013
Makefile Tutorial Eric S. Missimer December 6, 2013 1 Basic Elements of a Makefile 1.1 Explicit Rules A the major part of a Makefile are the explicit rules (a.k.a. recipes) that make certain files. Below
More information1.1 Introduction to C Language. Department of CSE
1.1 Introduction to C Language 1 Department of CSE Objectives To understand the structure of a C-Language Program To write a minimal C program To introduce the include preprocessor command To be able to
More informationCS240: Programming in C
CS240: Programming in C Lecture 2: Hello World! Cristina Nita-Rotaru Lecture 2/ Fall 2013 1 Introducing C High-level programming language Developed between 1969 and 1973 by Dennis Ritchie at the Bell Labs
More informationUsing Lex or Flex. Prof. James L. Frankel Harvard University
Using Lex or Flex Prof. James L. Frankel Harvard University Version of 1:07 PM 26-Sep-2016 Copyright 2016, 2015 James L. Frankel. All rights reserved. Lex Regular Expressions (1 of 4) Special characters
More informationChapter 11 Introduction to Programming in C
Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University C: A High-Level Language! Gives
More informationCS 322 Operating Systems Programming Assignment 2 Using malloc and free Due: February 15, 11:30 PM
CS 322 Operating Systems Programming Assignment 2 Using malloc and free Due: February 15, 11:30 PM Goals To get more experience programming in C To learn how to use malloc and free To lean how to use valgrind
More information27-Sep CSCI 2132 Software Development Lecture 10: Formatted Input and Output. Faculty of Computer Science, Dalhousie University. Lecture 10 p.
Lecture 10 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 10: Formatted Input and Output 27-Sep-2017 Location: Goldberg CS 127 Time: 14:35 15:25 Instructor:
More informationCSCi 4061: Intro to Operating Systems Spring 2017 Instructor: Jon Weissman Assignment 1: Simple Make Due: Feb. 15, 11:55 pm
CSCi 4061: Intro to Operating Systems Spring 2017 Instructor: Jon Weissman Assignment 1: Simple Make Due: Feb. 15, 11:55 pm 1 Purpose Make is a useful utility which builds executable programs or libraries
More informationModule 8 - Lexical Analyzer Generator. 8.1 Need for a Tool. 8.2 Lexical Analyzer Generator Tool
Module 8 - Lexical Analyzer Generator This module discusses the core issues in designing a lexical analyzer generator from basis or using a tool. The basics of LEX tool are also discussed. 8.1 Need for
More informationScanners. Xiaokang Qiu Purdue University. August 24, ECE 468 Adapted from Kulkarni 2012
Scanners Xiaokang Qiu Purdue University ECE 468 Adapted from Kulkarni 2012 August 24, 2016 Scanners Sometimes called lexers Recall: scanners break input stream up into a set of tokens Identifiers, reserved
More informationLanguages and Compilers
Principles of Software Engineering and Operational Systems Languages and Compilers SDAGE: Level I 2012-13 4. Lexical Analysis (Scanning) Dr Valery Adzhiev vadzhiev@bournemouth.ac.uk Office: TA-121 For
More informationJim 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 informationCMPE-013/L. Introduction to C Programming
CMPE-013/L Introduction to C Programming Bryant Wenborg Mairs Spring 2014 What we will cover in 13/L Embedded C on a microcontroller Specific issues with microcontrollers Peripheral usage Reading documentation
More informationCOP 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 informationRule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.
Chapter 9: Rules Chapter 1:Style and Program Organization Rule 1-1: Organize programs for readability, just as you would expect an author to organize a book. Rule 1-2: Divide each module up into a public
More informationIntroduction to Lexical Analysis
Introduction to Lexical Analysis Outline Informal sketch of lexical analysis Identifies tokens in input string Issues in lexical analysis Lookahead Ambiguities Specifying lexical analyzers (lexers) Regular
More informationAN OVERVIEW OF C. CSE 130: Introduction to Programming in C Stony Brook University
AN OVERVIEW OF C CSE 130: Introduction to Programming in C Stony Brook University WHY C? C is a programming lingua franca Millions of lines of C code exist Many other languages use C-like syntax C is portable
More informationCSCI-243 Exam 2 Review February 22, 2015 Presented by the RIT Computer Science Community
CSCI-43 Exam Review February, 01 Presented by the RIT Computer Science Community http://csc.cs.rit.edu C Preprocessor 1. Consider the following program: 1 # include 3 # ifdef WINDOWS 4 # include
More informationLexical Analysis. Lecture 3. January 10, 2018
Lexical Analysis Lecture 3 January 10, 2018 Announcements PA1c due tonight at 11:50pm! Don t forget about PA1, the Cool implementation! Use Monday s lecture, the video guides and Cool examples if you re
More informationWeek 5 Lecture 3. Compiler Errors
Lecture 3 Compiler Errors Agile Development Backlog of stories defines projects Backlog contains all of the requirements currently known Stories define features of the project Three elements: feature user,
More informationIntroduction to Lexical Analysis
Introduction to Lexical Analysis Outline Informal sketch of lexical analysis Identifies tokens in input string Issues in lexical analysis Lookahead Ambiguities Specifying lexers Regular expressions Examples
More informationIntroduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan
Introduction to C Programming Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Printing texts Adding 2 integers Comparing 2 integers C.E.,
More informationCS 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 informationCS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code
CS102: Standard I/O Our next topic is standard input and standard output in C. The adjective "standard" when applied to "input" or "output" could be interpreted to mean "default". Typically, standard output
More informationProgramming. Data Structure
Programming & Data Structure For Computer Science & Information Technology By www.thegateacademy.com Syllabus Syllabus for Programming and Data Structures Programming in C, Arrays, Stacks, Queues, Linked
More informationc) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.
2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C
More informationCS240: Programming in C. Lecture 2: Overview
CS240: Programming in C Lecture 2: Overview 1 Programming Model How does C view the world? Stack Memory code Globals 2 Programming Model Execution mediated via a stack function calls and returns local
More informationProject #1: Tracing, System Calls, and Processes
Project #1: Tracing, System Calls, and Processes Objectives In this project, you will learn about system calls, process control and several different techniques for tracing and instrumenting process behaviors.
More informationCS 553 Compiler Construction Fall 2009 Project #1 Adding doubles to MiniJava Due September 8, 2009
CS 553 Compiler Construction Fall 2009 Project #1 Adding doubles to MiniJava Due September 8, 2009 In this assignment you will extend the MiniJava language and compiler to enable the double data type.
More informationAn introduction to Flex
An introduction to Flex 1 Introduction 1.1 What is Flex? Flex takes a set of descriptions of possible tokens and produces a scanner. 1.2 A short history Lex was developed at Bell Laboratories in the 1970s.
More informationProgramming I Laboratory - lesson 01
Programming I Laboratory - lesson 0 Introduction in C++ programming environment. The C++ program structure. Computer programs are composed of instructions and data. Instructions tell the computer to do
More informationLexical Analysis. Finite Automata
#1 Lexical Analysis Finite Automata Cool Demo? (Part 1 of 2) #2 Cunning Plan Informal Sketch of Lexical Analysis LA identifies tokens from input string lexer : (char list) (token list) Issues in Lexical
More informationProgramming 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 informationSyntactic Analysis. CS345H: Programming Languages. Lecture 3: Lexical Analysis. Outline. Lexical Analysis. What is a Token? Tokens
Syntactic Analysis CS45H: Programming Languages Lecture : Lexical Analysis Thomas Dillig Main Question: How to give structure to strings Analogy: Understanding an English sentence First, we separate a
More informationChapter 11 Introduction to Programming in C
Chapter 11 Introduction to Programming in C C: A High-Level Language Gives symbolic names to values don t need to know which register or memory location Provides abstraction of underlying hardware operations
More informationChapter 11 Introduction to Programming in C
C: A High-Level Language Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University! Gives
More informationFeatures of C. Portable Procedural / Modular Structured Language Statically typed Middle level language
1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC
More informationC Input/Output. Before we discuss I/O in C, let's review how C++ I/O works. int i; double x;
C Input/Output Before we discuss I/O in C, let's review how C++ I/O works. int i; double x; cin >> i; cin >> x; cout
More informationEL2310 Scientific Programming
(yaseminb@kth.se) Overview Overview Roots of C Getting started with C Closer look at Hello World Programming Environment Discussion Basic Datatypes and printf Schedule Introduction to C - main part of
More informationSchool of Computer Science Introduction to Algorithms and Programming Winter Midterm Examination # 1 Wednesday, February 11, 2015
Page 1 of 8 School of Computer Science 60-141-01 Introduction to Algorithms and Programming Winter 2015 Midterm Examination # 1 Wednesday, February 11, 2015 Marking Exemplar Duration of examination: 75
More informationTopic 6: A Quick Intro To C
Topic 6: A Quick Intro To C Assumption: All of you know Java. Much of C syntax is the same. Also: Many of you have used C or C++. Goal for this topic: you can write & run a simple C program basic functions
More informationTDDD55- Compilers and Interpreters Lesson 2
TDDD55- Compilers and Interpreters Lesson 2 November 11 2011 Kristian Stavåker (kristian.stavaker@liu.se) Department of Computer and Information Science Linköping University PURPOSE OF LESSONS The purpose
More information!"#$% &'($) *+!$ 0!'" 0+'&"$.&0-2$ 10.+3&2),&/3+, %&&/3+, C,-"!.&/+"*0.&('1 :2 %*10% *%7)/ 30'&. 0% /4%./
0!'" 0+'&"$ &0-2$ 10 +3&2),&/3+, #include int main() int i, sum, value; sum = 0; printf("enter ten numbers:\n"); for( i = 0; i < 10; i++ ) scanf("%d", &value); sum = sum + value; printf("their
More informationMP 3 A Lexer for MiniJava
MP 3 A Lexer for MiniJava CS 421 Spring 2010 Revision 1.0 Assigned Tuesday, February 2, 2010 Due Monday, February 8, at 10:00pm Extension 48 hours (20% penalty) Total points 50 (+5 extra credit) 1 Change
More informationChapter 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 informationAn Introduction to LEX and YACC. SYSC Programming Languages
An Introduction to LEX and YACC SYSC-3101 1 Programming Languages CONTENTS CONTENTS Contents 1 General Structure 3 2 Lex - A lexical analyzer 4 3 Yacc - Yet another compiler compiler 10 4 Main Program
More informationINTERMEDIATE SOFTWARE DESIGN SPRING 2011 ACCESS SPECIFIER: SOURCE FILE
HEADER FILE A header (.h,.hpp,...) file contains Class definitions ( class X {... }; ) Inline function definitions ( inline int get_x() {... } ) Function declarations ( void help(); ) Object declarations
More informationObjectives. 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 informationCS16 Midterm Exam 2 E02, 10W, Phill Conrad, UC Santa Barbara Tuesday, 03/02/2010
CS16 Midterm Exam 2 E02, 10W, Phill Conrad, UC Santa Barbara Tuesday, 03/02/2010 Name: Umail Address: @ umail.ucsb.edu Circle Lab section: 3PM 4PM 5PM Link to Printer Friendly PDF Version Please write
More informationCS133 C Programming. Instructor: Jialiang Lu Office: Information Center 703
CS133 C Programming Instructor: Jialiang Lu Email: jialiang.lu@sjtu.edu.cn Office: Information Center 703 1 Course Information: Course Page: http://wirelesslab.sjtu.edu.cn/~jlu/teaching/cp2014/ Assignments
More informationEat (we provide) link. Eater. Goal: Eater(Self) == Self()
15-251: Great Theoretical Ideas Guru: Yinmeng Zhang Assignment 12 Due: December 6, 2005 1 Reading Comprehension (0 points) Read the accompanying handout containing Ken Thompson s Turing Award Lecture,
More informationChapter 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 informationCSE 333 Midterm Exam July 24, Name UW ID#
Name UW ID# There are 6 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,
More informationProgramming 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 informationRecitation: C Review. TA s 20 Feb 2017
15-213 Recitation: C Review TA s 20 Feb 2017 Agenda Logistics Attack Lab Conclusion C Assessment C Programming Style C Exercise Cache Lab Overview Appendix: Valgrind Clang / LLVM Cache Structure Logistics
More informationFull file at C How to Program, 6/e Multiple Choice Test Bank
2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)
More informationHave examined process Creating program Have developed program Written in C Source code
Preprocessing, Compiling, Assembling, and Linking Introduction In this lesson will examine Architecture of C program Introduce C preprocessor and preprocessor directives How to use preprocessor s directives
More informationEdited by Himanshu Mittal. Lexical Analysis Phase
Edited by Himanshu Mittal Lexical Analysis Phase Lexical Analyzer The main task of Lexical analysis is to read input characters of source program and group them into lexemes and produce as output a sequence
More informationProgramming 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 informationChapter 11 Introduction to Programming in C
Chapter 11 Introduction to Programming in C C: A High-Level Language Gives symbolic names to values don t need to know which register or memory location Provides abstraction of underlying hardware operations
More informationBinghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program
Syntax What the Compiler needs to understand your program 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line Possibly replacing it with other
More informationCasting in C++ (intermediate level)
1 of 5 10/5/2009 1:14 PM Casting in C++ (intermediate level) Casting isn't usually necessary in student-level C++ code, but understanding why it's needed and the restrictions involved can help widen one's
More informationCOMP 321: Introduction to Computer Systems
Assigned: 1/18/18, Due: 2/1/18, 11:55 PM Important: This project must be done individually. Be sure to carefully read the course policies for assignments (including the honor code policy) on the assignments
More informationUniversity 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 informationCS 470 Operating Systems Spring 2013 Shell Project
CS 470 Operating Systems Spring 2013 Shell Project 40 points Out: January 11, 2013 Due: January 25, 2012 (Friday) The purpose of this project is provide experience with process manipulation and signal
More information9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C
Overview The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments
More informationProgramming for Engineers Introduction to C
Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines
More informationLecture 2: C Programming Basic
ECE342 Introduction to Embedded Systems Lecture 2: C Programming Basic Ying Tang Electrical and Computer Engineering Rowan University 1 Facts about C C was developed in 1972 in order to write the UNIX
More informationDeep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems
Deep C Multifile projects Getting it running Data types Typecasting Memory management Pointers Fabián E. Bustamante, Fall 2004 Multifile Projects Give your project a structure Modularized design Reuse
More informationLecture Outline. COMP-421 Compiler Design. What is Lex? Lex Specification. ! Lexical Analyzer Lex. ! Lex Examples. Presented by Dr Ioanna Dionysiou
Lecture Outline COMP-421 Compiler Design! Lexical Analyzer Lex! Lex Examples Presented by Dr Ioanna Dionysiou Figures and part of the lecture notes taken from A compact guide to lex&yacc, epaperpress.com
More informationOverview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program
Overview - General Data Types - Categories of Words - The Three S s - Define Before Use - End of Statement - My First Program a description of data, defining a set of valid values and operations List of
More informationIntro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?
Intro to Programming & C++ Unit 1 Sections 1.1-4 and 2.1-10, 2.12-13, 2.15-17 CS 1428 Spring 2019 Jill Seaman 1.1 Why Program? Computer programmable machine designed to follow instructions Program a set
More informationLexical Analysis. Finite Automata
#1 Lexical Analysis Finite Automata Cool Demo? (Part 1 of 2) #2 Cunning Plan Informal Sketch of Lexical Analysis LA identifies tokens from input string lexer : (char list) (token list) Issues in Lexical
More informationComparing Multiple Source Code Trees, version 3.1
Comparing Multiple Source Code Trees, version 3.1 Warren Toomey School of IT Bond University April 2010 This is my 3 rd version of a tool to compare source code trees to find similarities. The latest algorithm
More informationProgramming Assignment I Due Thursday, October 9, 2008 at 11:59pm
Programming Assignment I Due Thursday, October 9, 2008 at 11:59pm 1 Overview Programming assignments I IV will direct you to design and build a compiler for Cool. Each assignment will cover one component
More informationThe C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)
The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) 1 Overview Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments
More information