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 CSE 2
The Game: It’s a Bug’s World! 27 February 2019 OSU CSE 3
The Simulator • The BugsWorld game is played on a system consisting of: – Server – Clients – Displays 27 February 2019 OSU CSE 4
The Simulator • The BugsWorld game is played on a system consisting of: – Server The server keeps track of “the world”, processes client requests, resolves conflicts. 27 February 2019 OSU CSE 5
The Simulator • The BugsWorld game is played on a system consisting of: – Server – Clients Each client program simulates creature (bug) behavior for all creatures of one species. 27 February 2019 OSU CSE 6
The Simulator • The BugsWorld game is played on a system consisting of: – Server – Clients – Displays Each display shows the current state of the world, plus some statistics about the simulation. 27 February 2019 OSU CSE 7
Each process can run The Simulator on a different computer (distributed simulation). • The BugsWorld game is played on a system consisting of: – Server – Clients – Displays 27 February 2019 OSU CSE 8
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
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
BL Program Example PROGRAM TryToGuess IS INSTRUCTION FindObstacle IS WHILE next-is-empty DO move END WHILE END FindObstacle See next slide... ... 27 February 2019 OSU CSE 11
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
BL Features • Precise syntax • Case sensitive • Matching END s • 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
The Compiler PROGRAM TryToGuess IS INSTRUCTION FindObstacle IS WHILE next-is-empty DO move END WHILE END FindObstacle BEGIN <20, 15, 20, 6, 7, 0, WHILE true DO FindObstacle 5, 2, 12, 12, 3, 5, IF next-is-enemy THEN 18, 8, 17, 1, 5, 18, infect ELSE 4, 5, 0> IF next-is-wall THEN turnleft ELSE skip END IF END IF END WHILE END TryToGuess 27 February 2019 OSU CSE 14
The Compiler This string of integers is the object code for PROGRAM TryToGuess IS the BL program INSTRUCTION FindObstacle IS source code shown WHILE next-is-empty DO move on the left. END WHILE END FindObstacle BEGIN <20, 15, 20, 6, 7, 0, WHILE true DO FindObstacle 5, 2, 12, 12, 3, 5, IF next-is-enemy THEN 18, 8, 17, 1, 5, 18, infect ELSE 4, 5, 0> IF next-is-wall THEN turnleft ELSE skip END IF END IF END WHILE END TryToGuess 27 February 2019 OSU CSE 15
Compiler Structure Code Tokenizer Parser Generator string of string of abstract string of characters tokens program integers (source code) (“words”) (object code) 27 February 2019 OSU CSE 16
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
Recommend
More recommend