Found 177 Articles for Programming Languages

What is the role of the lexical analyzer in compiler design?

Ginni
Updated on 07-Nov-2023 05:29:58

40K+ Views

The lexical analysis is the first phase of the compiler where a lexical analyser operate as an interface between the source code and the rest of the phases of a compiler. It reads the input characters of the source program, groups them into lexemes, and produces a sequence of tokens for each lexeme. The tokens are sent to the parser for syntax analysis.If the lexical analyzer is located as a separate pass in the compiler it can need an intermediate file to locate its output, from which the parser would then takes its input. It can eliminate the need for ... Read More

What is Ambiguous Grammar?

Ginni
Updated on 26-Oct-2021 08:59:12

16K+ Views

A Grammar that makes more than one Leftmost Derivation (or Rightmost Derivation) for the similar sentence is called Ambiguous Grammar.Example − Verify whether the following Grammar is Ambiguous or Not.E → E+E|E $\ast$ E|idSolutionFor string id + id * id, there exist two parse trees.E ⇒lm $\underline{E}$+E ⇒ id+ $\underline{E}$⇒ id+$\underline{E}$ $\ast$ E⇒ id+id $\ast$ $\underline{E}$⇒ id+id $\ast$ idE ⇒lm $\underline{E}$ $\ast$ E⇒ $\underline{E}$+E $\ast$ E⇒ id+ $\underline{E}$ $\ast$ E⇒ id+id $\ast$ $\underline{E}$⇒ id+id $\ast$ idSo, the same string is generated using two different leftmost derivations. Each is having a different parse tree.∴ Two different parse trees exist for string id + id ... Read More

What are Parse Trees (Derivation Trees)?

Ginni
Updated on 26-Oct-2021 08:47:49

11K+ Views

Derivations mean replacing a given string’s non-terminal by the right-hand side of the production rule. The sequence of applications of rules that makes the completed string of terminals from the starting symbol is known as derivation. The parse tree is the pictorial representation of derivations. Therefore, it is also known as derivation trees. The derivation tree is independent of the other in which productions are used.A parse tree is an ordered tree in which nodes are labeled with the left side of the productions and in which the children of a node define its equivalent right parse tree also known ... Read More

What are Derivations?

Ginni
Updated on 26-Oct-2021 08:38:45

3K+ Views

Derivations mean replacing a given string’s non-terminal by the right-hand side of the production rule. The sequence of applications of rules that makes the completed string of terminals from the starting symbol is known as derivation.It can derive terminal strings, beginning with the start symbol, by repeatedly replacing a variable with some production. The language of CFG is a set of terminal symbols we can derive so. This language is called context Free Language.Derivations are denoted by ⇒.For example, consider a Grammar.G=({S}, {a, b}, P, S), where, P contains following productions −P={S→aSa |bSb | ∈}In the above, S may be ... Read More

What is Context-Free Grammar?

Ginni
Updated on 26-Oct-2021 08:20:44

5K+ Views

Grammar − It is a set of rules which checks whether a string belongs to a particular language a not.A program consists of various strings of characters. But, every string is not a proper or meaningful string. So, to identify valid strings in a language, some rules should be specified to check whether the string is valid or not. These rules are nothing but make Grammar.Example − In English Language, Grammar checks whether the string of characters is acceptable or not, i.e., checks whether nouns, verbs, adverbs, etc. are in the proper sequence.Context-Free GrammarIt is a notation used to specify ... Read More

What is the implementation of a Lexical Analyzer?

Ginni
Updated on 26-Oct-2021 08:18:10

9K+ Views

Lexical Analysis is the first step of the compiler which reads the source code one character at a time and transforms it into an array of tokens. The token is a meaningful collection of characters in a program. These tokens can be keywords including do, if, while etc. and identifiers including x, num, count, etc. and operator symbols including >, >=, +, etc., and punctuation symbols including parenthesis or commas. The output of the lexical analyzer phase passes to the next phase called syntax analyzer or parser.The syntax analyser or parser is also known as parsing phase. It takes tokens ... Read More

What is LEX?

Ginni
Updated on 03-Nov-2023 03:39:01

24K+ Views

It is a tool or software which automatically generates a lexical analyzer (finite Automata). It takes as its input a LEX source program and produces lexical Analyzer as its output. Lexical Analyzer will convert the input string entered by the user into tokens as its output.LEX is a program generator designed for lexical processing of character input/output stream. Anything from simple text search program that looks for pattern in its input-output file to a C compiler that transforms a program into optimized code.In program with structure input-output two tasks occurs over and over. It can divide the input-output into meaningful ... Read More

What is minimizing of DFA in compiler design?

Ginni
Updated on 26-Oct-2021 08:09:57

3K+ Views

Minimizing means reducing the number of states in DFA. We have to detect those states of DFA whose presence or absence in DFA does not affect language accepted by DFA. These states can be eliminated from DFA.Algorithm: Minimization of DFAInput − DFA D1 with a set of states Q with a set of final states F.Output − DFA D2 which accepts the same language as D1 and having a minimum number of states as possible.MethodMake a partition 'π' of a set of states with two subsets −Final state 'F'Non-Final States 'Q-F'∴ π={F, Q−F}To apply the following procedure to make πnew ... Read More

Can we convert a non-deterministic finite automata into a deterministic finite Automata?

Ginni
Updated on 26-Oct-2021 08:02:51

908 Views

Yes, we can convert a NFA into DFA. For every NFA there exists an equivalent DFA. The equivalence is defined in terms of languages acceptance. Since NFA is nothing but a finite automata in which zero, one or more transitions on an input symbols are permitted. It can always construct finite automata which will simulate all moves of DFA on a particular input symbol in parallel, then get a finite automata in which there will be exactly one transition on every input symbol. Here, corresponding to a NFA there exist a DFA. To construct DFA equivalent to NFA, it should ... Read More

What is Non-Deterministic Finite Automata (NFA)?

Ginni
Updated on 26-Oct-2021 07:54:36

2K+ Views

Non-Deterministic means that there can be several possible transitions on the same input symbol from some state. The output is non-deterministic for a given input. NFA can be represented as a nondeterministic finite state machine.NFA can be represented by 5 tuples (Q, $\sum$, $\delta$, q0, F)Q is a finite non-empty set of states.$\sum$ is a finite set of input symbols.$\delta$ is the transition function to move from the current state to the next state.∴ $\delta$:Q x $\sum$ → 2Qq0 ∈ Q is the initial state.F \subseteq Q is the set of final states.Example1 − Draw NFA for the Regular Expression ... Read More

Advertisements