OBJECTIVE The objectives of Lab 1 are (1) to play with the Ocamllex/Ocamlyacc & ECLIPSE IDE tool; (2) to construct a simple lexer with few regular expressions (REs) using Ocamllex/Ocamlyacc. 2. INTRODUCTION Ocamllex/Ocamlyacc is a powerful tool for those who want to develop a language compiler quickly and stably. To download and get more information about Ocamllex/Ocamlyacc, visit ECLIPSE is a multi-language software development environment comprising an IDE and a plug-in system to extend it. It is written primarily in Java and can be used to develop applications in Java and, by means of the various plug-ins, in other languages as well, including C, C++, COBOL, Python, Perl, PHP, and others. The initial codebase originated from VisualAge. In its default form it is meant for Java developers, consisting of the Java Development Tools (JDT). Users can extend its capabilities by installing plug-ins written for the Eclipse software framework, such as development toolkits for other programming languages, and can write and contribute their own plug-in modules. ( 3. LAB CONTENTS 3.1. Install Ocamlex/Ocamlyacc Ocamllex/Ocamlyacc requires: − Cywin, a Linux-like enviroment for Windows. − Ocaml, a programming language • Get and install Cywin at Note: You do not need to install any packages in cygwin when prompted. Or, you can choose Ocaml in cygwin packages and you don't have to do the next step. Remember to choose version 3.12.x • Get and install Ocaml at, choose the Windows version for the port based on the MinGW toolchain 3.2. Edit Ocamlex/Ocamlyacc in Eclipse OcaIDE, the Eclipse plug-in for Ocamllex/Ocamlyacc, requires: − Java 5.0+ − Eclipse 3.3/3.4/3.5

Get and install Java SE Development Kit (JDK) 6.0 at

Get Eclipse IDE 3.5.2 (Galileo Packages) at

Install OcaIDE

Open Eclipse, click on Help > Install New Software...

Enter as the update site.

Check the OcaIDE category or feature in the list.

Then, click Next twice, accept the agreement and click Finish.

Accept the installation (the plug-in is not digitally signed), and restart Eclipse when it asks you to. As soon as Eclipse is restarted, you can start using the plug-in. You can find more information about OcaIDE installation at Open Eclipse and choose the Eclipse workspace for the first run

Change the current perspective into Ocaml (Window -> Open Perspective -> Other, choose Ocaml)

Create a new Ocaml project

Make a new lexical file to edit.

Note: If you receive the error warning that you haven't downloaded cygwin and set the environment variables, that means you have to do the latter one. To do that, consult these webpage: • How to define an environment variable Environment variables of Cygwin

3.3. Ocamlex/Ocamlyacc tutorial Open a command window (Start -> Run -> Enter “cmd”), then change the current directory to Example1. Run lexgen.bat to generate a lexical analyzer from REs in file lex.mll. Note: File lex.mll contains REs to recognise patterns of numerical expressions. Run compile.bat to make a driver to test the lexical analyzer. Run run.bat to execute the driver with input from file test1.txt.

Using notepad or something, open file text1.txt and compare with the results on the screen. 4. CLASS EXERCISES 4.1 Open text2.txt and point out the difference between two files. Now insert this line into lex.mll, after line 8 | ['+' '-'] as x { ADD x}

Run lexgen.bat, compile.bat then driver test2.txt Write the results! 4.2 Now insert this line into lex.mll, after recent added line | ('*' | '/') as y { MUL y}

Run lexgen.bat, compile.bat then driver test3.txt Look at the result, what do you think about square brackets (“[]”) and parentheses (“(|)”)?