Recursive descent parser: Difference between revisions

Content deleted Content added
Bluebot (talk | contribs)
Bringing "External links" and "See also" sections in line with the Manual of Style using AWB
Example parser: fmt (EBNF grammar example) (spacing and 4-space indent)
Line 15:
[[Algorithms + Data Structures = Programs]]) is in [[LL parser|LL(1)]] form:
 
program = block "." .
<pre>
program = block "." .
block =
 
["const" ident "=" number {"," ident "=" number} ";"]
block =
[ "constvar" ident "=" number {"," ident "=" number} ";"]
[ {"varprocedure" ident {",;" ident}block ";"]} statement .
{ "procedure" ident ";" block ";" } statement .
statement =
 
factor = [ident | number | "(:=" expression ")" .
statement =
[ ident| ":=call" expressionident
| "whilebegin" conditionstatement {"do;" statement} "end"
| "call" ident
| "beginif" statementcondition {";then" statement } "end"
| "ifwhile" condition "thendo" statement
] .
| "while" condition "do" statement
].
condition =
 
"odd" expression
condition =
| expression ("odd="|"#"|"<"|"<="|">"|">=") expression
.
| expression ("="|"#"|"<"|"<="|">"|">=") expression
.
expression = [ "+"|"-"] term { ("+"|"-") term} .
 
expression = [ "+"|"-"] term { ("+"|"-") term} .
term = factor {("*"|"/") factor} .
 
term = factor {("*"|"/") factor} .
factor = ident | number | "(" expression ")" .
 
factor = ident | number | "(" expression ")" .
</pre>
 
[[Terminal symbol|Terminals]] are expressed in quotes (except for the well defined ''ident''