2-10 Grammars Flashcards
Syntax
the form or structure of the code (expressions, statements, program units)
Semantics:
the meaning of the code (what does each statement do?)
Alphabet:
What characters can constitute a program (C++: letters, numbers,
symbols: ()[]{}.,;+=-*/, whitespace: space, tab, return, eof)
Sentence
: string of characters from the alphabet
Language
: set of sentences
Lexeme
: the lowest level syntactic unit of a language (if, (, continue, ), etc.)
Token
category of lexeme: (keyword, punctuation, identifier, punctuation,
punctuation, identifier, operator, integer literal, punctuation, etc.)
DFA’s and NFA’s
recognize a language
Grammars
define the rules of a language
Regular Grammars
- Can be right-linear or left-linear
- Generate regular languages
- Accepted by DFA’s
- Some computer languages are regular like when you use regular expressions for pattern matching
Context-Free Grammars
- Generate context-free languages
- Accepted by push-down automata
- Programming languages are context free
Context-Sensitive Grammars (Unrestricted Grammars)
- Generate recursively enumerable languages
- Accepted by Turing Machines
BNF grammars are a form of
context-free grammars
Grammar is ambiguous if
It can generate multiple parse trees
Grammar is unambiguous if
it generates a single parse tree