(→Exercises) |
|||
Line 25: | Line 25: | ||
* [[The YACC Parser Generator/Exercise 1|Exercise 1]] | * [[The YACC Parser Generator/Exercise 1|Exercise 1]] | ||
+ | * [[The YACC Parser Generator/Exercise 2|Exercise 2]] | ||
+ | * [[The YACC Parser Generator/Exercise 3|Exercise 3]] | ||
+ | * [[The YACC Parser Generator/Exercise 4|Exercise 4]] | ||
== See Also == | == See Also == |
Yacc (yet another compiler compiler) is a grammar parser and parser generator. That is, it is a program that reads a grammar specification and generates code that is able to organize input tokens in a syntactic tree in accordance with the grammar. In addition, the grammar specification has semantic content (in the form of actions associated with grammar rules) that are also organized to be executed when tree nodes are built ("reduced" is the actual term).
The parser generated by Yacc is an LALR(1) parser with a few pragmatic extensions to deal with non-LALR(1) grammars and other problems having to do with the fact that grammars sometimes are wrong and Yacc must signal those problems in a useful way, so that the grammar creator can improve it. Examples of these extensions are error handling (e.g. in case of conflicts). Theoretically, in the presence of conflicts, the parser could be said not to exist, but Yacc solves the problem by coding default behavior when needed. These behaviors may be what is needed, but, in general, it is an error using grammars that give rise to conflicts in the parser. These matters will be discussed below.
After a successful run, Yacc will produce, at least, the yyparse() function, which runs the parser and produces the syntax-driven evaluation of the semantic actions in the rules. This function, when the appropriate actions are coded, produces the syntactic tree as a data structure (a tree, which may not come as much of a surprise).