cse 2231 - bugsworld introductionweb.cse.ohio-state.edu/.../slides/20.bugsworld-intro.pdf ·...

17
BugsWorld Introduction 27 February 2019 OSU CSE 1

Upload: others

Post on 30-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf · 2019-02-27 · of “the world”, processes client requests, resolves conflicts. The

BugsWorld Introduction

27 February 2019 OSU CSE 1

Page 2: CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf · 2019-02-27 · of “the world”, processes client requests, resolves conflicts. The

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

Page 3: CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf · 2019-02-27 · of “the world”, processes client requests, resolves conflicts. The

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

27 February 2019 OSU CSE 3

Page 4: CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf · 2019-02-27 · of “the world”, processes client requests, resolves conflicts. The

The Simulator

• The BugsWorld game is played on a system consisting of:– Server– Clients– Displays

27 February 2019 OSU CSE 4

Page 5: CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf · 2019-02-27 · of “the world”, processes client requests, resolves conflicts. The

The Simulator

• The BugsWorld game is played on a system consisting of:– Server

27 February 2019 OSU CSE 5

The server keeps track of “the world”,

processes client requests, resolves

conflicts.

Page 6: CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf · 2019-02-27 · of “the world”, processes client requests, resolves conflicts. The

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.

Page 7: CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf · 2019-02-27 · of “the world”, processes client requests, resolves conflicts. The

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.

Page 8: CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf · 2019-02-27 · of “the world”, processes client requests, resolves conflicts. The

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 on a different computer (distributed simulation).

Page 9: CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf · 2019-02-27 · of “the world”, processes client requests, resolves conflicts. The

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

Page 10: CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf · 2019-02-27 · of “the world”, processes client requests, resolves conflicts. The

BL Program ExamplePROGRAM TryToGuess IS

INSTRUCTION FindObstacle ISWHILE next-is-empty DO

moveEND WHILE

END FindObstacle

...

27 February 2019 OSU CSE 10

Page 11: CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf · 2019-02-27 · of “the world”, processes client requests, resolves conflicts. The

BL Program ExamplePROGRAM TryToGuess IS

INSTRUCTION FindObstacle ISWHILE next-is-empty DO

moveEND WHILE

END FindObstacle

...

27 February 2019 OSU CSE 11

See next slide...

Page 12: CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf · 2019-02-27 · of “the world”, processes client requests, resolves conflicts. The

BL Program Example (Cont’d)BEGIN

WHILE true DOFindObstacleIF next-is-enemy THEN

infectELSE

IF next-is-wall THENturnleft

ELSEskip

END IFEND IF

END WHILEEND TryToGuess

27 February 2019 OSU CSE 12

Page 13: CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf · 2019-02-27 · of “the world”, processes client requests, resolves conflicts. The

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

Page 14: CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf · 2019-02-27 · of “the world”, processes client requests, resolves conflicts. The

The CompilerPROGRAM TryToGuess IS

INSTRUCTION FindObstacle ISWHILE next-is-empty DO

moveEND WHILE

END FindObstacleBEGIN

WHILE true DOFindObstacleIF next-is-enemy THEN

infectELSE

IF next-is-wall THENturnleft

ELSEskip

END IFEND IF

END WHILEEND 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>

Page 15: CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf · 2019-02-27 · of “the world”, processes client requests, resolves conflicts. The

The CompilerPROGRAM TryToGuess IS

INSTRUCTION FindObstacle ISWHILE next-is-empty DO

moveEND WHILE

END FindObstacleBEGIN

WHILE true DOFindObstacleIF next-is-enemy THEN

infectELSE

IF next-is-wall THENturnleft

ELSEskip

END IFEND IF

END WHILEEND 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

on the left.

Page 16: CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf · 2019-02-27 · of “the world”, processes client requests, resolves conflicts. The

Compiler Structure

27 February 2019 OSU CSE 16

CodeGeneratorParserTokenizer

string ofcharacters

(source code)

string oftokens

(“words”)

abstractprogram

string ofintegers

(object code)

Page 17: CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf · 2019-02-27 · of “the world”, processes client requests, resolves conflicts. The

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