BugsWorld Introduction 27 February 2019 OSU CSE 1 BugsWorld You - - PowerPoint PPT Presentation

bugsworld introduction
SMART_READER_LITE
LIVE PREVIEW

BugsWorld Introduction 27 February 2019 OSU CSE 1 BugsWorld You - - PowerPoint PPT Presentation

BugsWorld Introduction 27 February 2019 OSU CSE 1 BugsWorld You will be working on projects related to various aspects of a game called BugsWorld : The Game The Simulator The Language The Compiler 27 February 2019 OSU


slide-1
SLIDE 1

BugsWorld Introduction

27 February 2019 OSU CSE 1

slide-2
SLIDE 2

BugsWorld

  • You will be working on projects related to

various aspects of a game called BugsWorld:

– The Game – The Simulator – The Language – The Compiler

27 February 2019 OSU CSE 2

slide-3
SLIDE 3

The Game: It’s a Bug’s World!

27 February 2019 OSU CSE 3

slide-4
SLIDE 4

The Simulator

  • The BugsWorld game is played on a

system consisting of:

– Server – Clients – Displays

27 February 2019 OSU CSE 4

slide-5
SLIDE 5

The Simulator

  • The BugsWorld game is played on a

system consisting of:

– Server

27 February 2019 OSU CSE 5

The server keeps track

  • f “the world”,

processes client requests, resolves conflicts.

slide-6
SLIDE 6

The Simulator

  • The BugsWorld game is played on a

system consisting of:

– Server – Clients

27 February 2019 OSU CSE 6

Each client program simulates creature (bug) behavior for all creatures of one species.

slide-7
SLIDE 7

The Simulator

  • The BugsWorld game is played on a

system consisting of:

– Server – Clients – Displays

27 February 2019 OSU CSE 7

Each display shows the current state of the world, plus some statistics about the simulation.

slide-8
SLIDE 8

The Simulator

  • The BugsWorld game is played on a

system consisting of:

– Server – Clients – Displays

27 February 2019 OSU CSE 8

Each process can run

  • n a different computer

(distributed simulation).

slide-9
SLIDE 9

The Language

  • The behavior of each species is determined by a

program in the language BL

  • Primitive instructions: move, turnleft, turnright,

infect, skip

  • Control structures: IF-THEN, IF-THEN-ELSE,

WHILE-DO

  • Defining new instructions: INSTRUCTION-IS
  • Conditions: test whether “next” cell is empty,

friend, enemy, or wall (plus true and random)

27 February 2019 OSU CSE 9

slide-10
SLIDE 10

BL Program Example

PROGRAM TryToGuess IS INSTRUCTION FindObstacle IS WHILE next-is-empty DO move END WHILE END FindObstacle ...

27 February 2019 OSU CSE 10

slide-11
SLIDE 11

BL Program Example

PROGRAM TryToGuess IS INSTRUCTION FindObstacle IS WHILE next-is-empty DO move END WHILE END FindObstacle ...

27 February 2019 OSU CSE 11

See next slide...

slide-12
SLIDE 12

BL Program Example (Cont’d)

BEGIN WHILE true DO FindObstacle IF next-is-enemy THEN infect ELSE IF next-is-wall THEN turnleft ELSE skip END IF END IF END WHILE END TryToGuess

27 February 2019 OSU CSE 12

slide-13
SLIDE 13

BL Features

  • Precise syntax
  • Case sensitive
  • Matching ENDs
  • Identifiers:

– Start with any of 'a'..'z', 'A'..'Z' – Followed by any of 'a'..'z', 'A'..'Z', '0'..'9', '-'

27 February 2019 OSU CSE 13

slide-14
SLIDE 14

The Compiler

PROGRAM TryToGuess IS INSTRUCTION FindObstacle IS WHILE next-is-empty DO move END WHILE END FindObstacle BEGIN WHILE true DO FindObstacle IF next-is-enemy THEN infect ELSE IF next-is-wall THEN turnleft ELSE skip END IF END IF END WHILE END TryToGuess

27 February 2019 OSU CSE 14

<20, 15, 20, 6, 7, 0, 5, 2, 12, 12, 3, 5, 18, 8, 17, 1, 5, 18, 4, 5, 0>

slide-15
SLIDE 15

The Compiler

PROGRAM TryToGuess IS INSTRUCTION FindObstacle IS WHILE next-is-empty DO move END WHILE END FindObstacle BEGIN WHILE true DO FindObstacle IF next-is-enemy THEN infect ELSE IF next-is-wall THEN turnleft ELSE skip END IF END IF END WHILE END TryToGuess

27 February 2019 OSU CSE 15

<20, 15, 20, 6, 7, 0, 5, 2, 12, 12, 3, 5, 18, 8, 17, 1, 5, 18, 4, 5, 0> This string of integers is the object code for the BL program source code shown

  • n the left.
slide-16
SLIDE 16

Compiler Structure

27 February 2019 OSU CSE 16

Code Generator Parser Tokenizer string of characters (source code) string of tokens (“words”) abstract program string of integers (object code)

slide-17
SLIDE 17

What You Will Do

  • You will implement at least major parts of

all three pieces of the BL compiler:

– Tokenizer – Parser – Code Generator

27 February 2019 OSU CSE 17