Parsing Flashcards

1
Q

What is parsing?

A

The task of converting a program or other complex text into a parse tree

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do we write code that can convert a grammar into a parser?

A
  • Identify the terminals of the grammar (the concrete syntax of the language)
  • Ensure that the resulting string of terminals is induced by the grammar (could have been generated)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the two approaches to implementation?

A

Recursive descent

Table driven

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe the pipeline from source text to a parse tree

A

Source text
Tokeniser
Parser
Parse tree

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is tokenisation?

A

The process that turns a sequence of characters into a symbol

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are some advantages of describing the tokens using a FSA?

A

Small, tight, fast, low memory footprint

Only looking for simple things, so no back-tracking or other complicated operations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe the approach of tokenisation using a FSA

A

Tokenise the input source, generating a stream of tokens for the grammar
Some tokens carry values with them
FSA keeps track of the characters it uses
Attaches them to the recognised symbol

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe recursive descent parsing

A

Treat each production as a small recogniser that looks at the token stream and tries to recognise itself
‘Try and see’ method (back up the token stream)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Benefits of recursive descent parsing

A

Works with pretty much any grammar

Simple

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Disadvantages of recursive descent parsing

A

Deep stack of recursive calls
Slow
Potentially a lot of back tracking

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Describe table driven parsing

A

Start with the tokens
See which productions could have given rise to them
Build the tree as a constraints problem

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Advantages of table driven parsing

A

Smaller and faster than recursive descent
Little more sensitive to features of the
grammar
No need for back tracking

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Disadvantages of table driven parsing

A

Less clear

Can be tripped up by ambiguous grammars

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the two approaches to tokenisation?

A

Sub grammars

Finite state automata

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Advantages of using sub grammars for tokenisation

A

Just one thing to remember
Simply structure
Designed for pattern recognition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Advantages of using FSA for tokenisation

A

Graphical, fast, and simple

Designed for simple patterns

17
Q

One important thing to remember about parsers

A

Parsers are a tool, nothing more and they often need to be tied together with other aspects

18
Q

Describe the ways to fix the dangling if problem

A
  • make whitespace significant
  • force else’s to every if statement
  • force a block structure
19
Q

What does a production in a grammar become in a parser?

A

A function

20
Q

What is the responsibility of terminal recognisers during parsing?

A

Check if the current token in the token stream is the expected one

21
Q

What is the responsibility of non terminal recognisers during parsing?

A

Save and rewind the token stream

Check compound patterns, repetitions, etc

22
Q

What does logic do in the parsing process?

A

If token recognised, move past the tokens used

If not recognised, leave the tokens and try again

23
Q

What do table driven parses do with the grammar?

A

Convert it into a table and use that to drive a parser function

24
Q

What do recursive descent parsers do with the productions?

A

Turn them straight into code

25
Q

What is the goal of parsing?

A

To get from what a human can write to what a computer can execute with minimal pain

26
Q

What are the four functions needed in a recursive descent parser?

A

nextToken()
advanceTokenStream()
getTokenStreamPosition()
setTokenStreamPosition()