Compilation: a bit about the target architecture

Size: px
Start display at page:

Download "Compilation: a bit about the target architecture"

Transcription

1 Compilation: a bit about the target architecture MIF08 Laure Gonnord Laure.Gonnord@univ-lyon1.fr

2 Plan 1 The LEIA architecture in a nutshell 2 One example Laure Gonnord (Lyon1/FST) Compilation: a bit about the target architecture 2 / 12

3 The LEIA architecture in a nutshell Outline 1 The LEIA architecture in a nutshell 2 One example Laure Gonnord (Lyon1/FST) Compilation: a bit about the target architecture 3 / 12

4 The LEIA architecture in a nutshell Our target machine : LEIA Memory: bits words. Instructions are also encoded in 16-bits words. Registers PC, IR + 16 general purpose registers R0,...,R15. We will use only the 8 first registers We have a assembler and a simulator (see Lab 1) Laure Gonnord (Lyon1/FST) Compilation: a bit about the target architecture 4 / 12

5 The LEIA architecture in a nutshell LEIA ISA See companion document. Laure Gonnord (Lyon1/FST) Compilation: a bit about the target architecture 5 / 12

6 The LEIA architecture in a nutshell Example : ADD instruction add dr sr1 sr2, does dr <- sr1 + sr2. All operands are registers. Example : add r1 r2 r3 executes r1 <- r2 + r3. add dr sr1 imm4, does dr <- sr + imm4. The last operand is an immediate value (on 4bits) encoded in the instruction. Example : add r1 r2 5 executes r1 <- r Laure Gonnord (Lyon1/FST) Compilation: a bit about the target architecture 6 / 12

7 The LEIA architecture in a nutshell LEIA ADD : encoding A bit specifies the addressing mode: class action ADD reg r d r i + r j d i j ADD imm4 r d r i + ext(j) d i j Example: assemble add r1 r2 5 Laure Gonnord (Lyon1/FST) Compilation: a bit about the target architecture 7 / 12

8 The LEIA architecture in a nutshell LEIA Memory access instructions store wmem sr [dr], does mem[dr] <- sr. load rmem dr [sr], does dr <- mem[sr]. indirect addressing: the address must be stored in a register mem[rj] the value at the address stored in r j. class action wmem mem[r j ] r i i j rmem r d mem[r j ] d j See also the copy instruction. Laure Gonnord (Lyon1/FST) Compilation: a bit about the target architecture 8 / 12

9 The LEIA architecture in a nutshell LEIA: branching Unconditional branching: jump c, does PC <- a + c where a is the current instruction address. class action jump jump c Test and branch: snif r1 op r2, skip the next instruction if the test is true class action snif /0 condition i j Laure Gonnord (Lyon1/FST) Compilation: a bit about the target architecture 9 / 12

10 One example Outline 1 The LEIA architecture in a nutshell 2 One example Laure Gonnord (Lyon1/FST) Compilation: a bit about the target architecture 10 / 12

11 One example Ex : Assembly code - demo 1 ; ;; simple LEIA assembly demo leth r1 0 ; first op letl r1 5.set r3 b ; second, from memory 6 rmem r2 [r3] add r4 r1 r2 ; add and store in memory.set r3 resu wmem r4 [r3] 11 jump 0 ; stop b: resu:.word 2 16.reserve 1 ; reservation of a memory cell python3 asm.py demo.s && LEIA -s demo.obj Laure Gonnord (Lyon1/FST) Compilation: a bit about the target architecture 11 / 12

12 One example LEIA Exercises see TD sheet. Laure Gonnord (Lyon1/FST) Compilation: a bit about the target architecture 12 / 12

13 Introduction MIF08 Laure Gonnord

14 What s compilation? source language compiler targuet language errors Laure Gonnord (Lyon1/FST) Introduction 2 / 7

15 Compilation toward the machine language We immediatly think of the translation of a high-level language (C,Java,OCaml) into the machine language of a processor (Pentium, PowerPC... ) % gcc -o sum sum.c i n t main ( i n t argc, char argv ) { i n t i, s = 0; for ( i = 0; i <= 100; i ++) s += i i ; p r i n t f ( " = %d \ n ", s ) ; } But this is only one aspect, we will see more! Laure Gonnord (Lyon1/FST) Introduction 3 / 7

16 Course Objective Be familiar with the mecanisms inside a (simple) compiler. Beyond the scope: compilers optimisations of the 21 th century. Laure Gonnord (Lyon1/FST) Introduction 4 / 7

17 Course Content Syntax Analysis : lexing, parsing, AST Evaluators Code generation (Code Optimisation) Support language: Python 2.7 Frontend infrastructure : ANTLR 4. Laure Gonnord (Lyon1/FST) Introduction 5 / 7

18 Course Organization 4 TD groups: S. Brandel, L. Gonnord, Matthieu Moy, X.Urbain (@univ-lyon1.fr) 6 (or 7) TP groups: S. Brandel, T. Excoffier, J. Fernandez, G. Salagnac (Insa), G. Bouchard, M. Moy, X.Urbain. The official URL : Laure Gonnord (Lyon1/FST) Introduction 6 / 7

19 Evaluation One quick during an exercise session. Some of the lab exercises. A final exam. Laure Gonnord (Lyon1/FST) Introduction 7 / 7

