- Some Languages Allow Programs To Declare Precedence And Associativity For User Defined Operators This Can Make It Diffi 1 (56.95 KiB) Viewed 69 times
Some languages allow programs to declare precedence and associativity for user-defined operators. This can make it diffi
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Some languages allow programs to declare precedence and associativity for user-defined operators. This can make it diffi
Some languages allow programs to declare precedence and associativity for user-defined operators. This can make it difficult to handle precedence during parsing, as the prece- dences are not known when the parser is generated. A typical solution is to parse all operators using the same precedence and then restructure the syntax tree afterwards. Below are two other methods that have been used for this purpose: (a) An ambiguous grammar is used and conflicts exist in the parsing table. Whenever a conflict arises during parsing, the parser consults a table of precedences to resolve this conflict. The precedence table is extended whenever a precedence declaration is read. (b) A terminal symbol is made for every possible precedence and associativity com- bination. A conflict-free parse table is made either by writing an unambiguous grammar or by eliminating conflicts in the usual way. The lexical analyzer uses a table of precedences to assign the correct terminal symbol to each operator it reads. Compare all three methods. What are the advantages and disadvantages of each method?