Week 3 Flashcards

1
Q

What is syntax

A

the form or structure of the expressions,
statements, and program units

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

whay is semantics

A

the meaning of the expressions, statements and program units

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

What is the overview of the standard of turning a text file into an executable program

A

The character stream enters teh scanner(lexical analysis)
The scanner produces token stream which then enters the parser(syntax analysis) after which produces the parse tree.

The parse tree enters the semantic analyser and intermediate code generation this produces the abstract syntax tree or other intermeidate form

This then enters the machine independent code imporovement(optional) which produces modified intermediate form.

This enters the target code generation which produces assembly or machine language or other target language

Machine specific code imporvoement -> Modified target language

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

What is a sentence

A

A sentence is a string of characters over some
alphabet (e.g., def add1(n): return n + 1)

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

What is a language

A

A language is a set of sentences

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

What is a lexeme

A

A lexeme is the lowest level syntactic unit of a language (e.g., *, add1, begin)

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

What is a token

A

A token is a category of lexemes e.g identifier

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

What are the formal apporaches to describing syntax

A

Recognizers- used in compilers
Generators

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

What are language generators

A

They are meant to describe the syntax of natural language

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

What is a meta language

A

A metalanguage is a language used to describe another language

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

What is a non terminal

A
  • A non-terminal symbol is any symbol that is on the LHS of
    a rule. They represent abstractions in the language
    Example: (if-then-else-statement in) <if-then-else-statement> ::= if <test>
    then <statement> else <statement></statement></statement></test></if-then-else-statement>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a terminal

A

A terminal symbol is any symbol that is not on the LHS of
any rule. AKA lexemes.
e.g(, if, then, else in rules above)

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

What is a pre-terminal

A

A pre-terminal symbol is a non-terminal that appears on the
LHS of >= 1 rule(s), but in every case, the RHSs consist of
single terminal symbols, e.g., <digit> in</digit>

<digit> ::= 0 | 1 | 2 | 3 … 7 | 8 | 9
</digit>

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

What is derivation

A

A derivation is a repeated application of rules, starting with the start symbol and ending with a sentence consisting only of terminal symbols

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

Example of derivation

A

<sentence> ::= <nounPhrase><verbPhrase>.
<nounPhrase> ::= <article><noun>
<article> ::= a | the
<noun> ::= man | apple | worm | penguin
<verbPhrase> ::= <verb> | <verb><nounPhrase>
<verb> ::= eats | throws | sees | is

Here is a derivation for “the man eats the apple.”
<sentence> -> <nounPhrase><verbPhrase>.
<article><noun><verbPhrase>.
the<noun><verbPhrase>.
the man <verbPhrase>.
the man <verb><nounPhrase>.
the man eats <nounPhrase>.
the man eats <article> < noun>.
the man eats the <noun>.
the man eats the apple.
</noun></article></nounPhrase></nounPhrase></verb></verbPhrase></verbPhrase></noun></verbPhrase></noun></article></verbPhrase></nounPhrase></sentence></verb></nounPhrase></verb></verb></verbPhrase></noun></article></noun></article></nounPhrase></verbPhrase></nounPhrase></sentence>

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

When is a grammar considered ambigious

A

A grammar is ambiguous if and only if (iff) it generates a sentential form that has two or more distinct parse trees.

17
Q

What is precedenc

A
  • Precedence rules specify order in which operators
    of different precedence level are evaluated
18
Q

What is associativity

A

Associativity rules specify order in which operators of
the same precedence level are evaluated.

Operators are typically either left associative or right
associative.

19
Q

Give examples of Left associaitivity

A

+, - , * and /

20
Q

What langauages diverge from the conventional left to right

A

– In Fortran, ** associates from right-to-left, as is
normally the case for mathematics

– In Ada, ** doesn’t associate; you must write the
previous expression as 2 ** (3 ** 4) to obtain the
expected answer

21
Q

Give examples of assignemnt operators that associate right to left

A

= += -= *= /= %=&raquo_space;= «= &= ^= |=

22
Q
A
23
Q
A