CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf ·...
Transcript of CSE 2231 - BugsWorld Introductionweb.cse.ohio-state.edu/.../slides/20.BugsWorld-Intro.pdf ·...
![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](https://reader034.fdocuments.in/reader034/viewer/2022050401/5f7f53ffc4c428061b6d27d6/html5/thumbnails/1.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022050401/5f7f53ffc4c428061b6d27d6/html5/thumbnails/2.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022050401/5f7f53ffc4c428061b6d27d6/html5/thumbnails/3.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022050401/5f7f53ffc4c428061b6d27d6/html5/thumbnails/4.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022050401/5f7f53ffc4c428061b6d27d6/html5/thumbnails/5.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022050401/5f7f53ffc4c428061b6d27d6/html5/thumbnails/6.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022050401/5f7f53ffc4c428061b6d27d6/html5/thumbnails/7.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022050401/5f7f53ffc4c428061b6d27d6/html5/thumbnails/8.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022050401/5f7f53ffc4c428061b6d27d6/html5/thumbnails/9.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022050401/5f7f53ffc4c428061b6d27d6/html5/thumbnails/10.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022050401/5f7f53ffc4c428061b6d27d6/html5/thumbnails/11.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022050401/5f7f53ffc4c428061b6d27d6/html5/thumbnails/12.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022050401/5f7f53ffc4c428061b6d27d6/html5/thumbnails/13.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022050401/5f7f53ffc4c428061b6d27d6/html5/thumbnails/14.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022050401/5f7f53ffc4c428061b6d27d6/html5/thumbnails/15.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022050401/5f7f53ffc4c428061b6d27d6/html5/thumbnails/16.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022050401/5f7f53ffc4c428061b6d27d6/html5/thumbnails/17.jpg)
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