Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

20

Click here to load reader

Transcript of Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

Page 1: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

Parser-DrivenGames Tool programming

© Allan C. Milne

Abertay University

v12.7.11

Page 2: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

Agenda.

• Motivation and Course Overview.• Translator Process Overview.

• Applications.• Some Terminology.

Page 3: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

Motivation.

• Games are complicated compositions of many components and often a tool may assist either the development or implementation process.

• Tools may be useful in the areas of

– management, assisting the project development process by providing support functions against the code base;

– development, generating parts of the code base.

– implementation, being an integral part of the code base.

Page 4: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

Motivation Continued.

• The tools you develop will often be analysing, processing or be under the control of a program/script written in some language.

• Therefore the tool is in some sense “driven” by the structure of the program; this structure being elucidated by a parser; hence the term parser-driven tools.

Page 5: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

The Aim Of This Course Is To Provide You With …

… an overview of analysis and synthesis phases of the compilation process;

… an appreciation of appropriate parser-based tools for use within computer games software development projects;

… an introduction to the skills, terminology and techniques used to develop such tools.

Page 6: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

The Development Environment.

• We will be using Flex and Bison;– These are versions of the Lex and Yacc

language processing packages respectively.

• These will be working in the C language.• We will be working in a command-line

environment;– Programs > Visual Studio > Visual Studio

Tools > Visual Studio Command Prompt

Page 7: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

On Completion You Should Be Able To …

… explain the terms and terminology used to describe the construction and operation of compilers

… construct simple software translators

… identify opportunities for parser based tools within a development project

… specify and develop parser based tools

Page 8: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

Translator Overview.

• A translator (or compiler) will process input text by treating it syntactically as a sentence from some language.

• It must also include semantic knowledge of the language in its processing.

• In processing the sentence a compiler must– Determine its syntactic structure,– check the semantic consistency, and– interpret or generate corresponding artifacts.

Page 9: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

Translator Input.

• The primary input to a translator is the input text (source program).

• Formally this input text is a sentence from some language.

• The translator inputs the program as a stream of individual characters.

• Other user inputs may control the operation of the translator.

Page 10: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

Translator Output.

• Intermediate or machine code.• A program in some other language.• An analytical report on the input text.• A data structure representing the input.• Direct actions.• … or some other artifact.

Page 11: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

Translator Processing Phases.

Input text LexicalAnalysis

SyntaxAnalysis

SemanticAnalysis

SynthesisGenerated

artifact

Page 12: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

Component Interactions.

characterstream

LexicalAnalysis

SyntaxAnalysis

SemanticAnalysis

Synthesis

Artifact(instruction

stream)

terminal tokens

syntax tree

symbol table

Page 13: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

Error Handling.

• The translator must handle syntactic and semantic errors.

• Error detection: find invalid syntactic structures or misuse of semantics.

• Error reporting: report to the user the type, position and cause of the error.

• Error recovery: allow the translation process to continue after an error.

Page 14: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

Application Areas.

• Management.– providing support functions against the

code base;

• Development.– generating parts of the code base.

• Implementation.– being an integral part of the code base.

Page 15: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

Examples of Management Tools.

• Reporting code metrics.• Code transformations.• Integration of different code components.• Test data generation.• Identifying and controlling versioning.

Page 16: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

Examples of Development Tools.

• Particle generators.• Generating graphics rendering pipelines.• Managing audio resources.• Generating graphics data files.• Scripting generic game engines.

Page 17: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

Examples of Implementation Tools.

• Processing user conversations.• Dynamic scripting.• Configuration and property management.• Handling message protocols.• Game state storage and retrieval.

Page 18: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

Some Translator Terminology.

• Translator;– Transforms structured input text into some

corresponding output artifact.

• Compiler;– Transforms an input source program into

object code for a real or virtual machine.

• Interpreter;– Transforms input source program into directly

executed actions.

Page 19: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

Some Compiler Terminology.

• Source program = input text.• Object code = 1 type of generated artifact.• Scanner = lexical analyser = lexer.• Parser = syntax analyser = recogniser.

Page 20: Parser-Driven Games Tool programming © Allan C. Milne Abertay University v12.7.11.

The Language.

• The tools we are looking at all require some input text that is a sentence (program) in some language.

• This language has both a syntax (structure) and semantics (context-sensitive meaning).

• The syntax of the language defines the structure of all possible programs that can be written in that language.