Docsity

CS426 Compiler Assignment: Creating Lexical Scanner & Java VM Code, Assignments of Computer Science

Toggle sidebar
bg1
CS426 Compiler Construction
Fall 2006
Machine Problem 1
Due Thursday September 14 at 12pm (midnight)
This assignment has two parts. One involves the creation of a lexical scanner and the second learning
how to assemble code for the Java Virtual Machine.
1. For the first part of the assignment you should download a lexical scanner generator such as JLex
(http://www.cs.princeton.edu/~appel/modern/java/JLex/) or JFlex (http://jflex.de/) (both of them
generate java programs) or any other scanner generator of your choice (e.g. Flex
[http://www.cs.princeton.edu/~appel/modern/c/software/flex/] or Lex which generate C pro-
grams). Then, you should generate a scanner for a subset of C which includes
• for, while, if and assignment statements
• Integer and floating point variables and values
•arrays
• functions and function calls.
Write a driver that prints the pair <token type, lexeme> for each token in the input file.
2. The second part you should download the jasmin assembler (http://jasmin.sourceforge.net/) and
write and succesfully execute a JVM program in the assembly language accepted by jasmin that reads
an integer, n, and computes the nth fibonacci number
(http://en.wikipedia.org/wiki/Fibonacci_sequence). For this part of the assignment you will need to
learn about the Java Virtual Machine. You can find information in the following web sites:
• http://en.wikipedia.org/wiki/Java_bytecode
• .class file format:
http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html
• More detailed opcode descriptions
http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions2.doc.html
• JVM overview
http://java.sun.com/docs/books/vmspec/2nd-edition/html/Overview.doc.html
To hand in the MP, please send me a tar file containing
• the input to the scanner generator
• the program produced by the scanner generator
3. The Jasmin assembly language that computes the nth fibonacci number.

Partial preview of the text

Download CS426 Compiler Assignment: Creating Lexical Scanner & Java VM Code and more Assignments Computer Science in PDF only on Docsity!

CS426 Compiler Construction

Fall 2006

Machine Problem 1

Due Thursday September 14 at 12pm (midnight)

This assignment has two parts. One involves the creation of a lexical scanner and the second learning how to assemble code for the Java Virtual Machine.

  1. For the first part of the assignment you should download a lexical scanner generator such as JLex ( http://www.cs.princeton.edu/~appel/modern/java/JLex/ ) or JFlex ( http://jflex.de/ ) (both of them generate java programs) or any other scanner generator of your choice (e.g. Flex [ http://www.cs.princeton.edu/~appel/modern/c/software/flex/ ] or Lex which generate C pro- grams). Then, you should generate a scanner for a subset of C which includes - for, while, if and assignment statements - Integer and floating point variables and values - arrays - functions and function calls. Write a driver that prints the pair <token type, lexeme> for each token in the input file.
  2. The second part you should download the jasmin assembler ( http://jasmin.sourceforge.net/ ) and write and succesfully execute a JVM program in the assembly language accepted by jasmin that reads an integer, n , and computes the n th fibonacci number ( http://en.wikipedia.org/wiki/Fibonacci_sequence ). For this part of the assignment you will need to learn about the Java Virtual Machine. You can find information in the following web sites: - http://en.wikipedia.org/wiki/Java_bytecode - .class file format: http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html - More detailed opcode descriptions http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions2.doc.html - JVM overview http://java.sun.com/docs/books/vmspec/2nd-edition/html/Overview.doc.html

To hand in the MP, please send me a tar file containing

  • the input to the scanner generator
  • the program produced by the scanner generator
  1. The Jasmin assembly language that computes the nth fibonacci number.