{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

20101111 - = CS 441 Fall 2010 JWJ Pre-class notes do not...

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

View Full Document Right Arrow Icon
============================ CS 441 Fall 2010 -- JWJ Pre-class notes - do not distribute Thursday, November 11, 2010 ============================ Topics Constructing compilers with Yacc and Lex Concepts/Definitions This class has the format of practicum. We are working in the lab dissecting the calculator code from one of our textbook. We will review the basic elements of Bison and will see how the calculator can be modified to generate code for a P-stack machine. This modification is essential to your programming assignment that will be explained today. http://www.epaperpress.com/lexandyacc/index.html The general structure of a Yacc spec is ... definitions ... %% ... rules <<< The rules correspond to the syntax-directed translation. %% ... subroutines ... From the calc3.y ... (Tom Niemann) The language supported by calc3 is a calculator extended with basic control statements (while, if-then-else). The language does require declarations and does not support functions or blocks.
Background image of page 1

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

View Full Document Right Arrow Icon
Example program: n=12; p=1; i=1; while (i <= n) { p = p * i; print p; i = i + 1; }; and the AST corresponding to the while-loop is while | |-------------------------| | | [<=] [;] | | |-----| |-------------------| | | | | id(I) id(N) [;] [=] | | |-----------| |-------| | | | | [=] print id(I) [+] | | | |--------| | |----| | | | | | id(P) [*] id(P) id(I) c(1) | |-----| | |
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.

{[ snackBarMessage ]}