3.5.2 Syntax Diagrams
3.5.2 Syntax Diagrams
Syntax Diagrams Syntax Diagrams: Graphical representations for visually representing EBNF rules An example: consider the grammar rule factor-(exp number The syntax diagram
Syntax Diagrams • Syntax Diagrams: – Graphical representations for visually representing EBNF rules. • An example: consider the grammar rule factor→( exp ) | number • The syntax diagram: factor number ( exp )
Syntax diagrams factor number Boxes representing terminals and non-terminals Arrowed lines representing sequencing and choices. Non-terminal labels for each diagram representing the grammar rule defining that Non-terminal. a round or oval box is used to indicate terminals in a diagram A square or rectangular box is used to indicate non terminals
Syntax Diagrams • Boxes representing terminals and non-terminals. • Arrowed lines representing sequencing and choices. • Non-terminal labels for each diagram representing the grammar rule defining that Non-terminal. • A round or oval box is used to indicate terminals in a diagram. • A square or rectangular box is used to indicate nonterminals. factor number ( exp )
Syntax diagrams A repetition:A→>{B} An optional:A→/B
Syntax Diagrams • A repetition : A → {B} • An optional : A → [B] B A B A
Examples Example: Consider the example of simple arithmetic expressions exp,exp addo termterm adop→+ term,term mulop factor factor factor→(exp) number This bnf includes associativity and precedence
Examples • Example: Consider the example of simple arithmetic expressions. exp → exp addop term | term addop → + | - term → term mulop factor | factor mulop→ * factor → ( exp ) | number • This BNF includes associativity and precedence