20 Syntax Analysis MIF08 Laure Gonnord

21 Goal of this chapter Understand the syntaxic structure of a language; Separate the different steps of syntax analysis; Be able to write a syntax analysis tool for a simple language; Remember: syntax semantics. Laure Gonnord (Lyon1/FST) Syntax Analysis 2 / 29

22 Syntax analysis steps How do you read text? Text=a sequence of symbols (letters, spaces, punctuation); Group symbols into tokens: Words: groups of letters; Punctuation; Spaces. Laure Gonnord (Lyon1/FST) Syntax Analysis 3 / 29

23 Syntax analysis steps How do you read text? Text=a sequence of symbols (letters, spaces, punctuation); Group symbols into tokens: Lexical analysis Words: groups of letters; Punctuation; Spaces. Laure Gonnord (Lyon1/FST) Syntax Analysis 3 / 29

24 Syntax analysis steps How do you read text? Text=a sequence of symbols (letters, spaces, punctuation); Group symbols into tokens: Lexical analysis Words: groups of letters; Punctuation; Spaces. Group tokens into: Propositions; Sentences. Laure Gonnord (Lyon1/FST) Syntax Analysis 3 / 29

25 Syntax analysis steps How do you read text? Text=a sequence of symbols (letters, spaces, punctuation); Group symbols into tokens: Lexical analysis Words: groups of letters; Punctuation; Spaces. Group tokens into: Parsing Propositions; Sentences. Laure Gonnord (Lyon1/FST) Syntax Analysis 3 / 29

26 Syntax analysis steps How do you read text? Text=a sequence of symbols (letters, spaces, punctuation); Group symbols into tokens: Lexical analysis Words: groups of letters; Punctuation; Spaces. Group tokens into: Parsing Propositions; Sentences. Then proceed with word meanings: Definition of each word. ex: a dog is a hairy mammal, that barks and... Role in the phrase: verb, subject,... Laure Gonnord (Lyon1/FST) Syntax Analysis 3 / 29

27 Syntax analysis steps How do you read text? Text=a sequence of symbols (letters, spaces, punctuation); Group symbols into tokens: Lexical analysis Words: groups of letters; Punctuation; Spaces. Group tokens into: Parsing Propositions; Sentences. Then proceed with word meanings: Semantics Definition of each word. ex: a dog is a hairy mammal, that barks and... Role in the phrase: verb, subject,... Laure Gonnord (Lyon1/FST) Syntax Analysis 3 / 29

28 Syntax analysis steps How do you read text? Text=a sequence of symbols (letters, spaces, punctuation); Group symbols into tokens: Lexical analysis Words: groups of letters; Punctuation; Spaces. Group tokens into: Parsing Propositions; Sentences. Then proceed with word meanings: Semantics Definition of each word. ex: a dog is a hairy mammal, that barks and... Role in the phrase: verb, subject,... Syntax analysis=lexical analysis+parsing Laure Gonnord (Lyon1/FST) Syntax Analysis 3 / 29

29 Lexical Analysis aka Lexing Outline 1 Lexical Analysis aka Lexing 2 Parsing Laure Gonnord (Lyon1/FST) Syntax Analysis 4 / 29

30 Lexical Analysis aka Lexing What for? int y = *x ; = [TINT, VAR("y"), EQ, INT(12), PLUS, INT(4), TIMES, VAR("x"), SCOL] Group characters into a list of tokens, e.g.: The word int stands for type integer; A sequence of letters stands for a variable; A sequence of digits stands for an integer;... Laure Gonnord (Lyon1/FST) Syntax Analysis 5 / 29

31 Lexical Analysis aka Lexing What s behind From a Regular Language, produce a Finite State Machine (see LIF15) Laure Gonnord (Lyon1/FST) Syntax Analysis 6 / 29

32 Lexical Analysis aka Lexing Tools: lexical analyzer constructors Lexical analyzer constructor: builds an automaton from a regular language definition; Ex: Lex (C), JFlex (Java), OCamllex, ANTLR (multi),... input: a set of regular expressions with actions (Toto.g4); output: a file(s) (Toto.java) that contains the corresponding automaton. Laure Gonnord (Lyon1/FST) Syntax Analysis 7 / 29

33 Lexical Analysis aka Lexing Analyzing text with the compiled lexer The input of the lexer is a text file; Execution: Checks that the input is accepted by the compiled automaton; Executes some actions during the automaton traversal. Laure Gonnord (Lyon1/FST) Syntax Analysis 8 / 29

34 Lexical Analysis aka Lexing Lexing tool for Java: ANTLR The official webpage : (BSD license); ANTLR is both a lexer and a parser; ANTLR is multi-language (not only Java). During the labs; we will use the Python back-end (here, demo in java) Laure Gonnord (Lyon1/FST) Syntax Analysis 9 / 29

