Last active
November 6, 2018 10:19
-
-
Save shivamMg/b60885fea0cf657d82cbb6e820981d7b to your computer and use it in GitHub Desktop.
Grammars for parsing arithmetic expressions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Grammar with left-recursion (e.g. Expr's derivation contains Expr as first non-terminal). | |
| Not suitable for Recursive Descent parsing. | |
| Expr = Expr "+" Term | Expr "-" Term | Term | |
| Term = Term "*" Factor | Term "/" Factor | Factor | |
| Factor = "(" Expr ")" | "-" Factor | Number |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Grammar without left-recursion. But not left-factored, that's why it needs arbitrary lookahead, | |
| e.g. Expr's derivation will need to look ahead Term to see which derivation to go with. | |
| Suitable for R.D. parsing but needs backtracking. | |
| Expr = Term "+" Expr | Term "-" Expr | Term | |
| Term = Factor "*" Term | Factor "/" Term | Factor | |
| Factor = "(" Expr ")" | "-" Factor | Number |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Grammar without left-recursion. Left-factored. Needs single lookahead. | |
| Suitable for R.D. parsing. Does not need backtracking. | |
| Expr = Term Expr' | |
| Expr' = "+" Expr | "-" Expr | ε | |
| Term = Factor Term' | |
| Term' = "*" Term | "/" Term | ε | |
| Factor = "(" Expr ")" | "-" Factor | Number |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment