Guidebook 2

Guidebook 2 - CSCI 3155 Student Notes Parsing 2.1 2....

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSCI 3155 Student Notes Parsing 2.1 2. Parsing Coursework and Goals for This Part of the Course : By the end of this section, you will be able to… o write context-free grammar rules for typical programming language constructions such as lists and arithmetic expressions o draw parse trees that are generated by a context-free grammar for a given sequence of tokens o describe in English the patterns recognized by a context-free grammar o demonstrate ambiguities in grammars caused by arithmetic expressions and the dangling else problem o write a complete bison specification file to build a parser for significant parts of a programming language o explain the shift-reduce parse algorithm that a bison parser implements o explain the source of shift-reduce and reduce-reduce conflicts in a bison grammar, and solve those conflicts through the use of rules for associativity and operator precedence o use a bison-built parser in a small test program. Read Sebesta §3.3, 4.3, and 4.5 (if you haven’t already read them) Lecture topics: o What we have now: The lexer o The parser o Context-free grammars o A context-free grammar for the CU++ programming Language o Describing lists with and without separators o Left recursion vs right recursion o Parse trees o Ambiguity from associativity and operator precedence o The dangling-else ambiguity o Two ways to solve ambiguities o Building a parser with the bison tool o Bison's shift-reduce parsing algorithm o Solving shift-reduce and reduce-reduce conflicts in bison o Example: www.cs.colorado.edu/~main/proglang/examples/bison o Homework discussion including using a makefile Bison Reference: www.delorie.com/gnu/docs/bison/bison_toc.html Homework 2: Building a Parser
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSCI 3155 Student Notes Parsing 2.2 2.1. Introduction to Parsing Context-free grammars are one method to specify which sequences of tokens form a valid program. This approach is discussed in Sectiion 3.3 of the Sebesta textbook, which you should read before going through this section of the class notes. This section of the notes provides a grammar for the CU++ programming Language. Throughout the grammar specification, we address issues such as ambiguity [§3.3.1.7]. We also provide small commentary about the meanings of the program elements, but for the most part this specification is concerned only with recognizing the correct syntactic form of a CU++ program. 2.2. Terminal symbols Our grammar has 50-some terminal symbols that correspond to the token categories defined in Section 1.15. Although we use all capital letters for the names of the token categories, in the context-free grammar specification, we'll follow the style of Sebesta's textbook, using lower-case letters and actual symbol sequences for the names of the terminals. In particular, this specification will use these terminal symbols: 2.2.1 Each of the reserved words from Section 1.2 is a single terminal symbol. For example, while is one of our terminal symbols. 2.2.2
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

Guidebook 2 - CSCI 3155 Student Notes Parsing 2.1 2....

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online