Parsing
Vedi:
Grammar
E –> E “+” E
E “-” E |
---|
“-” E |
E “*” E |
E “/” E |
E “^” E |
“(” E “)” |
v |
Rules
We want to build a parser that will
- Produce an error message if its input is not in the language of this grammar.
- Produce an “abstract syntax tree” (AST) reflecting the structure of the input, if the input is in the language of the grammar.
Each input in the language will have a single AST based on the following precedence and associativity rules:
- Parentheses have precedence over all operators.
- ^ (exponentiation) has precedence over unary - and the binary operators /, *, -, and +.
- * and / have precedence over unary - and binary - and +.
- Unary - has precedence over binary - and +.
- ^ is right associative while all other binary operators are left associative.