Here’s a BNF definition:
- lcchar ::= a | b | c | … | z
- varname ::= lcchar | lcchar varname
- equals ::= “=”
- operator ::= + | - | * | /
- operand ::= integer | varname
- unaryoperation ::= operand
- binaryoperation ::= operand operator operand
- operation ::= unaryoperation | binaryoperation
- expression ::= varname equals operation
Exercise: you should be able to write some lines of Python code to implement this by yourself now, give it a try before proceeding to the next page
One more operation you should know is the ‘^’ operand, which can be used to OR two Pyparsing operands.














5 Responses to “Pyparsing introduction: BNF to code”
Leave a comment