High-Level Programming Language

Slides:



Advertisements
Similar presentations
Programming Languages Third Edition Chapter 6 Syntax.
Advertisements

Compilers and Language Translation
CPSC Compiler Tutorial 9 Review of Compiler.
ISBN Chapter 3 Describing Syntax and Semantics.
1 Chapter 5 Compilers Source Code (with macro) Macro Processor Expanded Code Compiler or Assembler obj.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
PZ02A - Language translation
1 Terminology l Statement ( 敘述 ) »declaration, assignment containing expression ( 運算式 ) l Grammar ( 文法 ) »a set of rules specify the form of legal statements.
Specifying Languages CS 480/680 – Comparative Languages.
Invitation to Computer Science 5th Edition
1 Syntax and Semantics The Purpose of Syntax Problem of Describing Syntax Formal Methods of Describing Syntax Derivations and Parse Trees Sebesta Chapter.
Compiler1 Chapter V: Compiler Overview: r To study the design and operation of compiler for high-level programming languages. r Contents m Basic compiler.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
Winter 2007SEG2101 Chapter 71 Chapter 7 Introduction to Languages and Compiler.
LANGUAGE DESCRIPTION: SYNTACTIC STRUCTURE
1 Syntax In Text: Chapter 3. 2 Chapter 3: Syntax and Semantics Outline Syntax: Recognizer vs. generator BNF EBNF.
CPS 506 Comparative Programming Languages Syntax Specification.
D Goforth COSC Translating High Level Languages Note error in assignment 1: #4 - refer to Example grammar 3.4, p. 126.
Chapter 3 Describing Syntax and Semantics
1 Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
CSE 425: Syntax I Syntax and Semantics Syntax gives the structure of statements in a language –Allowed ordering, nesting, repetition, omission of symbols.
LECTURE 4 Syntax. SPECIFYING SYNTAX Programming languages must be very well defined – there’s no room for ambiguity. Language designers must use formal.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 12–Compilers.
Chapter 3 – Describing Syntax CSCE 343. Syntax vs. Semantics Syntax: The form or structure of the expressions, statements, and program units. Semantics:
Describing Syntax and Semantics Chapter 3: Describing Syntax and Semantics Lectures # 6.
CS 3304 Comparative Languages
Chapter 3 – Describing Syntax
Describing Syntax and Semantics
Chapter 6 Compiler.
Lexical and Syntax Analysis
CS510 Compiler Lecture 4.
Parsing and Parser Parsing methods: top-down & bottom-up
Chapter 3 Context-Free Grammar and Parsing
Chapter 3 – Describing Syntax
Concepts of Programming Languages
Overview of Compilation The Compiler Front End
Overview of Compilation The Compiler Front End
What does it mean? Notes from Robert Sebesta Programming Languages
Automata and Languages What do these have in common?
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Compiler Construction
Syntax versus Semantics
Compiler Lecture 1 CS510.
CS 363 Comparative Programming Languages
CS416 Compiler Design lec00-outline September 19, 2018
CSE 3302 Programming Languages
Introduction CI612 Compiler Design CI612 Compiler Design.
Programming Language Syntax 2
ENERGY 211 / CME 211 Lecture 15 October 22, 2008.
R.Rajkumar Asst.Professor CSE
CS 3304 Comparative Languages
CS 3304 Comparative Languages
Programming Languages 2nd edition Tucker and Noonan
September 13th Grammars.
BNF 23-Feb-19.
CS416 Compiler Design lec00-outline February 23, 2019
Syntax vs Semantics Backus-Naur Form Extended BNF Derivations
Chapter 3 Describing Syntax and Semantics.
BNF 9-Apr-19.
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Chapter 10: Compilers and Language Translation
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Programming Languages 2nd edition Tucker and Noonan
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
COMPILER CONSTRUCTION
Faculty of Computer Science and Information System
Presentation transcript:

Basic Compiler Functions Grammars Lexical Analysis Syntactic Analysis Code Generation

High-Level Programming Language A high-level programming language is described in terms of a grammar, which specifies the syntax of legal statements. An assignment statement: a variable name + an assignment operator + an expression

Compiler Compilation: matching statements (written by programmers) to structures (defined by the grammar) and generating the appropriate object code Lexical analysis (scanning) Scanning the source statement, recognizing and classifying the various tokens, including keywords, variable names, data types, operators, etc. Syntactic analysis (parsing) Recognizing each statement as some language construct described by the grammar Semantics (code generation) Generation of the object code

Grammars A grammar is a formal description of the syntax. BNF (Backus-Naur Form): A simple and widely used notations for writing grammars introduced by John Backus and Peter Naur in about 1960. Meta-symbols of BNF: ::= "is defined as" | "or" < > angle brackets used to surround non-terminal symbols A BNF rule defining a nonterminal has the form: nonterminal ::= sequence_of_alternatives consisting of strings of terminals (tokens) or nonterminals separated by the meta-symbol |

Simplified Pascal Grammar Recursive rule

Parse Tree (Syntax Tree) READ(VALUE) VARIANCE:=SUMSQ DIV 100 – MEAN*MEAN The multiplication and division precede the addition and subtraction

Parse Tree

Parse Tree

Lexical Analysis Tokens might be defined by grammar rules to be recognized by the parser: For better efficiency, a scanner can be used instead to recognize and output the tokens in a sequence represented by fixed-length codes and the associated token specifiers.

Lexical Scan

Modeling Scanners as Finite Automata Tokens can often be recognized by a finite automaton, which consists of A finite set of states (including a starting state and one or more final states) A set of transtitions from one state to another

Finite Automata for Typical Tokens

Token Recognition Algorithm