CS152
Chris Pollett
Feb. 16, 2009
Recall we are learning about how to specify the syntax of a programming language. On Wednesday, we were learning about context-free grammars and gave an example grammar for a very tiny fragment of English:
sentence → noun-phrase verb-phrase . noun-phrase → article noun article → a | the noun → girl | dog verb-phrase → verb noun-phrase verb → sees | pets
You could imagine productions where you have more than one thing on the left hand side:
<sentence> ::= <start-of-sentence> <noun-phrase> <verb-phrase> <start-of-sentence> <article> ::= The | A <start-of-sentence> ::= empty-string ...
This would allow you to capitalize the start of sentence, but the rule:
<start-of-sentence> <article> ::= The | A
uses the context in which the <article> appears.
Which string does not match the regular expression: [a-z]+[0-9]*
?
<expr> ::= <expr> + <expr> | <expr> * <expr> | (<expr> ) | <number> <number> ::= <number> <digit> | <digit> <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<external-declaration> ::= <function-definition> | <declaration>
<struct1> ::= <struct2> <struct3> terminalwas used then in the parse tree <struct2>, <struct3>, and terminal will be children of <struct1>