70 likes | 90 Views
Explore Syntax vs Semantics, Backus-Naur Form, Extended BNF, Derivations, Parse Trees in CSE 341. Learn about syntactic components such as identifiers, expressions, and statements. Understand how syntax is crucial in defining the structure of programs.
E N D
Syntax • Syntax vs Semantics • Backus-Naur Form • Extended BNF • Derivations • Parse Trees CSE 341 -- S. Tanimoto Syntax
Syntax Syntax: The grammatical form of programs. vs Semantics: The meaning of the program Syntax (of textual languages) is typically specified by production rules for a context-free grammar using Backus-Naur Form (BNF) or Extended BNF (EBNF) In visual languages, syntax is described by a set of restrictions on how diagrams may be constructed. (e.g., connection constraints) CSE 341 -- S. Tanimoto Syntax
Syntactic Components Identifiers and reserved words Numeric constants Parentheses, braces and brackets Expressions Statements CSE 341 -- S. Tanimoto Syntax
BNF (Backus-Naur Form) (2.0 * PI) / n <expression> ::= <expression> + <term> | <expression> - <term> | <term> <term> ::= <term> * <factor> | <term> / <factor> | <factor> <factor> ::= number | name | ( <expression> ) CSE 341 -- S. Tanimoto Syntax
Extended BNF Optional constructs written as [ x ] Zero or more of x written as { x } Choice (“or”) written using | Grouping with parentheses ( x | y ) as in { (x | y ) z } <expression> ::= <term> { (+ | -) <term> } <term> ::= <factor> { (* | /) <factor> } <factor> ::= ’(’ <expression> ’)’ | name | number CSE 341 -- S. Tanimoto Syntax
Derivation E ::= E + T | E - T | T T ::= T * F | T / F | F F ::= number | name | ( E ) E E + T T + T T / F + T F / F + T F / F + F 25 / F + F 25 / 100 + F 25 / 100 + total CSE 341 -- S. Tanimoto Syntax
Parse Trees E ::= E + T | E - T | T T ::= T * F | T / F | F F ::= number | name | ( E ) 25 / 100 + total number / number + name F F F T T T E E CSE 341 -- S. Tanimoto Syntax