Page 3 2. (a) Carol is writing a compiler for a new language. She writes the source code for the compiler in Java and co
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Page 3 2. (a) Carol is writing a compiler for a new language. She writes the source code for the compiler in Java and co
Page 3 2. (a) Carol is writing a compiler for a new language. She writes the source code for the compiler in Java and compiles it with javac. Unfortunately, when she tests the compiler, she finds that her hand- written parser has many bugs. Rather than attempting to correct her hand-written parser, she decides to use a parser generator instead. Outline the steps she might take to achieve this, making clear how using a parser generator changes the build process for the compiler. (4 marks) (b) Consider the following excerpt from a grammar for a Java-like programming language in Backus-Naur form, as accepted by ANTLR and other parser generators: statement : 'if (expression ')' statement 'else' statement # StmtIf | identifier '='expression ';' # StmtAssign expression : 'true' # ExpConstTrue | 'false' # ExpConstFalse identifier: 'x' Ily' The grammar also contains a rule to ignore whitespace (not shown). (i) Give a brief definition of each of the following components of a grammar: terminal nonterminal alternation For each component, give an example of where it occurs in the grammar above. (6 marks)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!