1 / 9

COMPILERS

COMPILERS. LECTURE DATE: AUG-14,2013. By- Smriti Agrawal 11cs10056. Algorithm to convert NFA to DFA. NFA: has x no. of states DFA: has atmost 2^x no. of states Algorithm should be such that we have to simulate NFA to DFA instead of converting to DFA Let S0 be start state of NFA,

kibo-hebert
Download Presentation

COMPILERS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMPILERS LECTURE DATE: AUG-14,2013 By- SmritiAgrawal 11cs10056

  2. Algorithm to convert NFA to DFA • NFA: has x no. of states • DFA: has atmost 2^x no. of states • Algorithm should be such that we have to simulate NFA to DFA instead of converting to DFA • Let S0 be start state of NFA, • then start state of DFA (S):є- closure(S0) • Always the longest string is preferred. • So if there is >=< then (>=) will be recognised and one token and (<) will be recognised as another token. > 3 2 є 1 > = 5 4 6 є

  3. Algorithm: C= read_character() While (c!=‘\0’) { S(set of states of NFA) = є-closure ( δ(s,c)) c= read_nextchar() } If(S∩F != ɸ) { acceptance state } Else { Reject }

  4. Syntax Analyzer • There are syntactic rules for a particular Grammar. • A grammar: • Precisely specify syntax rules of programming language • Automatically generate those parser which will detect the correctness of programming language • Report errors • Add new rules to make the language more powerful by improving the functionality of grammar

  5. Programming definition CFGFG Directed by specification/grammatical rules Syntax Rules Programme Parser Parse Tree • Parser will report some of the possible ambiguities of programming language definition(CFG) • Output file should contain tokens. • Generate errors if it fails to construct parse tree

  6. <V, T, S, P> • V: Variables, • T: Terminal set which contains set of symbols which construct the string • -Terminals are mapped with tokens • S: S -> S є V where S is the Start variable • P: Production: rules which combine terminals and non terminals

  7. Example: Production: st-> if (expr)then st else st If : T ( : T Expr : V ) : T Then : T st : V Else : T

  8. S  w, a string of terminals . • If by some production /derivation we can create w from s, then we say it is accepted. • L(G)  CFG (Set of strings accepted by that grammar) • Derivations: • E  E + E • E  (E) • E  -E • E  Id • a Ab  a g b • A  g

  9. S  a Ab Sentential form which is a combination of terminals and non terminals( NT , T) • If it contains only terminals, then it is called sentence • After deriving, how to move from  • 1. During derivation it should be known which non terminal to replace. • 2. Secondly, it should be known which rule to be used. • A  g • Here, A is the head and g is the body of the production. • For example: • E  (E) -1 •  (E+E) -2 •  ( id + E) -3 •  (id + id) -4 • In the above derivation, thus to avoid conflict we should know whether to replace left or right E by id in the 3rd step of derivation.

More Related