Describing Syntax Flashcards

(50 cards)

1
Q

Sentence

A

A string of characters over some alphabet or finite set of symbols.

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

Language

A

A set of sentences.

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

Lexeme

A

The lowest level of a syntactic unit of a language. Are often not included in the formal description of the syntax of a programming language. Lexemes are divided into groups, each group receiving a token.

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

Token

A

A category of lexemes, e.g. an identifier.

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

Lexical analysis

A

The process of recognizing lexemes.

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

What are the lexemes in the line:
index = 2 * count + 17;

A

index, = , 2, *, count, +, 17, ;

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

What are the tokens in the line:
index = 2 * count + 17;

A

identifier, equal_sign, int_literal, multi_op, identifier, plus_op, int_literal, semicolon

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

Recognizers

A

Reads input strings over the alphabet of the language and decides whether the input string belong to the language. The syntax analyzer part of the compiler is a recognizer.

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

Generator

A

A device that generates sentences of a language. One can determine if the syntax of a sentence is correct if it could be made by a generator.

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

Formal Grammar

A

A set of rules for rewriting strings, along with a “start symbol” from which rewriting starts. Therefore, a grammar is usually thought of as a language generator.

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

What are the four basic formal rules for string patterns?

A

Concatenation, Alternation, Kleene Closure, and Recursion.

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

Concatenation

A

The adding of strings.

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

Alternation:

A

Choice among a finite number of alternatives.

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

Kleene Closure:

A

Repetition an arbitrary number of times.

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

Recursion:

A

Creation of a construct from simpler instances of the same construct.

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

Regular Languages

A

A set of strings that can be defined by the first three rules of string patterns, and are generated by regular expressions.

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

Context Free Language (CFL)

A

Any set of strings that can be defined if we add recursion and are generated by context-free grammars.

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

Context-Free Grammars

A

Developed by Noam Chomsky in the mid 1950s, they are language generators meant to describe the syntax of natural languages.

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

Backus-Naur Form (BNF)

A

Invented by John Backus in 1959 to describe the syntax of Algol 58 and later modified by Peter Naur to describe Algol 60. BNF is equivalent to context-free grammars.

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

Metalanguage

A

A language used to define another language. BNF is a metalanguage.

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

Abstractions

A

Used to represent classes of syntactic structures and act like syntactic variables. They are also called nonterminal symbols. Can have more than one RHS.

22
Q

Terminals

A

Lexemes and tokens not defined in terms of other terminals or non-terminals. Non-terminals are enclosed in angle brackets.

23
Q

Rule/Production

A

Has a LHS that is nonterminal and a RHS that is terminal and/or nonterminals.

24
Q

Define Context-Free Grammar G:

A

A tuple of elements (S, N, T, P) where S is a start symbol, T is a set of terminals, N is a set of non-terminals, and P is a finite non-empty set of rules.

25
How are syntactic lists described?
Using recursion.
26
What is a Grammar?
A generative device for defining languages.
27
What is a Derivation?
A repeated application of the rules, starting with a start symbol and ending with a sentence (all terminal symbols).
28
Describe BNF notation.
Non-terminals have angle brackets < >. Symbols without angle brackets are terminals. "-->", "::=", or ":=" means "is defined as." When rules are written X -> Y, X is the LHS and Y is the RHS.
29
What symbol is used to represent an empty string?
The lowercase sigma symbol.
30
Sentential Form
Every string of symbols in a derivation is of this form. A sentence, for example, is a sentential form with only terminals.
31
Leftmost Derivation
A derivation where the leftmost non-terminal is expanded first.
32
Parse Trees
Represents the derivation steps for the hierarchal structures where each internal node is a non-terminal and each leaf is a terminal. The in-order traversal of the tree is a representation of the statement that was parsed, and the traversal of the tree for execution is post-order.
33
When is a grammar ambiguous?
If and only if it generates a sentential form with two or more distinct parse trees. If the grammar generates a sentence with more than one leftmost or rightmost derivation, then it is ambiguous.
34
How to prevent ambiguity with operators?
If we use the parse tree to indicate precedence levels of the operators, we cannot have ambiguity.
35
Can a grammar rule have associativity?
Yes, operator associativity can be indicated by a grammar rule. Left recursion specifies left associativity, whereas right recursion specifies right associativity.
36
Extended BNF (EBNF)
Does not enhance the power of BNF but increases readability and writability. Optional parts are placed in brackets [], alternate parts of RHSs are placed inside parenthesis and separated with vertical bars, repetitions are put inside braces {}, and terminals that are grammar symbols are enclosed in quotes ''.
37
Is there a standard for EBNF?
Yes, the standard EBNF, ISO/IEC 14997:1996 exists but is rarely used.
38
How do you convert from BNF to EBNF?
Look for recursion in grammar and common strings that can be factored out with grouping and options, then apply EBNF rules.
39
How do you convert from EBNF to BNF?
Look for brackets and braces, then apply the normal BNF rules.
40
What are some recent variations in EBNF?
Alternative RHSs are put on separate lines, non-terminals begin with uppercase letters (replacing <>), use of the colon instead of ->, use of the subscript opt for optional parts, and the use of oneof for choices.
41
Regular Grammar
A simple scheme for using rules that represent strings to recognize. They are the simplest and least powerful of the grammars; they cannot recognize all patterns in general, such as paired items.
42
Regular Expressions
A notation for representing patterns of characters.
43
Where can regular expressions be found?
String finding in editors, pattern expansion built into command interpreters through consoles, regex libraries in java and python, and string types with built in regular expression matching (such as reg expressions in Perl).
44
What are the two types of characters in a regular expression?
A character in a regular expression is either a regular character or a metacharacter.
45
Metacharacter
A character that stands for something else. E.g. '.' is a metacharacter that means "matches any single character in the string." Placing a backslash before the metacharacter changes it into a regular character.
46
What is the regular expression for an identifier?
[a-z_A-Z][0-9a-zA-Z]*
47
What is the regular expression for an octal constant?
0[0-7]+
48
What is the regular expression for a hex constant?
0x[0-9a-fA-F]+
49
What is the regular expression for a floating point number?
[+-]?([0-9]*\.[0-9]+)e[+-][0-9]
50
Can the matching of strings to regular expressions be automated?
Yes. There are libraries that compile regular expressions and match them to strings. In fact, there is a tool called lex (or flex) that uses regular expressions to create a lexical analyzer for a compiler/interpreter. The matcher is a finite state machine.