Symbols in tINY Represent the alphabet of tokens for the TINY language fif. then, else, end, repeat, until, read, write, identifier, number;+,-,*,/, Instead of the set of tokens(as defined in the tinY scanner) FIF,THEN,ELSE,END, REPEAT, UNTIL, READ, WRI TE, ID, NUM, PLUS, MINUS,TIMES, OVER,EQ T, LPAREN, RPAREN, SEML, ASSIGN J
Symbols in TINY • Represent the alphabet of tokens for the TINY language: {if. then, else, end, repeat, until, read, write, identifier, number, +, -, *, /, =, <, (, ), ; , := } • Instead of the set of tokens (as defined in the TINY scanner) {IF,THEN,ELSE,END,REPEAT,UNTIL,READ,WRI TE,ID,NUM, PLUS,MINUS,TIMES, OVER,EQ, LT, LPAREN,RPAREN, SEMI, ASSIGN }
Construction of a cfg rule Given an alphabet, a context-free grammar rule in bnf consists of a string of symbols The first symbol is a name for a structure The second symbol is the meta-symbol"> This symbol is followed by a string of symbols each of which is either a symbol from the alphabet a name for a structure, or the metasymbol
Construction of a CFG rule • Given an alphabet, a context-free grammar rule in BNF consists of a string of symbols. – The first symbol is a name for a structure. – The second symbol is the meta-symbol"→". – This symbol is followed by a string of symbols, each of which is either a symbol from the alphabet, a name for a structure, or the metasymbol "|
Construction of a cfg rule a grammar rule in BNF is interpreted as follows The rule defines the structure whose name is to the left of the arrow The structure is defined to consist of one of the choices on the right-hand side separated by the vertical bars The sequences of symbols and structure names within each choice defines the layout of the structure For example exp>exp op exp (exp) number
Construction of a CFG rule • A grammar rule in BNF is interpreted as follows – The rule defines the structure whose name is to the left of the arrow – The structure is defined to consist of one of the choices on the right-hand side separated by the vertical bars – The sequences of symbols and structure names within each choice defines the layout of the structure – For example: • exp → exp op exp | (exp) | number • op → + | – | *
More about the conventions The meta-symbols and conventions used here are in wide use but there is no universal standard for these conventions Common alternatives for the arrow metasymbol> include (the equal sign), " " (the colon), and". " double-colon-equals") In normal text files, replacing the use of italics, by surrounding structure names with angle brackets <. and by writing italicized token names in uppercase Example <exp>: :=<exp> <op> <exp> (<exp>)INUMBER <0p>:=+|-
More about the Conventions • The meta-symbols and conventions used here are in wide use but there is no universal standard for these conventions – Common alternatives for the arrow metasymbol '→' include "=" (the equal sign), ":" (the colon), and "::=" ("double-colon-equals") • In normal text files, replacing the use of italics, by surrounding structure names with angle brackets <...> • and by writing italicized token names in uppercase • Example: – <exp> ::= <exp> <op> <exp> | (<exp>) | NUMBER – <op> ::= + | - | *
3.2.3 Derivations language Defined by a grammar
3.2.3 Derivations & Language Defined by a Grammar