CS405 Assignment 2: Creating a Recursive-Descent Syntax Analyzer for Matrix Language, Assignments of Programming Languages

Assignment 2 for cs405, where students are required to design and implement a recursive-descent syntax analyzer for the matrix language. The parser should conform to the ebnf grammar, interact with the lexical analyzer, handle syntax errors, and produce a syntax-tree representation of the input program in cambridge polish prefix notation. Students are suggested to build the parser without syntax-tree construction first.

Typology: Assignments

Pre 2010

Uploaded on 04/12/2010

koofers-user-ef6
koofers-user-ef6 🇺🇸

5

(1)

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS405 Assignment 2
Due Oct 7, 2004
Design and implement a recursive-descent syntax analyzer for matrix language as is
specified in Assignment 1, which will parse programs according to the prescribed
grammar and produce a syntax-tree representation of the input program. This process has
the following steps:
1. The layout of the parser should conform to the EBNF grammar of the matrix language
given in the previous assignment.
2. The parser should interact with the lexical analyzer to retrieve tokens as it needs them.
3. The parser may terminate execution if a syntax error is detected, printing a suitable
error message.
4. If the source program has no syntax errors, the result of the parse should be a source
program listing (e.g. this can be printed by the lexical analyzer as the program is read)
and a syntax tree representation of the major program units, e.g. each main program and
method will have a syntax tree. For convenience this syntax tree may be output at the
point at which it is generated, i.e. interleaved with the source program listing. Print the
tree in Cambridge Polish prefix notation. e.g., (1+3)*2 in Cambridge Polish prefix
notation will be (* (+ 1 3) 2) .
Suggestion: First construct the recursive-descent parser without syntax-tree construction
and once this is working add the syntax tree construction.

Partial preview of the text

Download CS405 Assignment 2: Creating a Recursive-Descent Syntax Analyzer for Matrix Language and more Assignments Programming Languages in PDF only on Docsity!

CS405 Assignment 2 Due Oct 7, 2004 Design and implement a recursive-descent syntax analyzer for matrix language as is specified in Assignment 1, which will parse programs according to the prescribed grammar and produce a syntax-tree representation of the input program. This process has the following steps:

  1. The layout of the parser should conform to the EBNF grammar of the matrix language given in the previous assignment.
  2. The parser should interact with the lexical analyzer to retrieve tokens as it needs them.
  3. The parser may terminate execution if a syntax error is detected, printing a suitable error message.
  4. If the source program has no syntax errors, the result of the parse should be a source program listing (e.g. this can be printed by the lexical analyzer as the program is read) and a syntax tree representation of the major program units, e.g. each main program and method will have a syntax tree. For convenience this syntax tree may be output at the point at which it is generated, i.e. interleaved with the source program listing. Print the tree in Cambridge Polish prefix notation. e.g., (1+3)2 in Cambridge Polish prefix notation will be ( (+ 1 3) 2). Suggestion: First construct the recursive-descent parser without syntax-tree construction and once this is working add the syntax tree construction.