Note that this syntax contains terminal symbols and

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Note that this syntax contains terminal symbols { and } which are different from the extended BNF meta-symbols { and } , and distinguished by underlining. Write an equivalent syntax graph and a recursive descent parser for this construction. Assume the existence of production rules for function-definition and corresponding parsing procedure FUNCTION DEFINITION , and a scanning procedure GET TOKEN to set a global string variable TOKEN to the token type of the next token. Furthermore, assume that TOKEN is already set to the first token when parsing begins. The syntax graph is shown in .
Image of page 1

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

View Full Document Right Arrow Icon
The recursive descent parser is: procedure CLASS_SPECIFIER; begin if TOKEN != CLASS then ERROR; GET_TOKEN; if TOKEN != IDENTIFIER then ERROR; GET_TOKEN; if TOKEN = COLON then begin GET_TOKEN; if TOKEN != IDENTIFIER then ERROR; GET_TOKEN; end; if TOKEN != LEFT_BRACE then ERROR; GET_TOKEN; repeat MEMBER_DECLARATION; until TOKEN = RIGHT_BRACE; GET_TOKEN; end; procedure MEMBER_DECLARATION; begin if TOKEN = IDENTIFIER then GET_TOKEN; else if TOKEN = INT then GET_TOKEN; else ERROR; if TOKEN != IDENTIFIER then ERROR; GET_TOKEN; FUNCTION_DEFINITION; end;
Image of page 2
5. Consider the attribute grammar below: < string > ::= < a-n > < b-n > < c-n > < b-n
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern