(11) Using the grammar, draw a parse tree for the following statement: if (true) x= false else y = false (6 marks) (c) Consider the following claim: "A human will always be able to optimise code at least as well as a compiler. For example: (add 5 (subtract 3 1) would become add (5,subtract (3,1)). 1) 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. The compiler’s goal is to take Lisp-style functions and convert them to equivalent C-style function calls. Addison-Wesley Modern Compiler Implementation in Java (Second Edition) Andrew Appel and Jens Palsberg. (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' I'Y' The grammar also contains a rule to ignore whitespace (not shown). There are a number of good textbooks on compilers here are three in particular: Compilers: Principles, Techniques, and Tools (Second Edition) Alfred Aho, Monica Lam, Ravi Sethi, and Jeffrey Ullman. Use some metaprogramming tricks to compile an app once that runs different code as you feed it, basically interpreter with the optimised code installed. Compile it to another language like C/C++ and then compile it separately. It would have saved us tons of time, allowing us to work on our compiler, instead of debugging all those cannot move out of borrowed content errors. Halfway through our project we found out that we should not have used Rust. Outline the steps she might take to achieve this, making clear how using a parser generator changes the build process for the compiler. Writing A Compiler In Go is the sequel to Writing An Interpreter In Go. Compile down to Assembly and then assemble it. Building a compiler for the first time is not easy. Rather than attempting to correct her hand-written parser, she decides to use a parser generator instead. Unfortunately, when she tests the compiler, she finds that her handwritten parser has many bugs. She writes the source code for the compiler in Java and compiles it with javac. (a) Carol is writing a compiler for a new language.
0 Comments
Leave a Reply. |