Week 3 Flashcards
What is syntax
the form or structure of the expressions,
statements, and program units
whay is semantics
the meaning of the expressions, statements and program units
What is the overview of the standard of turning a text file into an executable program
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
What is a sentence
A sentence is a string of characters over some
alphabet (e.g., def add1(n): return n + 1)
What is a language
A language is a set of sentences
What is a lexeme
A lexeme is the lowest level syntactic unit of a language (e.g., *, add1, begin)
What is a token
A token is a category of lexemes e.g identifier
What are the formal apporaches to describing syntax
Recognizers- used in compilers
Generators
What are language generators
They are meant to describe the syntax of natural language
What is a meta language
A metalanguage is a language used to describe another language
What is a non terminal
- 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>
What is a terminal
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)
What is a pre-terminal
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>
What is derivation
A derivation is a repeated application of rules, starting with the start symbol and ending with a sentence consisting only of terminal symbols
Example of derivation
<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>