Posts

What is the Difference between Scanning and Parsing

Image
  What is the Difference between Scanning and Parsing The main difference between scanning and parsing is that scanning is the process of reading the source code one character at a time in a methodical manner to convert them into tokens while parsing is the process of taking the tokens and generating a parse tree as the output. Generally, a compiler is a software program that is capable of converting the source code into machine code so that the computer can execute that machine code. The compiler goes through multiple phases to compile a program. Scanning and parsing are two activities that occur during this compilation process. Overall, scanning occurs at the lexical analysis phase, whereas parsing occurs at the syntax analysis phase. Furthermore, the lexical analyzer performs scanning while the parser performs parsing.

Derivation & Derivation Tree in Compiler Design (Left Most Derivation & Right Most Derivation)

Image
  Download pdf Derivation   ·          The process of deriving a string is called as  derivation . ·          The geometrical representation of a derivation is called as a  parse tree  or  derivation tree. 1. Leftmost Derivation-   ·          The process of deriving a string by expanding the leftmost non-terminal at each step is called as  leftmost derivation . ·          The geometrical representation of leftmost derivation is called as a  leftmost derivation tree .   Example-   Consider the following grammar- S → aB / bA A → aS / bAA / a B → bS / aBB / b ( Unambiguous Grammar )   Let us consider a string w = aaabbabbba Now, let us derive the string w using leftmost derivation.   Leftmost Derivation-   S   → a B →  aa B B                   (Using B → aBB) → aaa B BB                (Using B → aBB) → aaab B B                (Using B → b) → aaabb B                 (Using B → b) → aaabba B B            (Using B → aBB) → aaabbab B  

Syntax Tree

Image
Download pdf What is Syntax Tree? Tree in which each leaf node describes an operand & each interior node an operator. The syntax tree is shortened form of the Parse Tree. Example1  − Draw Syntax Tree for the string a + b ∗ c − d. Rules for constructing a syntax tree Each node in a syntax tree can be executed as data with multiple fields. In the node for an operator, one field recognizes the operator and the remaining field includes a pointer to the nodes for the operands. The operator is known as the label of the node. The following functions are used to create the nodes of the syntax tree for the expressions with binary operators. Each function returns a pointer to the recently generated node. ·         mknode (op, left, right)  − It generates an operator node with label op and two field including pointers to left and right. ·         mkleaf (id, entry)  − It generates an identifier node with label id and the field including the entry, a pointer to the symbol tabl