Recursion and Rpal’s synTax

Slides:



Advertisements
Similar presentations
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Advertisements

AST Generation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Concepts Lecture 9.
CMSC 330: Organization of Programming Languages Tuples, Types, Conditionals and Recursion or “How many different OCaml topics can we cover in a single.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
1 Lecture 5 Topics –Closure Properties for REC Proofs –2 examples Applications.
Solving Equations Involving Cube Roots. Negative Solutions.
CIS Computer Programming Logic
Introduction to Scheme Lectures on The Scheme Programming Language, 2 nd Ed. R. Kent Dybvig.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Group 4 Java Compiler Group Members: Atul Singh(Y6127) Manish Agrawal(Y6241) Mayank Sachan(Y6253) Sudeept Sinha(Y6483)
Standardizing RPAL AST’s Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 10.
Writing RPAL Programs Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Concepts Lecture 13.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
The RPAL Functional Language Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Concepts Lecture 12.
Repetition Control Structure. Introduction Many applications require certain operations to be carried out more than once. Such situations require repetition.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
Programming Language Principles Lecture 32 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Course Summary.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Building AST's for RPAL Programs
Context-free grammars, derivation trees, and ambiguity
LL(1) grammars Module 07.1 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Tuples Module 11.1 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Paradigm blindness programming paradigms
Writing a scanner Module 05.5 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Overview of Compilation The Compiler Front End
Overview of Compilation The Compiler Front End
Topic: Recursion – Part 1
Parameter passing Module 12.3 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Fixing non-ll(1) grammars
Overview of Compilation The Compiler BACK End
The chomsky hierarchy Module 03.3 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Introduction to RPAL Module 10.1 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
RPAL Function definitions
Control structures Chapter 3.
Top-down derivation tree generation
Programming Language Principles
Regular grammars Module 04.1 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Programming Language Syntax 6
Recursive Descent Parsing
Bottom-up AST, original grammar
Top-down derivation tree generation
Top-down parsing Module 06.3 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Bottom-up derivation tree, original grammar
Bottom-up derivation tree, original grammar
TaBle-driven LL(1) Parsing
Overview of Compilation The Compiler BACK End
Bottom-up AST, original grammar
Bottom-up derivation tree generation
Control Structures: for & while Loops
TaBle-driven LL(1) Parsing
COP4020 Programming Language Concepts Dr. Manuel E. Bermudez
NFA->DFA Module 05.3 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Fixing non-ll(1) grammars
Repetition Control Structure
Regular Expression to NFA
Building AST's for RPAL Programs
Regular Expression to NFA
Replacing recursion with iteration
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
The RPAL Functional Language
Operator precedence and AST’s
Recursion and Fixed-Point Theory
Bottom-up derivation tree generation
Programming Language Principles
High-Level Programming Language
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Paradigms and paradigm shifts
Operator Precedence and Associativity
Presentation transcript:

Recursion and Rpal’s synTax Module 10.3 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez

Recursion in RPAL RPAL’s Syntax Topics Recursion in RPAL RPAL’s Syntax

Recursion in rpal Only way to achieve repetition. No loops in RPAL. Use the rec keyword. Without rec, the function is not recursive.

(classic) factorial let rec Fact n = n eq 1 -> 1 | n * Fact (n-1) in Print (Fact 3) Without rec, the scope of Fact would be the last line ONLY.

String length Typical layout: define functions, and print test cases. let rec length S = S eq '' -> 0 | 1 + length (Stern S) in Print ( length('1,2,3'), length (''), length('abc') ) Typical layout: define functions, and print test cases.

Is perfect square let Is_perfect_Square N = Has_sqrt_ge (N,1) where rec Has_sqrt_ge (N,R) = R**2 gr N -> false | R**2 eq N -> true | Has_sqrt_ge (N,R+1) in Print (Is_perfect_Square 4, Is_perfect_Square 64, Is_perfect_Square 3)

RPAL lexicon: many legal tokens the parser would reject.

summary Recursion in RPAL RPAL’s Syntax