LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in...

26
LEX AND YACC TOOLS INSTALLATION Compiling and Running Lex Program. Prepared by: Ms. Meerah Alhaqbani Ms. Awabed Aljibreen 1

Transcript of LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in...

Page 1: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

LEX AND YACC TOOLS INSTALLATIONCompiling and Running Lex Program.

Prepared by:

Ms. Meerah Alhaqbani

Ms. Awabed Aljibreen

1

Page 2: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

• Setting up the tools:

• On Mac.

• On Windows.

• Compiling and running Lex program.

Outline

2

Page 3: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

Setting up the Tools On Mac

• If you are on Mac:

• you only have to Install Xcode.

• You can jump to slide #22

3

Page 4: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

Setting up the Tools on Windows

• If you are on Mac or Linux, you don’t need to do the steps below.

• If you are on Windows, you need to create Linux environment by

following the steps below:

1. Download Ubuntu from

http://www.ubuntu.com/download/desktop

2. Download virtual box from

https://www.virtualbox.org/wiki/Downloads

If Virtualization Technology (intel VT) is disabled in your

system, you should enable it through BIOS settings.

3. Set up Lex and Yacc tools via terminal commands.

4

Page 5: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

5

Page 6: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

6

Page 7: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

7

Page 8: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

2. Downloading VirtualBox

8

Page 9: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

9

Page 10: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

10

Page 11: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

11

Page 12: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

12

Page 13: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

13

Page 14: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

14

Page 15: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

15

Page 16: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

16

Page 17: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

17

Page 18: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

18

Page 19: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

3. Setting up Lex and Yacc Tools via Terminal Commands.

19

Page 20: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

■ Connect your Ubuntu to the Internet then open terminal (Ctrl+Alt+t)

■ Type the following command: sudoapt-get update

■ Type the password for your Linux Account and press Enter, if ask for your password.

■ Type “y” and press Enter, ifask for your permissions to update.

3. Setting up Lex and Yacc Tools via Terminal Commands.

20

Page 21: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

• To install Lex tool, type the following command in terminal :

sudo apt-get install flex

• Type “y” and press Enter, if ask for confirmation.

• To install Yacc tool, type the following command in terminal :

sudo apt-get install bison

• If the servers of bison are down and give errors, you can use any

of the following alternatives commands:

• sudo apt-get install byacc

• sudo apt-get install bison++

• sudo apt-get install byacc-j

3. Setting up Lex and Ycc Tools via Terminal Commands.

21

Page 22: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

■ Right-click on the desktop and open a new document.

■ Rename the file with ( test.l ), the file extension is small L.

■ Write the code shown in the next slide.

Compiling and Running Lex File

22

Page 23: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

Compiling and Running Lex File

23

Page 24: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

Lex Example

Open the terminal and use CD command to change the current directory of the terminal

Cd /home/YourMachineName/Desktop

Use lex command as following to run the tool:

Compiling and Running Lex File

24

Page 25: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

Lex Example

Compile the generated file (lex.yy.c) usimng the compilation command as shown below:

Run the generated file (a.out) using the Run command as shown below :

Compiling and Running Lex File

25

Page 26: LEX AND YACC TOOLS INSTALLATION - KSU · • To install Yacc tool, type the following command in terminal : sudo apt-get install bison • If the servers of bison are down and give

Lex Example

• Enter different inputs and explore the given outputs.

Running the Output File

26