Prev | Current Page 167 | Next

Carl Reynolds and Paul Tymann

"Schaum's Outline of Principles of Computer Science"


If an expression can be parsed according to the grammar of the language, the expression conforms to
the syntax of the language. Once the parser creates the parse tree, the compiler can work from the bottom of the
tree to the top, creating the machine instructions to implement the expression. This last phase is called code
generation.
Today most descriptions of language syntax use a version (there are several) of EBNF. Some notational
changes simplify the representations of productions. In particular, EBNF uses curly brackets to denote ???zero
or more occurrences of,??? and it uses square brackets to denote optional parts of a production. EBNF uses
parentheses and vertical ???or??? separators to denote multiple-choice options for a single element. We can rewrite
the grammar above using this EBNF notation:
expression -> term { (+ | -) term }
term -> factor { (* | /) factor }
factor -> identifier | number | - factor | ( expression )
If it is not obvious that these rules agree with our earlier grammar, consider our earlier first rule for
expressions:
expression -> term | expression add_op term
From this rule, we can generate:
expression -> term
expression -> expression + term
expression -> expression + term + term
expression -> expression + term + term + term
.


Pages:
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
pokoje nad morzem tanio pomiary wiatru hotel kredyt samochodowy santander remont warszawa