35 Lexical Analysis aka Lexing ANTLR lexer format and compilation.g4 grammar { // Some init code... { // Some global variables } // More optional blocks are available --->> lex rules Compilation: antlr4 Toto.g4 javac *.java grun Toto r // produces several Java files // compiles into xx.class files // Run analyzer with starting rule r Laure Gonnord (Lyon1/FST) Syntax Analysis 10 / 29

36 Lexical Analysis aka Lexing Lexing with ANTLR: example Lexing rules: Must start with an upper-case letter; Follow the usual extended regular-expressions syntax (same as egrep, sed... A simple example grammar H e l l o ; / / This r u l e i s a c t u a l l y a parsing r u l e r : HELLO ID ; / / match " h e l l o " f o l l o w e d by an i d e n t i f i e r HELLO : 'hello ' ; / / beware the s i n g l e quotes ID : [ a z ]+ ; / / match lower case i d e n t i f i e r s WS : [ \ t \ r \ n ]+ > s kip ; / / skip spaces, t a b s, newlines Laure Gonnord (Lyon1/FST) Syntax Analysis 11 / 29

37 Lexical Analysis aka Lexing Lexing - more than regular languages Counting in ANTLR - CountLines.g4 l e x e r grammar CountLines; / / Members can be accessed i n any r u l { i n t nblines=0 ; } NEWLINE : [ \ r \ n ] { nblines++ ; System. out. p r i n t l n ( " Current l i n e s : " +nblines ) ; } ; SK : ( [ a z ]+ [ \ t ] + ) > s kip ; antlr4 Toto.g4 javac *.java grun Toto 'tokens' // produces several Java files // compiles into xx.class files // Run the lexical analyser only Laure Gonnord (Lyon1/FST) Syntax Analysis 12 / 29

38 Parsing Outline 1 Lexical Analysis aka Lexing 2 Parsing Semantic actions / Attributes Laure Gonnord (Lyon1/FST) Syntax Analysis 13 / 29

39 Parsing What s Parsing? Relate tokens by structuring them. Flat tokens [TINT, VAR("y"), EQ, INT(12), PLUS, INT(4), TIMES, VAR("x"), SCOL] Parsing Yes/No + Structured tokens = int y + 12 * 4 x int Laure Gonnord (Lyon1/FST) Syntax Analysis 14 / 29

40 Parsing Analysis Phases source code lexical analysis sequence of lexems (tokens) syntactic analysis (Parsing) abstract syntax tree (AST ) semantic analysis abstract syntax (+ symbol table) Laure Gonnord (Lyon1/FST) Syntax Analysis 15 / 29

41 Parsing What s behind? From a Context-free Grammar, produce a Stack Automaton (see LIF15). Laure Gonnord (Lyon1/FST) Syntax Analysis 16 / 29

42 Parsing Tools: parser generators Parser generator: builds a stack automaton from a grammar definition; Ex: yacc(c), javacup (Java), OCamlyacc, ANTLR,... input : a set of grammar rules with actions (Toto.g4); output : a file(s) (Toto.java) that contains the corresponding stack automaton. Laure Gonnord (Lyon1/FST) Syntax Analysis 17 / 29

43 Parsing Lexing vs Parsing Lexing supports ( regular) languages; We want more (general) languages rely on context-free grammars; To that intent, we need a way: To declare terminal symbols (tokens); To write grammars. Use both Lexing rules and Parsing rules. Laure Gonnord (Lyon1/FST) Syntax Analysis 18 / 29

44 Parsing From a grammar to a parser The grammar must be context-free: S-> asb S-> eps The grammar rules are specified as Parsing rules; a and b are terminal tokens, produced by Lexing rules. On board: notion of derivation tree (see also exercise session2) Laure Gonnord (Lyon1/FST) Syntax Analysis 19 / 29

45 Parsing Parsing with ANTLR: example 1/2 AnBnLexer.g4 lexer grammar AnBnLexer; // Lexing rules: recognize tokens A: 'a ' ; B: 'b ' ; WS : [\ t \ r \ n ]+ -> skip ; // skip spaces, tabs, newlines Laure Gonnord (Lyon1/FST) Syntax Analysis 20 / 29

46 Parsing Parsing with ANTLR: example 2/2 AnBnParser.g4 parser grammar A nbnparser; options { tokenvocab = AnBnLexer; } // extern tokens definition // Parsing rules: structure tokens together prog : s EOF ; // EOF: predefined end - of - file token s : A s B ; // nothing for empty alternative Laure Gonnord (Lyon1/FST) Syntax Analysis 21 / 29

47 Parsing ANTLR expressivity LL(*) At parse-time, decisions gracefully throttle up from conventional fixed k 1 lookahead to arbitrary lookahead. Further reading (PLDI 11 paper, T. Parr, K. Fisher) Laure Gonnord (Lyon1/FST) Syntax Analysis 22 / 29

48 Parsing Left recursion ANTLR permits left recursion: a: a b; But not indirect left recursion. X 1... X n There exist algorithms to eliminate indirect recursions. Laure Gonnord (Lyon1/FST) Syntax Analysis 23 / 29

49 Parsing Lists ANTLR permits lists: prog: statement + ; Read the documentation! https: //github.com/antlr/antlr4/blob/master/doc/index.md Laure Gonnord (Lyon1/FST) Syntax Analysis 24 / 29

50 Parsing Semantic actions / Attributes Outline 1 Lexical Analysis aka Lexing 2 Parsing Semantic actions / Attributes Laure Gonnord (Lyon1/FST) Syntax Analysis 25 / 29

51 Parsing Semantic actions / Attributes Semantic actions Semantic actions: code executed each time a grammar rule is matched. Printing as a semantic action in ANTLR s : A s B { System. out. println (" rule s"); } s : A s B { print (" rule s"); } // python Right rule : Python/Java/C++, depending on the back-end antlr4 -Dlanguage=Python3 We can do more than acceptors. Laure Gonnord (Lyon1/FST) Syntax Analysis 26 / 29

52 Parsing Semantic actions / Attributes Semantic actions - attributes An attribute is a set attached to non-terminals/terminals of the grammar They are usually of two types: synthetized: sons father. inherited: the converse. Laure Gonnord (Lyon1/FST) Syntax Analysis 27 / 29

53 Parsing Semantic actions / Attributes Semantic attributes for numerical expressions 1/2 e ::= c constant x variable e + e add e e mult... Let s come to an attribution. On board. Laure Gonnord (Lyon1/FST) Syntax Analysis 28 / 29

54 Parsing Semantic actions / Attributes Semantic attributes 2/2 : Implem Implementation of the former actions (java): ArithExprParser.g4 parser grammar A r i t h E x p r P a r s e r ; options {tokenvocab=arithexprlexer; } prog : expr EOF { System. out. p r i n t l n ( " R e s u l t : " +$expr. v a l ) ; } ; expr r e t u r n s [ i n t v a l ] : / / expr has an i n t e g e r a t t r i b u t e LPAR e=expr RPAR { $val=$e. v a l ; } INT { $val=$int. i n t ; } / / i m p l i c i t a t t r i b u t e f o r INT e1=expr PLUS e2=expr / / name sub p a r t s { $val=$e1. v a l +$e2. v a l ; } / / access a t t r i b u t e s e1=expr MINUS e2=expr { $val=$e1. val $e2. v a l ; } ; Laure Gonnord (Lyon1/FST) Syntax Analysis 29 / 29

Syntax Analysis MIF08. Laure Gonnord

Syntax Analysis MIF08. Laure Gonnord Syntax Analysis MIF08 Laure Gonnord Laure.Gonnord@univ-lyon1.fr Goal of this chapter Understand the syntaxic structure of a language; Separate the different steps of syntax analysis; Be able to write a

More information

Lexing, Parsing. Laure Gonnord sept Master 1, ENS de Lyon

Lexing, Parsing. Laure Gonnord  sept Master 1, ENS de Lyon Lexing, Parsing Laure Gonnord http://laure.gonnord.org/pro/teaching/capm1.html Laure.Gonnord@ens-lyon.fr Master 1, ENS de Lyon sept 2017 Analysis Phase source code lexical analysis sequence of lexems (tokens)

More information

Introduction - CAP Course

Introduction - CAP Course Introduction - CAP Course Laure Gonnord http://laure.gonnord.org/pro/teaching/ Laure.Gonnord@ens-lyon.fr Master 1, ENS de Lyon sept 2016 Credits A large part of the compilation part of this course is inspired

More information

Writing Evaluators MIF08. Laure Gonnord

Writing Evaluators MIF08. Laure Gonnord Writing Evaluators MIF08 Laure Gonnord Laure.Gonnord@univ-lyon1.fr Evaluators, what for? Outline 1 Evaluators, what for? 2 Implementation Laure Gonnord (Lyon1/FST) Writing Evaluators 2 / 21 Evaluators,

More information

Compil M1 : Front-End

Compil M1 : Front-End Compil M1 : Front-End TD1 : Introduction à Flex/Bison Laure Gonnord (groupe B) http://laure.gonnord.org/pro/teaching/ Laure.Gonnord@univ-lyon1.fr Master 1 - Université Lyon 1 - FST Plan 1 Lexical Analysis

More information

Lab 2. Lexing and Parsing with ANTLR4

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

More information

Lab 1. Warm-up : discovering the target machine, LEIA

Lab 1. Warm-up : discovering the target machine, LEIA Lab 1 Warm-up : discovering the target machine, LEIA Objective Be familiar with the LEIA 1 instruction set. Understand how it executes on the LEIA processor with the help of a simulator. Write simple programs,

More information

Lexical Analysis. Chapter 2

Lexical Analysis. Chapter 2 Lexical Analysis Chapter 2 1 Outline Informal sketch of lexical analysis Identifies tokens in input string Issues in lexical analysis Lookahead Ambiguities Specifying lexers Regular expressions Examples

More information

Introduction to Lexical Analysis

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

Semantic Analysis. Lecture 9. February 7, 2018

Semantic Analysis. Lecture 9. February 7, 2018 Semantic Analysis Lecture 9 February 7, 2018 Midterm 1 Compiler Stages 12 / 14 COOL Programming 10 / 12 Regular Languages 26 / 30 Context-free Languages 17 / 21 Parsing 20 / 23 Extra Credit 4 / 6 Average

More information

Week 2: Syntax Specification, Grammars

Week 2: Syntax Specification, Grammars CS320 Principles of Programming Languages Week 2: Syntax Specification, Grammars Jingke Li Portland State University Fall 2017 PSU CS320 Fall 17 Week 2: Syntax Specification, Grammars 1/ 62 Words and Sentences

More information

Introduction to Compiler Design

Introduction to Compiler Design Introduction to Compiler Design Lecture 1 Chapters 1 and 2 Robb T. Koether Hampden-Sydney College Wed, Jan 14, 2015 Robb T. Koether (Hampden-Sydney College) Introduction to Compiler Design Wed, Jan 14,

More information

Building Compilers with Phoenix

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

More information

Topic 3: Syntax Analysis I

Topic 3: Syntax Analysis I Topic 3: Syntax Analysis I Compiler Design Prof. Hanjun Kim CoreLab (Compiler Research Lab) POSTECH 1 Back-End Front-End The Front End Source Program Lexical Analysis Syntax Analysis Semantic Analysis

More information

Lexical Analysis. Lecture 2-4

Lexical Analysis. Lecture 2-4 Lexical Analysis Lecture 2-4 Notes by G. Necula, with additions by P. Hilfinger Prof. Hilfinger CS 164 Lecture 2 1 Administrivia Moving to 60 Evans on Wednesday HW1 available Pyth manual available on line.

More information

Interpreter. Scanner. Parser. Tree Walker. read. request token. send token. send AST I/O. Console

Interpreter. Scanner. Parser. Tree Walker. read. request token. send token. send AST I/O. Console Scanning 1 read Interpreter Scanner request token Parser send token Console I/O send AST Tree Walker 2 Scanner This process is known as: Scanning, lexing (lexical analysis), and tokenizing This is the

More information

Lab 1. Warm-up : Python and the target machine : LEIA

Lab 1. Warm-up : Python and the target machine : LEIA Lab 1 Warm-up : Python and the target machine : LEIA Objective Start with Python. Be familiar with the LEIA 1 instruction set. Understand how it executes on the LEIA processor with the help of a simulator.

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

CSE450 Translation of Programming Languages. Lecture 4: Syntax Analysis

CSE450 Translation of Programming Languages. Lecture 4: Syntax Analysis CSE450 Translation of Programming Languages Lecture 4: Syntax Analysis http://xkcd.com/859 Structure of a Today! Compiler Source Language Lexical Analyzer Syntax Analyzer Semantic Analyzer Int. Code Generator

More information

Compiler Design (40-414)

Compiler Design (40-414) Compiler Design (40-414) Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007 Evaluation: Midterm Exam 35% Final Exam 35% Assignments and Quizzes 10% Project

More information

Lexical Analysis. Introduction

Lexical Analysis. Introduction Lexical Analysis Introduction Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California have explicit permission to make copies

More information

Lab 2. Lexing and Parsing with Flex and Bison - 2 labs

Lab 2. Lexing and Parsing with Flex and Bison - 2 labs Lab 2 Lexing and Parsing with Flex and Bison - 2 labs Objective Understand the software architecture of flex/bison. Be able to write simple grammars in bison. Be able to correct grammar issues in bison.

More information

Programming Languages and Compilers (CS 421)

Programming Languages and Compilers (CS 421) Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC http://courses.engr.illinois.edu/cs421 Based in part on slides by Mattox Beckman, as updated by Vikram Adve and Gul Agha 10/20/16

More information

KU Compilerbau - Programming Assignment

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

More information

n (0 1)*1 n a*b(a*) n ((01) (10))* n You tell me n Regular expressions (equivalently, regular 10/20/ /20/16 4

n (0 1)*1 n a*b(a*) n ((01) (10))* n You tell me n Regular expressions (equivalently, regular 10/20/ /20/16 4 Regular Expressions Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC http://courses.engr.illinois.edu/cs421 Based in part on slides by Mattox Beckman, as updated by Vikram Adve

More information

Introduction to Lexical Analysis

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

Formal Languages and Compilers Lecture VI: Lexical Analysis

Formal Languages and Compilers Lecture VI: Lexical Analysis Formal Languages and Compilers Lecture VI: Lexical Analysis Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/ artale/ Formal

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

Examples of attributes: values of evaluated subtrees, type information, source file coordinates,

Examples of attributes: values of evaluated subtrees, type information, source file coordinates, 1 2 3 Attributes can be added to the grammar symbols, and program fragments can be added as semantic actions to the grammar, to form a syntax-directed translation scheme. Some attributes may be set by

More information

Introduction to Parsing. Lecture 8

Introduction to Parsing. Lecture 8 Introduction to Parsing Lecture 8 Adapted from slides by G. Necula Outline Limitations of regular languages Parser overview Context-free grammars (CFG s) Derivations Languages and Automata Formal languages

More information

Lexical Analysis. Finite Automata

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

Administrivia. Lexical Analysis. Lecture 2-4. Outline. The Structure of a Compiler. Informal sketch of lexical analysis. Issues in lexical analysis

Administrivia. Lexical Analysis. Lecture 2-4. Outline. The Structure of a Compiler. Informal sketch of lexical analysis. Issues in lexical analysis dministrivia Lexical nalysis Lecture 2-4 Notes by G. Necula, with additions by P. Hilfinger Moving to 6 Evans on Wednesday HW available Pyth manual available on line. Please log into your account and electronically

More information

Lexical Analysis. Chapter 1, Section Chapter 3, Section 3.1, 3.3, 3.4, 3.5 JFlex Manual

Lexical Analysis. Chapter 1, Section Chapter 3, Section 3.1, 3.3, 3.4, 3.5 JFlex Manual Lexical Analysis Chapter 1, Section 1.2.1 Chapter 3, Section 3.1, 3.3, 3.4, 3.5 JFlex Manual Inside the Compiler: Front End Lexical analyzer (aka scanner) Converts ASCII or Unicode to a stream of tokens

More information

Compilers and computer architecture From strings to ASTs (2): context free grammars

Compilers and computer architecture From strings to ASTs (2): context free grammars 1 / 1 Compilers and computer architecture From strings to ASTs (2): context free grammars Martin Berger October 2018 Recall the function of compilers 2 / 1 3 / 1 Recall we are discussing parsing Source

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

CIS 341 Midterm February 28, Name (printed): Pennkey (login id): SOLUTIONS

CIS 341 Midterm February 28, Name (printed): Pennkey (login id): SOLUTIONS CIS 341 Midterm February 28, 2013 Name (printed): Pennkey (login id): My signature below certifies that I have complied with the University of Pennsylvania s Code of Academic Integrity in completing this

More information

Compiler Optimisation

Compiler Optimisation Compiler Optimisation 1 Introductory Lecture Hugh Leather IF 1.18a hleather@inf.ed.ac.uk Institute for Computing Systems Architecture School of Informatics University of Edinburgh 2018 Textbooks Engineering

More information

Building Compilers with Phoenix

Building Compilers with Phoenix Building Compilers with Phoenix Parser Generators: ANTLR History of ANTLR ANother Tool for Language Recognition Terence Parr's dissertation: Obtaining Practical Variants of LL(k) and LR(k) for k > 1 PCCTS:

More information

Compiler Construction D7011E

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

More information

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 3 Lexical Analysis

Chapter 3 Lexical Analysis Chapter 3 Lexical Analysis Outline Role of lexical analyzer Specification of tokens Recognition of tokens Lexical analyzer generator Finite automata Design of lexical analyzer generator The role of lexical

More information

Lexical Analysis. Lecture 3-4

Lexical Analysis. Lecture 3-4 Lexical Analysis Lecture 3-4 Notes by G. Necula, with additions by P. Hilfinger Prof. Hilfinger CS 164 Lecture 3-4 1 Administrivia I suggest you start looking at Python (see link on class home page). Please

More information

Lecture 14 Sections Mon, Mar 2, 2009

Lecture 14 Sections Mon, Mar 2, 2009 Lecture 14 Sections 5.1-5.4 Hampden-Sydney College Mon, Mar 2, 2009 Outline 1 2 3 4 5 Parse A parse tree shows the grammatical structure of a statement. It includes all of the grammar symbols (terminals

More information

Syntactic Analysis. CS345H: Programming Languages. Lecture 3: Lexical Analysis. Outline. Lexical Analysis. What is a Token? Tokens

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

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

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

More information

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

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

More information

Introduction to Parsing Ambiguity and Syntax Errors

Introduction to Parsing Ambiguity and Syntax Errors Introduction to Parsing Ambiguity and Syntax rrors Outline Regular languages revisited Parser overview Context-free grammars (CFG s) Derivations Ambiguity Syntax errors Compiler Design 1 (2011) 2 Languages

More information

Lab 5. Syntax-Directed Code Generation

Lab 5. Syntax-Directed Code Generation Lab 5 Syntax-Directed Code Generation Objective Generate 3-address code for the Mu language. Generate executable dummy LEIA from programs in Mu via 2 simple allocation algorithms. Student files are in

More information

Cunning Plan. Informal Sketch of Lexical Analysis. Issues in Lexical Analysis. Specifying Lexers

Cunning Plan. Informal Sketch of Lexical Analysis. Issues in Lexical Analysis. Specifying Lexers Cunning Plan Informal Sketch of Lexical Analysis LA identifies tokens from input string lexer : (char list) (token list) Issues in Lexical Analysis Lookahead Ambiguity Specifying Lexers Regular Expressions

More information

Compiler course. Chapter 3 Lexical Analysis

Compiler course. Chapter 3 Lexical Analysis Compiler course Chapter 3 Lexical Analysis 1 A. A. Pourhaji Kazem, Spring 2009 Outline Role of lexical analyzer Specification of tokens Recognition of tokens Lexical analyzer generator Finite automata

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

Compiler phases. Non-tokens

Compiler phases. Non-tokens Compiler phases Compiler Construction Scanning Lexical Analysis source code scanner tokens regular expressions lexical analysis Lennart Andersson parser context free grammar Revision 2011 01 21 parse tree

More information

Introduction to Parsing Ambiguity and Syntax Errors

Introduction to Parsing Ambiguity and Syntax Errors Introduction to Parsing Ambiguity and Syntax rrors Outline Regular languages revisited Parser overview Context-free grammars (CFG s) Derivations Ambiguity Syntax errors 2 Languages and Automata Formal

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

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology exam Compiler Construction in4303 April 9, 2010 14.00-15.30 This exam (6 pages) consists of 52 True/False

More information

CMSC 350: COMPILER DESIGN

CMSC 350: COMPILER DESIGN Lecture 11 CMSC 350: COMPILER DESIGN see HW3 LLVMLITE SPECIFICATION Eisenberg CMSC 350: Compilers 2 Discussion: Defining a Language Premise: programming languages are purely formal objects We (as language

More information

CSCI312 Principles of Programming Languages!

CSCI312 Principles of Programming Languages! CSCI312 Principles of Programming Languages!! Chapter 3 Regular Expression and Lexer Xu Liu Recap! Copyright 2006 The McGraw-Hill Companies, Inc. Clite: Lexical Syntax! Input: a stream of characters from

More information

CSE302: Compiler Design

CSE302: Compiler Design CSE302: Compiler Design Instructor: Dr. Liang Cheng Department of Computer Science and Engineering P.C. Rossin College of Engineering & Applied Science Lehigh University February 01, 2007 Outline Recap

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

COSE312: Compilers. Lecture 1 Overview of Compilers

COSE312: Compilers. Lecture 1 Overview of Compilers COSE312: Compilers Lecture 1 Overview of Compilers Hakjoo Oh 2017 Spring Hakjoo Oh COSE312 2017 Spring, Lecture 1 March 7, 2017 1 / 15 What is Compiler? Software systems that translate a program written

More information

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done What is a compiler? What is a compiler? Traditionally: Program that analyzes and translates from a high level language (e.g., C++) to low-level assembly language that can be executed by hardware int a,

More information

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

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

More information

COMPILER DESIGN LECTURE NOTES

COMPILER DESIGN LECTURE NOTES COMPILER DESIGN LECTURE NOTES UNIT -1 1.1 OVERVIEW OF LANGUAGE PROCESSING SYSTEM 1.2 Preprocessor A preprocessor produce input to compilers. They may perform the following functions. 1. Macro processing:

More information

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis CS 1622 Lecture 2 Lexical Analysis CS 1622 Lecture 2 1 Lecture 2 Review of last lecture and finish up overview The first compiler phase: lexical analysis Reading: Chapter 2 in text (by 1/18) CS 1622 Lecture

More information

Parser Tools: lex and yacc-style Parsing

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

More information

Programming Languages & Compilers. Programming Languages and Compilers (CS 421) Programming Languages & Compilers. Major Phases of a Compiler

Programming Languages & Compilers. Programming Languages and Compilers (CS 421) Programming Languages & Compilers. Major Phases of a Compiler Programming Languages & Compilers Programming Languages and Compilers (CS 421) Three Main Topics of the Course I II III Sasa Misailovic 4110 SC, UIUC https://courses.engr.illinois.edu/cs421/fa2017/cs421a

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

EDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised:

EDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised: EDAN65: Compilers, Lecture 06 A LR parsing Görel Hedin Revised: 2017-09-11 This lecture Regular expressions Context-free grammar Attribute grammar Lexical analyzer (scanner) Syntactic analyzer (parser)

More information

Programming Languages and Compilers (CS 421)

Programming Languages and Compilers (CS 421) Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC http://courses.engr.illinois.edu/cs421 Based in part on slides by Mattox Beckman, as updated by Vikram Adve and Gul Agha 10/30/17

More information

Programming Languages & Compilers. Programming Languages and Compilers (CS 421) I. Major Phases of a Compiler. Programming Languages & Compilers

Programming Languages & Compilers. Programming Languages and Compilers (CS 421) I. Major Phases of a Compiler. Programming Languages & Compilers Programming Languages & Compilers Programming Languages and Compilers (CS 421) I Three Main Topics of the Course II III Elsa L Gunter 2112 SC, UIUC http://courses.engr.illinois.edu/cs421 New Programming

More information

Parser Tools: lex and yacc-style Parsing

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

More information

Undergraduate Compilers in a Day

Undergraduate Compilers in a Day Question of the Day Backpatching o.foo(); In Java, the address of foo() is often not known until runtime (due to dynamic class loading), so the method call requires a table lookup. After the first execution

More information

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

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

More information

Compiler Code Generation COMP360

Compiler Code Generation COMP360 Compiler Code Generation COMP360 Students who acquire large debts putting themselves through school are unlikely to think about changing society. When you trap people in a system of debt, they can t afford

More information

Outline. Limitations of regular languages. Introduction to Parsing. Parser overview. Context-free grammars (CFG s)

Outline. Limitations of regular languages. Introduction to Parsing. Parser overview. Context-free grammars (CFG s) Outline Limitations of regular languages Introduction to Parsing Parser overview Lecture 8 Adapted from slides by G. Necula Context-free grammars (CFG s) Derivations Languages and Automata Formal languages

More information

Introduction to Parsing. Lecture 5

Introduction to Parsing. Lecture 5 Introduction to Parsing Lecture 5 1 Outline Regular languages revisited Parser overview Context-free grammars (CFG s) Derivations Ambiguity 2 Languages and Automata Formal languages are very important

More information

PSD3A Principles of Compiler Design Unit : I-V. PSD3A- Principles of Compiler Design

PSD3A Principles of Compiler Design Unit : I-V. PSD3A- Principles of Compiler Design PSD3A Principles of Compiler Design Unit : I-V 1 UNIT I - SYLLABUS Compiler Assembler Language Processing System Phases of Compiler Lexical Analyser Finite Automata NFA DFA Compiler Tools 2 Compiler -

More information

COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview

COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview COMP 181 Compilers Lecture 2 Overview September 7, 2006 Administrative Book? Hopefully: Compilers by Aho, Lam, Sethi, Ullman Mailing list Handouts? Programming assignments For next time, write a hello,

More information

Exercise ANTLRv4. Patryk Kiepas. March 25, 2017

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

More information

CD Assignment I. 1. Explain the various phases of the compiler with a simple example.

CD Assignment I. 1. Explain the various phases of the compiler with a simple example. CD Assignment I 1. Explain the various phases of the compiler with a simple example. The compilation process is a sequence of various phases. Each phase takes input from the previous, and passes the output

More information

CSE 3302 Programming Languages Lecture 2: Syntax

CSE 3302 Programming Languages Lecture 2: Syntax CSE 3302 Programming Languages Lecture 2: Syntax (based on slides by Chengkai Li) Leonidas Fegaras University of Texas at Arlington CSE 3302 L2 Spring 2011 1 How do we define a PL? Specifying a PL: Syntax:

More information

Preparing for the ACW Languages & Compilers

Preparing for the ACW Languages & Compilers Preparing for the ACW 08348 Languages & Compilers Introductory Lab There is an Introductory Lab Just involves copying the lab task See separate Lab slides Language Roadmaps Convenient way of showing syntax

More information

Lexical Analysis. Finite Automata

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

CSE 130 Programming Language Principles & Paradigms Lecture # 5. Chapter 4 Lexical and Syntax Analysis

CSE 130 Programming Language Principles & Paradigms Lecture # 5. Chapter 4 Lexical and Syntax Analysis Chapter 4 Lexical and Syntax Analysis Introduction - Language implementation systems must analyze source code, regardless of the specific implementation approach - Nearly all syntax analysis is based on

More information

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

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan Compilers Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan Lexical Analyzer (Scanner) 1. Uses Regular Expressions to define tokens 2. Uses Finite Automata to recognize tokens

More information

UNIT -2 LEXICAL ANALYSIS

UNIT -2 LEXICAL ANALYSIS OVER VIEW OF LEXICAL ANALYSIS UNIT -2 LEXICAL ANALYSIS o To identify the tokens we need some method of describing the possible tokens that can appear in the input stream. For this purpose we introduce

More information

Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization

Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES (2018-19) (ODD) Code Optimization Prof. Jonita Roman Date: 30/06/2018 Time: 9:45 to 10:45 Venue: MCA

More information

Profile Language Compiler Chao Gong, Paaras Kumar May 7, 2001

Profile Language Compiler Chao Gong, Paaras Kumar May 7, 2001 Profile Language Compiler Chao Gong, Paaras Kumar May 7, 2001 Abstract Our final project for CS227b is to implement a profile language compiler using PRECCX. The profile, which is a key component in the

More information

Lexical Analysis - An Introduction. Lecture 4 Spring 2005 Department of Computer Science University of Alabama Joel Jones

Lexical Analysis - An Introduction. Lecture 4 Spring 2005 Department of Computer Science University of Alabama Joel Jones Lexical Analysis - An Introduction Lecture 4 Spring 2005 Department of Computer Science University of Alabama Joel Jones Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.

More information

Fall Compiler Principles Lecture 4: Parsing part 3. Roman Manevich Ben-Gurion University of the Negev

Fall Compiler Principles Lecture 4: Parsing part 3. Roman Manevich Ben-Gurion University of the Negev Fall 2016-2017 Compiler Principles Lecture 4: Parsing part 3 Roman Manevich Ben-Gurion University of the Negev Tentative syllabus Front End Intermediate Representation Optimizations Code Generation Scanning

More information

Structure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler.

Structure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler. More detailed overview of compiler front end Structure of a compiler Today we ll take a quick look at typical parts of a compiler. This is to give a feeling for the overall structure. source program lexical

More information

CSCI 2041: Advanced Language Processing

CSCI 2041: Advanced Language Processing CSCI 2041: Advanced Language Processing Chris Kauffman Last Updated: Wed Nov 28 13:25:47 CST 2018 1 Logistics Reading OSM: Ch 17 The Debugger OSM: Ch 13 Lexer and Parser Generators (optional) Practical

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

Compiler Design Overview. Compiler Design 1

Compiler Design Overview. Compiler Design 1 Compiler Design Overview Compiler Design 1 Preliminaries Required Basic knowledge of programming languages. Basic knowledge of FSA and CFG. Knowledge of a high programming language for the programming

More information

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

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

More information

COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR

COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR Pune Vidyarthi Griha s COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR By Prof. Anand N. Gharu (Assistant Professor) PVGCOE Computer Dept.. 22nd Jan 2018 CONTENTS :- 1. Role of lexical analysis 2.

More information

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast! Lexical Analysis Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast! Compiler Passes Analysis of input program (front-end) character stream

More information

Implementation of Lexical Analysis

Implementation of Lexical Analysis Implementation of Lexical Analysis Outline Specifying lexical structure using regular expressions Finite automata Deterministic Finite Automata (DFAs) Non-deterministic Finite Automata (NFAs) Implementation

More information

flex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input.

flex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input. flex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input. More often than not, though, you ll want to use flex to generate a scanner that divides

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