Some languages allow programs to declare precedence and associativity for user-definedoperators. 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 alloperators 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. Whenevera conflict arises during parsing, the parser consults a table of precedences to resolvethis conflict. The precedence table is extended whenever a precedence declarationis 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 unambiguousgrammar or by eliminating conflicts in the usual way. The lexical analyzer usesa table of precedences to assign the correct terminal symbol to each operator itreads.
Compare the two methods. What are the advantages and disadvantages of each method?
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