Compiler Design: Theory questions with answer

April 3, 2018 | Author: Md Saidur Rahman Kohinoor | Category: Parsing, Computer Programming, Computer Science, Style (Fiction), Metalogic


Comments



Description

 What are the tasks of Lexical Analyzer?Ans: The main task of lexical analyzer is to read a stream of characters as an input and produce a sequence of tokens such as names: keywords, punctuation marks etc for syntax analyzer.  What are the properties of token? Ans: Properties of token- 1) Data Security token. 2) Security token. 3) Access token. 4) Session Token 5) Token Ring  What is token? Ans: A lexical token is a sequence of characters that can be treated as unit in the grammar of the programming Languages. Ex: Type token, Punctuation tokens, Alphabetic tokens.  What is Lexeme? Ans: The lexical analyzer read the stream of characters making up the source program and groups the characters into meaningful sequences called lexeme.  What is Lexer? Ans: A program that performs lexical analysis may be called lexer, tokenizer or scanner. Such a lexer is generally combined with a parser which together analyzes the syntax of programming languages, web pages and so for.  Draw the architecture of phases of compiler connected to symbol table and describe 2 or 3 steps. Ans:  What is the Properties of Grammar? Ans: Properties of Grammar- 1) V-Variables/non terminal 2) T-terminal 3) S-start 4) P-Production(rules)  Terminal and Non terminal. Ans: In computer science, terminal and non terminal symbol are the lexical elements used in specifying the production rules constituting a formal grammar. Ex- A-Z-> Variables/Non terminal a-z-> terminals 0-9-> terminals Special character (, ? ! @ etc)-> terminals €/₰-> terminals  Ambiguous Grammar. Ans: A grammar can have more than one parse tree generating a given string of terminals such a grammar to be ambiguous.  Parse Tree. Ans: A parse tree pictorially shows how the start symbol of a grammar derives a string in the language.  What is lexical analyzer? Ans: Lexical analyzer is the first phase of a compiler. It takes the modified source code from language preprocessors that are written in the form of syntaxes. The lexical analyzer breaks these syntaxes into a series of tokens by removing any whitespace or comments in the source code.  What is Syntax analyzer? Ans: A syntax analyzer or parser takes the input from a lexical analyzer in the form of token streams. The parser analyzes the source code (token streams) against the production rules to detect any errors in the code. The output of this phase is a parse tree. This way, the parser accomplishes two tasks, i.e. parsing the code, looking for errors and generating a parse tree as the output of the phase.  What is semantic analyzer? Ans: Semantics of a language provide meaning to its constructs, like tokens and syntax structure. Semantics help interpret symbols, their types, and their relations with each other. Semantic analyzer judges whether the syntax structured constructed in the source program derives any meaning or not.  Grammar: S-> ABA/aaBa ---- 1 A-> aBa/bA ----2 B-> bBB/ba ----3 From the given grammar derive the text below- abaabbababaa Grammar is combination of state machine i) Prove that the text will derive or not. ii) Draw Parse tree. ->Assume S derives ABA or A->bA. ->If not given then 1st one is the start point. Ans: (i) (ii) Parse Tree:  RE/RL: L={a,b,c} Suppose set of L contains all elements in it zero or more instance of a, two or more possibility of C. Zero or more instance of a and either two consecutive b or at least one or more possiblity of c. RE-> a*bb|c+ i) What is the RE. ii) Produce the NFA. iii) Convert to DFA. Ans: 1) RE-> a*bb|c+  Difference between Compiler and Interpreter. Ans:  What is Automata theory? Ans: The Automaton or Automata theory is the study of abstract mathematical machines or systems that can be used to solve computational problems. An automaton is made up of states and transitions and as it sees a symbol or letter of input, it makes a transition to another state taking the current state and symbol as input.  Difference between NFA and DFA. Ans:  Task of syntax analyzer. Ans: 1) Generate parse tree 2) Token arrangements are checked against the source code grammar.  Task of Semantic analyzer. Ans: 1) It checks whether the parse tree constructed follows the rules of language. 2) It keeps track identifier their types and expressions. 3) It produce an annotated syntax tree as output.  Why lexical analyzer is called removal?  Why lexical analyzer is called identifier?  Symbol Table management. Ans: An essential function of a compiler is to record the variable names used in the source program and collect information about various attributes of each name. These attributes may provide information about the storage allocated for a name, its type, its scope.  Symbol Table. Ans: The symbol table is a data structure containing a record for each variable name, with fields for the attributes of the name.  What is grammar? Ans: A context free grammar has 4 components.- 1) A set of terminal (T) symbols referred as ‘token’ 2) A set of non terminals (v), referred as ‘syntactic variables’. 3) A set of production (P), consists of terminals/ non terminals. 4) A designation of one of the non terminals as the start symbol (S). Grammar is the combination of state machines. Ex: list->list + digit.  Properties of parse tree. Ans: 1) The root is labeled by the start symbol. 2) Each leaf is labeled by a terminal or by €. 3) If any interior node labels children of that node from left to right, then there must be a production containing either a terminal or a non terminal.  What is parsing? Ans: Parsing is the process of determining how a string of terminals can be generated by a grammar. A parser must be capable of constructing the tree in principle, or else the translation cannot be guaranteed correct. Parsing method is divided into 3 classes- 1) Top-down parsing 2) Bottom-up parsing 3) Predicitive parsing  Difference between Top-down parsing, Bottom-up parsing and Predicitive parsing. Ans: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: www.PointOutBD.com ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Copyright © 2024 DOKUMEN.SITE Inc.