Presentation is loading. Please wait.

Presentation is loading. Please wait.

CO4301 – Advanced Games Development Week 3 Parsing Continued

Similar presentations


Presentation on theme: "CO4301 – Advanced Games Development Week 3 Parsing Continued"— Presentation transcript:

1 CO4301 – Advanced Games Development Week 3 Parsing Continued
Gareth Bellaby

2 Parsing an arithmetic operation
- Infix

3 Parsing infix notation
Operator inbetween the operands. Examples: 8 = 4 * 2 7 * 3 + 5 2+ 4 – 3 * 8

4 Tree walking Operator inbetween the operands. Examples: 8 = 4 * 2
7 * 3 + 5 2+ 4 – 3 * 8

5 Approach Tokeniser Parser Opertions.
If a parser for a programming language then this step would be code generation Function calls, e.g. for a behaviour tree Evaluation, for arithmetic parser

6 Approach Remember how easy it was to parse a postfix expression.
Can use a stack to translate an expression which uses infix notation, into one which uses postfix notation. Some different ways to express but in its essentials the following algorithm is used:

7 Algorithm Tokenised list dealt with from left to right.
If the token is an operand, push it onto the end of the output list. If the token is a left parenthesis, push it on the stack. If the token is a right parenthesis, pop the stack until the corresponding left parenthesis is removed. Push each operator onto the end of the output list. If the token is an operator and if equal or lower precedence than operators on the stack, pop and push them onto the output list. Push the operator onto the stack At the end of the express pop any operators still on the stack and push them onto the end of the output list.

8 Algorithm This is version of the “shunting yard algorithm”.
You can easily find a version of this, e.g. on Wikipedia.

9 Parser use Compiler. Recursive descent parser.
Checks grammar as well as evaluating. “descent” – depth first search. “recursive”- written as a collection of recursive procedures. Natural language parser.

10 Characteristics Tree structure Breaks expressions down into sub-trees
In effect, each sub-tree is a basic statement in the grammar, e.g. basic infix arithmetic operation, or the operational unit of a behaviour tree. Each leaf is the atomic element of the grammar.

11 Characteristics Arithmetic parser is a good example of a data structure as the engine of the algorithm. What other examples of this do you know?.

12 Trees – an overview Trees are a data structure. However, you may not see the tree being explicitly created. Build tree. Explicit. Nodes and arcs. Build tree. Implicit. For example, list. Only building the relevant part of the tree. Can prune a tree. May be possible to rewrite the tree generation algorithm so that it is pruned automatically.

13 Questions Give me an example of: Explicitly building a tree.
Implicitly building a tree. Only building the part of the tree you’re interested in. Note, an example might come cover more than one case.

14 Discusssion Why the different approach?
Evaluate the different approaches and place into context. Bring into the discussion what you’re already done on the degree (and any other algorithms you may have come across).


Download ppt "CO4301 – Advanced Games Development Week 3 Parsing Continued"

Similar presentations


Ads by Google