0% found this document useful (0 votes)
153 views

Building AST's For RPAL Programs: Programming Language Principles

This document discusses building abstract syntax trees (ASTs) for programs in the RPAL programming language. It provides examples of building ASTs for factorial, palindrome, and adding numbers from a list programs. It then outlines the steps for a class project to build a recursive descent parser for RPAL, which would include a lexical analyzer, procedures for each nonterminal in RPAL's grammar, and a module to represent and traverse the ASTs using a first-child, next-sibling binary tree representation.

Uploaded by

Mrunal Ruikar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
153 views

Building AST's For RPAL Programs: Programming Language Principles

This document discusses building abstract syntax trees (ASTs) for programs in the RPAL programming language. It provides examples of building ASTs for factorial, palindrome, and adding numbers from a list programs. It then outlines the steps for a class project to build a recursive descent parser for RPAL, which would include a lexical analyzer, procedures for each nonterminal in RPAL's grammar, and a module to represent and traverse the ASTs using a first-child, next-sibling binary tree representation.

Uploaded by

Mrunal Ruikar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 15

Building AST's for RPAL Programs

Programming Language Principles Lecture 9

Prepared by

Manuel E. Bermdez, Ph.D.


Associate Professor University of Florida

Let's Build a Few Abstract Syntax Trees


Example 1: Factorial, version 3.
Example 2: Palindrome.

Example 3: Add numbers from list.


Example 5: Build tuple of pairs of characters.

Class Project
Build a recursive descent parser for RPAL (gulp!) If done properly, it's easy. Need lexical analyzer, to be called repeatedly (important!) by the parser. Avoid scanning the entire input in advance of the parser.

Class Project (contd)


Code up one procedure per nonterminal in RPAL's grammar. Pseudo code for some portions of RPALs grammar

Class Project (contd)


Implement support module for trees, and stack of trees. Suggestion: use first-child, nextsibling binary tree representation of n-ary trees (it works!). Preorder traversal of this tree is the same as for n-ary tree. Popping n trees from the stack, and building a parent node on top of them, is easy.

Building AST's for RPAL Programs


Programming Language Principles Lecture 9

Prepared by

Manuel E. Bermdez, Ph.D.


Associate Professor University of Florida

You might also like