Standardizing RPAL ASTs Programming Language Principles Lecture 10

  • Slides: 30
Download presentation
Standardizing RPAL AST’s Programming Language Principles Lecture 10 Prepared by Manuel E. Bermúdez, Ph.

Standardizing RPAL AST’s Programming Language Principles Lecture 10 Prepared by Manuel E. Bermúdez, Ph. D. Associate Professor University of Florida

The Semantics of RPAL We use the operational approach: To specify the semantics of

The Semantics of RPAL We use the operational approach: To specify the semantics of a language, we give an OPERATIONAL PROCESS. In contrast, later we will discuss the DENOTATIONAL approach: PL constructs are “denoted” with functions whose behavior specify the meaning of the program.

The RPAL Operational Specification • In the case of RPAL, the process is 1.

The RPAL Operational Specification • In the case of RPAL, the process is 1. Scan and parse the program, transduce to a tree. 2. Standardize the tree.

The RPAL Operational Specification (cont’d) 3. Flatten the tree into either: a. A lambda

The RPAL Operational Specification (cont’d) 3. Flatten the tree into either: a. A lambda expression. b. Control Structures for a machine (more later) • Important: • RPAL = lambda-calculus + syntactic sugar

Standardizing an RPAL AST • "Desugar" the tree. • Transform into a binary tree,

Standardizing an RPAL AST • "Desugar" the tree. • Transform into a binary tree, whose internal nodes are exclusively 'gamma' and 'lambda'. • Use the RPAL subtree transformational grammar (pictorial version)

Standardizing 'let' and 'where' • See example let / = P / X E

Standardizing 'let' and 'where' • See example let / = P / X E gamma / => lambda E / X P where / <= P = / X E

Standardizing 'fcn_form' • See example fcn_form / |  P V+ E => =

Standardizing 'fcn_form' • See example fcn_form / | P V+ E => = / P +lambda / V. E • V+ means "one or more", to be repeated likewise on right side. • The 'dot' indicates the location of the pattern's repetition.

Standardizing Tuples • See example tau => ++gamma | /  E++ gamma E

Standardizing Tuples • See example tau => ++gamma | / E++ gamma E / aug. nil E++ means “two or more” E’s.

Standardizing Multi-Parameter Functions • See example lambda /  V++ E => ++lambda /

Standardizing Multi-Parameter Functions • See example lambda / V++ E => ++lambda / V. E

Standardizing the 'within' • See example within => /  = = / /

Standardizing the 'within' • See example within => / = = / / X 1 E 1 X 2 E 2 = / X 2 gamma / lambda E 1 / X 1 E 2

Standardizing Unary and Binary Operators • See example Uop | E => gamma /

Standardizing Unary and Binary Operators • See example Uop | E => gamma / Uop E Op => gamma / / E 1 E 2 gamma E 2 / Op E 1 Uop in [not, neg] Op in [aug, or, &, +, -, /, **, gr, . . . ]

Standardizing the '@' Operator • See example @ => gamma /| /  E

Standardizing the '@' Operator • See example @ => gamma /| / E 1 N E 2 gamma E 2 / N E 1

Standardizing Simultaneous Definitions • See example and => | =++ / X E =

Standardizing Simultaneous Definitions • See example and => | =++ / X E = / , tau | | X++ E++

Standardizing Simultaneous Definitions (cont’d) lambda /  , E | X++i => lambda /

Standardizing Simultaneous Definitions (cont’d) lambda / , E | X++i => lambda / Temp ++gamma / lambda gamma / X. i. E Temp <INTEGER: i>

Standardizing the Conditional Operator → => /| B T F gamma /  gamma

Standardizing the Conditional Operator → => /| B T F gamma / gamma nil / gamma lambda () F / Cond B () T Cond = fn B. fn T. fn F. B → T | F Circular semantic definition ! Purpose of lambdas: delay evaluation until one option is discarded

Circular Semantic Definitions • K. Goedel's Incompleteness Theorem (1930's): Every logic system is either

Circular Semantic Definitions • K. Goedel's Incompleteness Theorem (1930's): Every logic system is either incomplete or inconsistent. • Incomplete is preferable to inconsistent. • Inevitable in semantics: look up “building” in Webster’s dictionary. • English dictionary is useless to someone who understands no English.

Standardizing 'rec' • Will do later rec => | = / X E =

Standardizing 'rec' • Will do later rec => | = / X E = / X gamma / Ystar lambda / X E

Summary • Transform AST into a standardized tree (ST). • ST is binary. •

Summary • Transform AST into a standardized tree (ST). • ST is binary. • All internal nodes in the ST are either gamma or lambda. • It’s called “desugaring” the program: reducing it to two constructs: function abstraction/definition (lambda), and function application (gamma).

Standardizing RPAL AST’s Programming Language Principles Lecture 10 Prepared by Manuel E. Bermúdez, Ph.

Standardizing RPAL AST’s Programming Language Principles Lecture 10 Prepared by Manuel E. Bermúdez, Ph. D. Associate Professor University of Florida