Chapter 6 Flashcards

(55 cards)

1
Q

What is syntax in the context of programming languages?

A

Syntax is the structure of a language—the rules that describe how tokens can be combined to form valid phrases, expressions, and programs.

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

What is lexical structure?

A

Lexical structure is how characters form tokens like identifiers, keywords, literals, and operators.

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

What is the purpose of scanning?

A

Scanning groups characters into tokens and removes whitespace/comments.

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

What is the purpose of parsing?

A

Parsing checks token sequence against grammar and builds a parse tree or AST.

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

Difference between scanner and parser?

A

Scanner makes tokens; parser checks structure and builds syntax tree.

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

Common token categories?

A

Keywords, identifiers, literals, and special symbols.

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

What is a reserved word?

A

A keyword that cannot be used as an identifier.

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

What is a predefined identifier?

A

Identifier with built‑in meaning (library) but can technically be redefined.

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

Are true/false/null keywords in Java?

A

They are literals, not keywords.

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

Longest substring rule?

A

The scanner always chooses the longest sequence of characters that forms a valid token, rather than stopping early.

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

What are delimiters?

A

Whitespace/tabs/newlines separating tokens.

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

Indentation in Python vs C++/Java?

A

Python: syntactic; C++/Java: stylistic only.

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

What is a free‑format language?

A

Layout doesn’t affect syntax (Java, C++).

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

What is a fixed‑format language?

A

Column‑sensitive languages like old Fortran.

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

What defines tokens formally?

A

Regular expressions.

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

Basic reglar expression operations?

A

Concatenation, repetition, choice (|).

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

[a‑z] meaning?

A

Any lowercase letter a through z.

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

What does ? mean in regular expression?

A

Optional (0 or 1 occurrence).

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

What does . mean in regular expression?

A

. can be any type of character (excluding newline) that can be inserted into the expression

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

Meaning of (a|b)*c?

A

Any sequence of a/b ending with c.

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

What is a context‑free grammar?

A

Tells you how strings in the language can be built, using rules that replace nonterminal symbols with sequences of terminals and/or nonterminals.

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

What is Backus–Naur Form (BNF)?

A

BNF is a formal notation used to define a language’s grammar using nonterminals, terminals, and production rules.. Notation for grammars using ::= and |.

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

Terminals vs nonterminals?

A

Nonterminals define structure; terminals are actual tokens.

24
Q

What is a production rule?

A

Replacement rule for a nonterminal.

25
What is the start symbol?
First nonterminal that starts the expression
26
Language of a grammar?
The set of all possible strings of terminals that can be generated from the start symbol by applying grammar rules.
27
What is a derivation?
The process of repeatedly applying grammar rules until you end up with a string made entirely of terminals
28
Why some issues are semantic?
Because Context Free Grammars can't express meaning-based constraints.
29
What is a parse tree?
A tree diagram that shows how a grammar generates a string.
30
Abstract Syntax Tree (AST)?
Simplified parse tree focusing on essential structure.
31
Parse tree vs AST?
Parse tree shows full grammar; AST omits unnecessary nodes.
32
Why use Abstract Syntax Tree (AST)s?
Simplifies semantic analysis and code generation.
33
Ambiguous grammar?
A grammar is ambiguous if a single input can be parsed in more than one way
34
Classic ambiguity example?
3 + 4 * 5 without precedence rules.
35
Leftmost derivation?
Every step you expand the leftmost nonterminal first
36
Using leftmost derivations for ambiguity?
Two different leftmost derivations = ambiguous.
37
Operator precedence?
Operator precedence tells you which operations are higher priority and should be evaluated before others.
38
Encoding precedence?
Encoding precedence means rewriting a grammar so that operator precedence is built into the grammar rules, removing ambiguity. Use expr/term/factor hierarchy.
39
What is associativity?
Determines the order in which operators of the same precedence level are evaluated.
40
Left recursion & associativity?
Left recursion → left‑associative.
41
Right recursion & associativity?
Right recursion → right‑associative.
42
What is EBNF?
Extended BNF adding { } and [ ].
43
{ } in EBNF?
Means repetition: the enclosed pattern can appear zero or more times
44
[ ] in EBNF?
Optional part.
45
What is a syntax diagram?
Graph that show the grammar representation.
46
Compiler?
Translates source code into machine code.
47
What is a recognizer?
Parser that only checks if input is valid.
48
Top‑down parsing?
Builds tree from root downward.
49
Bottom‑up parsing?
Builds tree from leaves upward.
50
Recursive descent?
Hand‑written top‑down parser with one function per nonterminal.
51
Predictive (LL) parsing?
top-down method where the parser looks at the next token to immediately choose the correct grammar rule, without guessing
52
Shift‑reduce parsing?
Shift-reduce parsing is a bottom-up method where the parser shifts tokens onto a stack and reduces them using grammar rules until it forms the start symbol.
53
Parser generators?
Parser generators are tools that take a grammar and automatically produce a fully functioning parser, saving developers from writing parsing code manually.
54
Manual vs generated parsers?
Manual: more control; generators: faster and safer.
55
Lexics vs syntax vs semantics?
Lexics = tokens; syntax = structure; semantics = meaning.