Define YACC.
YACC is a parser generator, YACC is an automatic tool for generating the parser program. YACC stands for Yet Another compiler which is basically the utility available from UNIX. Basically, YACC is an LALR parser generator. It can report conflict or ambiguities in the form of an error message.
What is a syntax-directed translation scheme?
Ans. Syntax-directed translation scheme It formally for describing the process of translation within a syntax-directed compiler. Syntax directed scheme Is a context•fre• grammar in which the program fragments called semantic actions (or output action or semantic rule) are embedded within the right skies of productions. For example, suppose an output action is associated with production A -> XYZ. The action a is executed whenever the analyzer recognizes in its input a substring w which has a derivation of the form A -> XYZ -> *w
A translation scheme is like a syntax-directed definition except that the order of the evaluation of the semantic rules is explicitly shown. The position at action is to be executed is shown by enclosing it between braces and writing it within the right side of a production.
Explain the dependency graph.
Ans. Dependency graphs are useful tools for determining an evaluation order for the attribute instance in a given parse tree. A dependency graph depicts the flow of information among the attribute instance in a particular parse tree; an edge from one attribute instance to another means that the value of the first is needed to compute the second. Edge express constraints implied by the semantic actions.
Define syntax-directed definition.
Ans. A syntax-directed definition uses context-free grammar to specify the syntactic structure of the input. In syntax-directed definition:
(A) Each grammar symbol is associated with a set of attributes. For example, in the production cute X -> YZ, the attributes associated with the grammar symbols X, Y, and Z are represented as X.a., Y.a, and Z.a respectively.
(B) Each production rule is associated with a set of semantic rules computing the values of the attributes associated with the symbols appearing in that production. For example, if the semantic {X .a,:= Y .a,+Z.a} is associated with the production rule X -+ YZ then the parser should add the attribute ‘a’ of node Y and attribute ‘a’ of node Z together and set the attribute ‘a’ of node X to their Sum.
Define S-attribute.
Ans. A Syntax Directed Definition is called S-attribute or S-attributed definition if that uses synthesized attributes only. A parse tree for an S-attributed definition can always be annotated by evaluating the semantic rules for each node in bottom-up from the leaves to the root.
What is the difference between synthesized and inherited attribute?
S. no. | Synthesized Attribute | Inherited Attribute |
---|---|---|
1 | In synthesized attributes, the values are computed from the value of attributes at the children of that node in the parse tree. | In inherited attribute, the values are computed from the value of attributes at the siblings and parent of that node in the parse tree. |
2 | Contains only S- attributed notation. | Contains S-attributed as well as L- attributed notation. |
3 | In this, the processing is done in the form of a bottom-up fashion. | In this, the processing is done in the form of a top-down fashion. |
4 | For example: Let X -> YZ(X.x:=Y.y+ Z.z) | For example: Let X -> 1Z(Z.z:= X .x + Y.y) |