Approximating Context-Free Grammars for Parsing and Verification

Size: px
Start display at page:

Download "Approximating Context-Free Grammars for Parsing and Verification"

Transcription

1 Approximating Context-Free Grammars for Parsing and Verification Sylvain Schmitz LORIA, INRIA Nancy - Grand Est October 18, 2007

2 datatype a option = NONE SOME of a fun filter pred l = let fun filterp (x::r, l) = case (pred x) filterp ([], l) = rev l in of SOME y => filterp(r, y::l) NONE => filterp(r, l) filterp (l, []) end /** * smlfvalbind.y * * Standard ML function declarations. * See _The_definition_of_standard_ML_, Milner et al., 1997, * ISBN */ %token CASE "case" %token FUN "fun" %token MATCH "=>" %token OF %token VID %start dec %% dec: "of" "fun" fvalbind fvalbind: sfvalbind fvalbind sfvalbind sfvalbind: VID atpats = exp exp: VID "case" exp "of" match match: mrule match mrule mrule: pat "=>" exp atpats: atpat atpats atpat atpat: VID pat: VID atpat %% Motivation Approximations Shift-Resolve Parsing Ambiguity Detection Conclusion Standard ML Milner et al. [1997] Language Specification A Syntax Issue Program text Executable code Compiler

3 datatype a option = NONE SOME of a fun filter pred l = let fun filterp (x::r, l) = case (pred x) filterp ([], l) = rev l in of SOME y => filterp(r, y::l) NONE => filterp(r, l) filterp (l, []) end Motivation Approximations Shift-Resolve Parsing Ambiguity Detection Conclusion Standard ML Milner et al. [1997] A Syntax Issue Program text datatype a option = NONE SOME of a fun filter pred l = let fun filterp (x::r, l) = case (pred x) of SOME y => filterp(r, y::l) NONE => filterp(r, l) filterp ([], l) = rev l in filterp (l, []) end Executable code

4 datatype a option = NONE SOME of a fun filter pred l = let fun filterp (x::r, l) = case (pred x) filterp ([], l) = rev l in of SOME y => filterp(r, y::l) NONE => filterp(r, l) filterp (l, []) end Motivation Approximations Shift-Resolve Parsing Ambiguity Detection Conclusion Standard ML Milner et al. [1997] A Syntax Issue Program text datatype a option = NONE SOME of a fun filter pred l = let fun filterp (x::r, l) = case (pred x) of SOME y => filterp(r, y::l) NONE => filterp(r, l) filterp ([], l) = rev l in filterp (l, []) end Executable code MLton Moscow ML Poly/ML SML/NJ Error: match.sml Syntax error: replacing EQUALOP with DARROW

5 datatype a option = NONE SOME of a fun filter pred l = let fun filterp (x::r, l) = case (pred x) filterp ([], l) = rev l in of SOME y => filterp(r, y::l) NONE => filterp(r, l) filterp (l, []) end Motivation Approximations Shift-Resolve Parsing Ambiguity Detection Conclusion Standard ML Milner et al. [1997] A Syntax Issue Program text datatype a option = NONE SOME of a fun filter pred l = let fun filterp (x::r, l) = case (pred x) of SOME y => filterp(r, y::l) NONE => filterp(r, l) filterp ([], l) = rev l in filterp (l, []) end Executable code MLton Moscow ML Poly/ML SML/NJ! Toplevel input:! filterp ([], l) = rev l! ˆ! Syntax error.

6 datatype a option = NONE SOME of a fun filter pred l = let fun filterp (x::r, l) = case (pred x) filterp ([], l) = rev l in of SOME y => filterp(r, y::l) NONE => filterp(r, l) filterp (l, []) end Motivation Approximations Shift-Resolve Parsing Ambiguity Detection Conclusion Standard ML Milner et al. [1997] A Syntax Issue Program text datatype a option = NONE SOME of a fun filter pred l = let fun filterp (x::r, l) = case (pred x) of SOME y => filterp(r, y::l) NONE => filterp(r, l) filterp ([], l) = rev l in filterp (l, []) end Executable code MLton Moscow ML Poly/ML SML/NJ Error: => expected but = was found

7 datatype a option = NONE SOME of a fun filter pred l = let fun filterp (x::r, l) = case (pred x) filterp ([], l) = rev l in of SOME y => filterp(r, y::l) NONE => filterp(r, l) filterp (l, []) end Motivation Approximations Shift-Resolve Parsing Ambiguity Detection Conclusion Standard ML Milner et al. [1997] A Syntax Issue Program text datatype a option = NONE SOME of a fun filter pred l = let fun filterp (x::r, l) = case (pred x) of SOME y => filterp(r, y::l) NONE => filterp(r, l) filterp ([], l) = rev l in filterp (l, []) end Executable code MLton Moscow ML Poly/ML SML/NJ stdin: Error: syntax error: deleting EQUALOP ID

8 datatype a option = NONE SOME of a fun filter pred l = let fun filterp (x::r, l) = case (pred x) filterp ([], l) = rev l in of SOME y => filterp(r, y::l) NONE => filterp(r, l) filterp (l, []) end /** * smlfvalbind.y * * Standard ML function declarations. * See _The_definition_of_standard_ML_, Milner et al., 1997, * ISBN */ %token CASE "case" %token FUN "fun" %token MATCH "=>" %token OF %token VID %start dec %% dec: "of" "fun" fvalbind fvalbind: sfvalbind fvalbind sfvalbind sfvalbind: VID atpats = exp exp: VID "case" exp "of" match match: mrule match mrule mrule: pat "=>" exp atpats: atpat atpats atpat atpat: VID pat: VID atpat %% Motivation Approximations Shift-Resolve Parsing Ambiguity Detection Conclusion Parsers A Syntax Issue Language Specification Program text Executable code Compiler

9 datatype a option = NONE SOME of a fun filter pred l = let fun filterp (x::r, l) = case (pred x) filterp ([], l) = rev l in of SOME y => filterp(r, y::l) NONE => filterp(r, l) filterp (l, []) end /** * smlfvalbind.y * * Standard ML function declarations. * See _The_definition_of_standard_ML_, Milner et al., 1997, * ISBN */ %token CASE "case" %token FUN "fun" %token MATCH "=>" %token OF %token VID %start dec %% dec: "of" "fun" fvalbind fvalbind: sfvalbind fvalbind sfvalbind sfvalbind: VID atpats = exp exp: VID "case" exp "of" match match: mrule match mrule mrule: pat "=>" exp atpats: atpat atpats atpat atpat: VID pat: VID atpat %% Motivation Approximations Shift-Resolve Parsing Ambiguity Detection Conclusion Parsers A Syntax Issue Language Specification Program text Executable code Parser Compiler

10 /** * smlfvalbind.y * * Standard ML function declarations. * See _The_definition_of_standard_ML_, Milner et al., 1997, * ISBN */ %token CASE "case" %token FUN "fun" %token MATCH "=>" %token OF "of" %token VID %start dec %% dec: "fun" fvalbind fvalbind: sfvalbind fvalbind sfvalbind sfvalbind: VID atpats = exp "case" exp "of" match exp: VID match: mrule match mrule mrule: pat "=>" exp atpats: atpat atpats atpat atpat: VID pat: VID atpat %% Motivation Approximations Shift-Resolve Parsing Ambiguity Detection Conclusion Parsers A Syntax Issue Context-free grammar /** * smlfvalbind.y * * Standard ML function declarations. * See _The_definition_of_standard_ML_, Milner et al., 1997, * ISBN */ %token CASE "case" %token FUN "fun" %token MATCH "=>" %token OF "of" %token VID %start dec %% dec: "fun" fvalbind fvalbind: sfvalbind fvalbind sfvalbind sfvalbind: VID atpats = exp exp: VID "case" exp "of" match match: mrule match mrule mrule: pat "=>" exp atpats: atpat atpats atpat atpat: VID pat: VID atpat Parser %%

11 /** * smlfvalbind.y * * Standard ML function declarations. * See _The_definition_of_standard_ML_, Milner et al., 1997, * ISBN */ %token CASE "case" %token FUN "fun" %token MATCH "=>" %token OF "of" %token VID %start dec %% dec: "fun" fvalbind fvalbind: sfvalbind fvalbind sfvalbind sfvalbind: VID atpats = exp "case" exp "of" match exp: VID match: mrule match mrule mrule: pat "=>" exp atpats: atpat atpats atpat atpat: VID pat: VID atpat %% Motivation Approximations Shift-Resolve Parsing Ambiguity Detection Conclusion Parsers A Syntax Issue Context-free grammar... NONE => filterp(r, l) filterp ([], l ) = rev l Input tokens Parser generator Parse tree fvalbind sfvalbind exp match mrule fvalbind sfvalbind Parser... pat exp atpats exp NONE => filterp(r, l) filterp ([], l ) = rev l

12 /** * smlfvalbind.y * * Standard ML function declarations. * See _The_definition_of_standard_ML_, Milner et al., 1997, * ISBN */ %token CASE "case" %token FUN "fun" %token MATCH "=>" %token OF "of" %token VID %start dec %% dec: "fun" fvalbind fvalbind: sfvalbind fvalbind sfvalbind sfvalbind: VID atpats = exp "case" exp "of" match exp: VID match: mrule match mrule mrule: pat "=>" exp atpats: atpat atpats atpat atpat: VID pat: VID atpat %% Motivation Approximations Shift-Resolve Parsing Ambiguity Detection Conclusion Parsers A Syntax Issue Context-free grammar... NONE => filterp(r, l) filterp ([], l ) = rev l Input tokens Parser generator Parse tree fvalbind sfvalbind exp match mrule fvalbind sfvalbind Parser... pat exp atpats exp NONE => filterp(r, l) filterp ([], l ) = rev l

13 LALR(1) Parser Generator Grammar Conflicts GNU Bison state 20 6 exp: "case" exp "of" match. 8 match: match. mrule shift, and go to state 24 [reduce using rule 6 (exp)] Restricted grammar class

14 LALR(1) Parser Generator Grammar Conflicts CFG GNU Bison state 20 6 exp: "case" exp "of" match. 8 match: match. mrule shift, and go to state 24 [reduce using rule 6 (exp)] LALR(1) Restricted grammar class

15 Dealing with Conflicts An Objective Measure [Malloy et al., 2002] on a C# Grammar Grammar Conflicts _malloy.data using 1:($2+$3) LALR(1) conflicts Parser versions

16 Dealing with Conflicts A Subjective Measure Grammar Conflicts Courtesy of

17 Dealing with Conflicts A Subjective Measure Grammar Conflicts Courtesy of

18 Dealing with Conflicts A Subjective Measure Grammar Conflicts Courtesy of

19 State of the Art LR(k) [Knuth, 1965] Solutions CFG LR-Regular [Čulik and Cohen, 1973] Generalized LR [Tomita, 1986] Unambiguous CFGs [Cantor, 1962, Chomsky and Schützenberger, 1963] Horizontal and vertical unambiguity test [Brabrand et al., 2007] LR(k) LALR(1)

20 State of the Art LR(k) [Knuth, 1965] Solutions CFG LR-Regular [Čulik and Cohen, 1973] Generalized LR [Tomita, 1986] Unambiguous CFGs [Cantor, 1962, Chomsky and Schützenberger, 1963] Horizontal and vertical unambiguity test [Brabrand et al., 2007] LR-Regular LR(k) LALR(1)

21 State of the Art LR(k) [Knuth, 1965] Solutions CFG LR-Regular [Čulik and Cohen, 1973] Generalized LR [Tomita, 1986] Unambiguous CFGs [Cantor, 1962, Chomsky and Schützenberger, 1963] Horizontal and vertical unambiguity test [Brabrand et al., 2007]

22 /** * smlfvalbind.y * * Standard ML function declarations. * See _The_definition_of_standard_ML_, Milner et al., 1997, * ISBN */ %token CASE "case" %token FUN "fun" %token MATCH "=>" %token OF "of" %token VID %start dec %% dec: "fun" fvalbind fvalbind: sfvalbind fvalbind sfvalbind sfvalbind: VID atpats = exp "case" exp "of" match exp: VID match: mrule match mrule mrule: pat "=>" exp atpats: atpat atpats atpat atpat: VID pat: VID atpat %% Motivation Approximations Shift-Resolve Parsing Ambiguity Detection Conclusion Ambiguity Solutions Context-free grammar exp match mrule exp case a of b=> case b of c=> c d=> d Input tokens Parser generator Parse forest match match exp pat exp mrule mrule case a of b=> case b of c=> c d=> d exp match match mrule exp match Parser exp pat exp mrule mrule case a of b=> case b of c=> c d=> d

23 /** * smlfvalbind.y * * Standard ML function declarations. * See _The_definition_of_standard_ML_, Milner et al., 1997, * ISBN */ %token CASE "case" %token FUN "fun" %token MATCH "=>" %token OF "of" %token VID %start dec %% dec: "fun" fvalbind fvalbind: sfvalbind fvalbind sfvalbind sfvalbind: VID atpats = exp "case" exp "of" match exp: VID match: mrule match mrule mrule: pat "=>" exp atpats: atpat atpats atpat atpat: VID pat: VID atpat %% Motivation Approximations Shift-Resolve Parsing Ambiguity Detection Conclusion Ambiguity Solutions Context-free grammar exp match mrule exp case a of b=> case b of c=> c d=> d Input tokens Parser generator Parse forest match match exp pat exp mrule mrule case a of b=> case b of c=> c d=> d exp match match mrule exp match Parser exp pat exp mrule mrule case a of b=> case b of c=> c d=> d

24 State of the Art LR(k) [Knuth, 1965] Solutions CFG LR-Regular [Čulik and Cohen, 1973] Generalized LR [Tomita, 1986] Unambiguous CFGs [Cantor, 1962, Chomsky and Schützenberger, 1963] Horizontal and vertical unambiguity test [Brabrand et al., 2007] UCFG

25 State of the Art LR(k) [Knuth, 1965] Solutions CFG LR-Regular [Čulik and Cohen, 1973] Generalized LR [Tomita, 1986] Unambiguous CFGs [Cantor, 1962, Chomsky and Schützenberger, 1963] Horizontal and vertical unambiguity test [Brabrand et al., 2007] Unsafe Safe UCFG LR-Regular LR(k) LALR(1)

26 State of the Art LR(k) [Knuth, 1965] Solutions CFG LR-Regular [Čulik and Cohen, 1973] Generalized LR [Tomita, 1986] Unambiguous CFGs [Cantor, 1962, Chomsky and Schützenberger, 1963] Horizontal and vertical unambiguity test [Brabrand et al., 2007] Unsafe HVRU Safe UCFG

27 State of the Art LR(k) [Knuth, 1965] Solutions CFG LR-Regular [Čulik and Cohen, 1973] Generalized LR [Tomita, 1986] Unambiguous CFGs [Cantor, 1962, Chomsky and Schützenberger, 1963] Horizontal and vertical unambiguity test [Brabrand et al., 2007] Unsafe HVRU Safe UCFG LR-Regular LR(k) LALR(1)

28 Contributions Solutions Noncanonical parsing methods [Szymanski and Williams, 1976, Tai, 1979] Noncanonical LALR(1) Shift-Resolve Noncanonical unambiguity test Framework for grammar approximations

29 Contributions Noncanonical parsing methods [Szymanski and Williams, 1976, Tai, 1979] Noncanonical LALR(1) Shift-Resolve Noncanonical unambiguity test Solutions UCFG LR-Regular LR(k) NLALR(1) LALR(1) CFG Framework for grammar approximations

30 Contributions Noncanonical parsing methods [Szymanski and Williams, 1976, Tai, 1979] Noncanonical LALR(1) Shift-Resolve Solutions UCFG LR-Regular LR(k) ShRe CFG Noncanonical unambiguity test Framework for grammar approximations LALR(1)

31 Contributions Noncanonical parsing methods [Szymanski and Williams, 1976, Tai, 1979] Noncanonical LALR(1) Shift-Resolve Solutions HVRU UCFG NU LR-Regular LR(k) CFG Noncanonical unambiguity test Framework for grammar approximations LALR(1)

32 Contributions Noncanonical parsing methods [Szymanski and Williams, 1976, Tai, 1979] Noncanonical LALR(1) Shift-Resolve Solutions HVRU UCFG NU LR-Regular LR(k) CFG Noncanonical unambiguity test Framework for grammar approximations LALR(1)

33 Bracketed Grammars Grammar Approximations G = N, T, P, S, V = N T dec fvalbind fvalbind sfvalbind exp match match mrule atpats atpats pat atpat fun fvalbind sfvalbind fvalbind sfvalbind vid atpats = exp case exp of match mrule match mrule pat => exp atpat atpats atpat vid atpat vid

34 Bracketed Grammars Grammar Approximations G b = N, T b, P b, S, V b = N T b dec fvalbind fvalbind sfvalbind exp match match mrule atpats atpats pat atpat 1 d 1 fun fvalbind r 1 2 d 2 sfvalbind r 2 3 d 3 fvalbind sfvalbind r 3 4 d 4 vid atpats = exp r 4 5 d 5 case exp of match r 5 6 d 6 mrule r 6 7 d 7 match mrule r 7 8 d 8 pat => exp r 8 9 d 9 atpat r 9 10 d 10 atpats atpat r d 11 vid atpat r d 12 vid r 12

35 Positions Grammar Approximations fvalbind fvalbind sfvalbind sfvalbind vid atpats = exp d 3 d 2 sfvalbind r 2 d4 vid atpats = exp r 4 r 3

36 Position Graph Γ Left-to-right Walks in Trees Grammar Approximations fvalbind fvalbind sfvalbind d 4 vid sfvalbind atpats = exp d 3 d 2 sfvalbind r 2 d 4 vid atpats = exp r 4 r 3

37 Position Graph Γ Left-to-right Walks in Trees Grammar Approximations fvalbind fvalbind sfvalbind sfvalbind sfvalbind vid atpats = exp d 3 d 2 sfvalbind r 2 d 4 vid atpats = exp r 4 r3

38 Position Graph Γ Left-to-right Walks in Trees Grammar Approximations fvalbind r 3 fvalbind sfvalbind sfvalbind vid atpats = exp d 3 d 2 sfvalbind r 2 d 4 vid atpats = exp r 4 r 3

39 Position Graph Γ Left-to-right Walks in Trees Grammar Approximations... fvalbind d 3 r 3 fvalbind sfvalbind r 4 d 2 sfvalbind r 2 d 4 vid atpats = exp

40 Position Automaton Γ/ Grammar Approximations Definition Γ/ is the quotient of Γ by an equivalence relation between positions. Theorem (Language over-approximation) L(G b ) L(Γ/ ) T b

41 Example: item 0 Equivalence Grammar Approximations fvalbind d 3 r 3 fvalbind sfvalbind r 4 d 2 sfvalbind r 2 d 4 vid atpats = exp r 4 d 4 vid atpats = exp equivalence class [ sfvalbind vid atpats 4 = exp ] LR(0) items Γ/item 0 : nondeterministic LR(0) automaton

42 Example: item 0 Equivalence [ fvalbind sfvalbind ] 2 [ fvalbind fvalbind 3 sfvalbind ] Grammar Approximations d 4 d 4 [ sfvalbind vid 4 atpats = exp ] vid [ sfvalbind vid atpats 4 = exp ] atpats [ sfvalbind 4 vid atpats = exp ] = [ sfvalbind 4 vid atpats = exp ] exp [ sfvalbind 4 vid atpats = exp ] r 4 [ fvalbind 2 sfvalbind ] r 4 [ fvalbind 3 fvalbind sfvalbind ]

43 Summary Grammar Approximations general framework for approximations applications: parser construction ambiguity detection XML validation [Segoufin and Vianu, 2002]? symbolic supertagging [Boullier, 2003]?

44 Summary Grammar Approximations general framework for approximations applications: parser construction ambiguity detection XML validation [Segoufin and Vianu, 2002]? symbolic supertagging [Boullier, 2003]?

45 Shift-Resolve Parsing Parsing Principles noncanonical k = 1 reduced lookahead symbol resolve = reduce + pushback: emulates a bounded reduced lookahead without any preset bound

46 Shift-Resolve Parsing Parsing Principles noncanonical k = 1 reduced lookahead symbol resolve = reduce + pushback: emulates a bounded reduced lookahead without any preset bound

47 Shift-Resolve Parse Parsing Example fvalbind fvalbind sfvalbind exp sfvalbind atpats exp... NONE=> filterp(r, l) filterp ([], l ) = rev l

48 Shift-Resolve Parse Parsing Example fvalbind fvalbind sfvalbind exp match mrule sfvalbind pat exp atpats exp... NONE=> filterp(r, l) filterp ([], l ) = rev l

49 Shift-Resolve Parse Parsing Example fvalbind fvalbind sfvalbind exp match mrule sfvalbind pat exp atpats exp... NONE=> filterp(r, l) filterp ([], l ) = rev l

50 Shift-Resolve Parse Parsing Example fvalbind fvalbind sfvalbind exp match mrule sfvalbind pat exp atpats exp... NONE=> filterp(r, l) filterp ([], l ) = rev l

51 Shift-Resolve Parse Parsing Example fvalbind fvalbind sfvalbind exp match mrule sfvalbind pat exp atpats exp... NONE=> filterp(r, l) filterp ([], l ) = rev l

52 Shift-Resolve Parse Parsing Example fvalbind fvalbind sfvalbind exp match mrule sfvalbind pat exp atpats exp... NONE=> filterp(r, l) filterp ([], l ) = rev l

53 Generating the Parser Parser Construction 1. position automaton 2. determinization by subset construction

54 Subset Construction Principle Parser Construction d i transitions denote traditional item closures r i transitions denote a phrase that should be reduced other transitions denote shifts items in the construction hold 1. a state of the position automaton 2. a parsing action 3. a pushback length

55 Subset Construction Principle Parser Construction d i transitions denote traditional item closures r i transitions denote a phrase that should be reduced other transitions denote shifts items in the construction hold 1. a state of the position automaton 2. a parsing action 3. a pushback length

56 Subset Construction Example Parser Construction exp case exp of match, 0, 0 match match mrule, 0, 0

57 Subset Construction Example Parser Construction r 5 exp case exp of match, 0, 0 match match mrule, 0, 0 sfvalbind vid atpats = exp, 5, 0

58 Subset Construction Example Parser Construction r 4 exp case exp of match, 0, 0 match match mrule, 0, 0 sfvalbind vid atpats = exp, 5, 0 fvalbind fvalbind sfvalbind, 5, 0 fvalbind sfvalbind, 5, 0

59 Subset Construction Example Parser Construction exp case exp of match, 0, 0 match match mrule, 0, 0 sfvalbind vid atpats = exp, 5, 0 fvalbind fvalbind sfvalbind, 5, 0 fvalbind sfvalbind, 5, 0 fvalbind fvalbind sfvalbind, 5, 0 dec fun fvalbind, 5, 0 S dec $, 5, 0

60 Subset Construction Example Parser Construction exp case exp of match, 0, 0 match match mrule, 0, 0 sfvalbind vid atpats = exp, 5, 0 fvalbind fvalbind sfvalbind, 5, 0 fvalbind sfvalbind, 5, 0 fvalbind fvalbind sfvalbind, 5, 0 dec fun fvalbind, 5, 0 S dec $, 5, 0

61 Subset Construction Example Parser Construction exp case exp of match, 0, 0 match match mrule, 0, 0 sfvalbind vid atpats = exp, 5, 0 fvalbind fvalbind sfvalbind, 5, 0 fvalbind sfvalbind, 5, 0 fvalbind fvalbind sfvalbind, 5, 0 dec fun fvalbind, 5, 0 S dec $, 5, 0 fvalbind fvalbind sfvalbind, 5, 1 match match mrule, 0, 0

62 Subset Construction Example exp case exp of match, 0, 0 match match mrule, 0, 0 sfvalbind vid atpats = exp, 5, 0 fvalbind fvalbind sfvalbind, 5, 0 fvalbind sfvalbind, 5, 0 fvalbind fvalbind sfvalbind, 5, 0 dec fun fvalbind, 5, 0 S dec $, 5, 0 Parser Construction d 8 fvalbind fvalbind sfvalbind, 5, 1 match match mrule, 0, 0 mrule pat => exp, 0, 0

63 Subset Construction Example exp case exp of match, 0, 0 match match mrule, 0, 0 sfvalbind vid atpats = exp, 5, 0 fvalbind fvalbind sfvalbind, 5, 0 fvalbind sfvalbind, 5, 0 fvalbind fvalbind sfvalbind, 5, 0 dec fun fvalbind, 5, 0 S dec $, 5, 0 Parser Construction fvalbind fvalbind sfvalbind, 5, 1 match match mrule, 0, 0 mrule pat => exp, 0, 0 pat vid atpat, 0, 0 sfvalbind vid atpats = exp, 0, 0

64 Construction Failure Parser Construction exp case exp of match, 0, 0 match match mrule, 0, 0 sfvalbind vid atpats = exp, 5, 0 fvalbind fvalbind sfvalbind, 5, 0 fvalbind sfvalbind, 5, 0 fvalbind fvalbind sfvalbind, 5, 0 dec fun fvalbind, 5, 0 S dec $, 5, 0

65 Construction Failure Parser Construction r 5 exp case exp of match, 0, 0 match match mrule, 0, 0 sfvalbind vid atpats = exp, 5, 0 fvalbind fvalbind sfvalbind, 5, 0 fvalbind sfvalbind, 5, 0 fvalbind fvalbind sfvalbind, 5, 0 dec fun fvalbind, 5, 0 S dec $, 5, 0 mrule pat exp, 5, 0

66 Construction Failure Parser Construction exp case exp of match, 0, 0 match match mrule, 0, 0 sfvalbind vid atpats = exp, 5, 0 fvalbind fvalbind sfvalbind, 5, 0 fvalbind sfvalbind, 5, 0 fvalbind fvalbind sfvalbind, 5, 0 dec fun fvalbind, 5, 0 S dec $, 5, 0 mrule pat exp, 5, 0 match mrule, 5, 0 match match mrule, 5, 0

67 Complexity Parser Construction Γ/ : size of the position automaton A : size of the parser: O(2 Γ/ P ) parsing time complexity for input w: O( w )

68 Complexity Parser Construction Γ/ : size of the position automaton Γ/item 0 = O( G ) A : size of the parser: O(2 Γ/ P ) parsing time complexity for input w: O( w )

69 Limitations Parser Construction incomparable with classical parsing techniques + subset construction mendable

70 Limitations Parser Construction incomparable with classical parsing techniques + subset construction mendable

71 Summary Parser Construction Shift Resolve parsers 1. Large class of grammars accepted 2. Unambiguity 3. Linear time parsing 2-steps construction 1. Simple 2. Flexible

72 Principles a bracketed sentence = a derivation tree ambiguity = more than one tree with the same yield d 6 d 8 d 13 vid r 13 => d 5 case d 14 vid r 14 of d 7 d 6 d 8 d 13 vid r 13 => d 14 vid r 14 r 8 r 6 d 8 d 13 vid r 13 => d 14 vid r 14 r 8 r 7 r 5 r 8 r 6 d 7 d 6 d 8 d 13 vid r 13 => d 5 case d 14 vid r 14 of d 7 d 8 d 13 vid r 13 => d 14 vid r 14 r 8 r 7 r 5 r 8 r 6 d 8 d 13 vid r 13 => d 14 vid r 14 r 8 r 7 construct a FSA A such that L(G b ) L(A), and look for bracketed sentences with the same yield

73 Principles a bracketed sentence = a derivation tree ambiguity = more than one tree with the same yield d 6 d 8 d 13 vid r 13 => d 5 case d 14 vid r 14 of d 7 d 6 d 8 d 13 vid r 13 => d 14 vid r 14 r 8 r 6 d 8 d 13 vid r 13 => d 14 vid r 14 r 8 r 7 r 5 r 8 r 6 d 7 d 6 d 8 d 13 vid r 13 => d 5 case d 14 vid r 14 of d 7 d 8 d 13 vid r 13 => d 14 vid r 14 r 8 r 7 r 5 r 8 r 6 d 8 d 13 vid r 13 => d 14 vid r 14 r 8 r 7 construct a FSA A such that L(G b ) L(A), and look for bracketed sentences with the same yield

74 Principles a bracketed sentence = a derivation tree ambiguity = more than one tree with the same yield d 6 d 8 d 13 vid r 13 => d 5 case d 14 vid r 14 of d 7 d 6 d 8 d 13 vid r 13 => d 14 vid r 14 r 8 r 6 d 8 d 13 vid r 13 => d 14 vid r 14 r 8 r 7 r 5 r 8 r 6 d 7 d 6 d 8 d 13 vid r 13 => d 5 case d 14 vid r 14 of d 7 d 8 d 13 vid r 13 => d 14 vid r 14 r 8 r 7 r 5 r 8 r 6 d 8 d 13 vid r 13 => d 14 vid r 14 r 8 r 7 construct a FSA A such that L(G b ) L(A), and look for bracketed sentences with the same yield

75 RU( ) Regular Unambiguity G is regular unambiguous for of finite index, if there does not exist w b w b in L(Γ/ ) T b with h(w b ) = h(w b ) LR(0) RU(item 0 ) regular approximations are too weak

76 RU( ) Regular Unambiguity G is regular unambiguous for of finite index, if there does not exist w b w b in L(Γ/ ) T b with h(w b ) = h(w b ) LR(0) RU(item 0 ) regular approximations are too weak

77 Nonterminal Transitions Noncanonical Unambiguity SF(G b ) L(Γ/ ) look for two different bracketed sentential forms in L(Γ/ ) d 6 d 8 pat => d 5 case exp of d 7 match mrules r 7 r 5 r 8 r 6 d 7 d 6 d 8 pat => d 5 case exp of match r 5 r 8 r 6 mrules r 7 a nonterminal transition represents exactly its derived context-free language

78 Nonterminal Transitions Noncanonical Unambiguity SF(G b ) L(Γ/ ) look for two different bracketed sentential forms in L(Γ/ ) d 6 d 8 pat => d 5 case exp of d 7 match mrules r 7 r 5 r 8 r 6 d 7 d 6 d 8 pat => d 5 case exp of match r 5 r 8 r 6 mrules r 7 a nonterminal transition represents exactly its derived context-free language

79 Nonterminal Transitions Noncanonical Unambiguity SF(G b ) L(Γ/ ) look for two different bracketed sentential forms in L(Γ/ ) d 6 d 8 pat => d 5 case exp of d 7 match mrules r 7 r 5 r 8 r 6 d 7 d 6 d 8 pat => d 5 case exp of match r 5 r 8 r 6 mrules r 7 a nonterminal transition represents exactly its derived context-free language

80 Mutual Accessibility Relations between pairs of states of Γ/, (q 1, q 2 ) Noncanonical Unambiguity synchronized left-to-right walks from an initial pair (q s, q s ) d 6 d 8 d 14 vid r 14 => d 5 case exp of d 7 match mrules r 7 r 5 r 8 r 6 d 7 d 6 d 8 d 14 vid r 14 => d 5 case exp of match r 5 r 8 r 6 mrules r 7 epsilon: mae

81 Mutual Accessibility Relations between pairs of states of Γ/, (q 1, q 2 ) Noncanonical Unambiguity synchronized left-to-right walks from an initial pair (q s, q s ) d 6 d 8 d 14 vid r 14 => d 5 case exp of d 7 match mrules r 7 r 5 r 8 r 6 d 7 d 6 d 8 d 14 vid r 14 => d 5 case exp of match r 5 r 8 r 6 mrules r 7 epsilon: mae

82 Mutual Accessibility Relations between pairs of states of Γ/, (q 1, q 2 ) Noncanonical Unambiguity synchronized left-to-right walks from an initial pair (q s, q s ) d 6 d 8 d 14 vid r 14 => d 5 case exp of d 7 match mrules r 7 r 5 r 8 r 6 d 7 d 6 d 8 d 14 vid r 14 => d 5 case exp of match r 5 r 8 r 6 mrules r 7 epsilon: mae

83 Mutual Accessibility Relations between pairs of states of Γ/, (q 1, q 2 ) Noncanonical Unambiguity synchronized left-to-right walks from an initial pair (q s, q s ) d 6 d 8 d 14 vid r 14 => d 5 case exp of d 7 match mrules r 7 r 5 r 8 r 6 d 7 d 6 d 8 d 14 vid r 14 => d 5 case exp of match r 5 r 8 r 6 mrules r 7 shift: mas

84 Mutual Accessibility Relations between pairs of states of Γ/, (q 1, q 2 ) Noncanonical Unambiguity synchronized left-to-right walks from an initial pair (q s, q s ) d 6 d 8 d 14 vid r 14 => d 5 case exp of d 7 match mrules r 7 r 5 r 8 r 6 d 7 d 6 d 8 d 14 vid r 14 => d 5 case exp of match r 5 r 8 r 6 mrules r 7 nothing!

85 Mutual Accessibility Relations between pairs of states of Γ/, (q 1, q 2 ) Noncanonical Unambiguity synchronized left-to-right walks from an initial pair (q s, q s ) d 6 d 8 pat => d 5 case exp of d 7 match mrules r 7 r 5 r 8 r 6 d 7 d 6 d 8 pat => d 5 case exp of match r 5 r 8 r 6 mrules r 7 shift: mas

86 Mutual Accessibility Relations between pairs of states of Γ/, (q 1, q 2 ) Noncanonical Unambiguity synchronized left-to-right walks from an initial pair (q s, q s ) d 6 d 8 pat => d 5 case exp of d 7 match mrules r 7 r 5 r 8 r 6 d 7 d 6 d 8 pat => d 5 case exp of match r 5 r 8 r 6 mrules r 7 conflict: mac

87 Mutual Accessibility Relations between pairs of states of Γ/, (q 1, q 2 ) Noncanonical Unambiguity synchronized left-to-right walks from an initial pair (q s, q s ) d 6 d 8 pat => d 5 case exp of d 7 match mrules r 7 r 5 r 8 r 6 d 7 d 6 d 8 pat => d 5 case exp of match r 5 r 8 r 6 mrules r 7 conflict: mac

88 Mutual Accessibility Relations between pairs of states of Γ/, (q 1, q 2 ) Noncanonical Unambiguity synchronized left-to-right walks from an initial pair (q s, q s ) d 6 d 8 pat => d 5 case exp of d 7 match mrules r 7 r 5 r 8 r 6 d 7 d 6 d 8 pat => d 5 case exp of match r 5 r 8 r 6 mrules r 7 conflict: mac

89 Mutual Accessibility Relations between pairs of states of Γ/, (q 1, q 2 ) Noncanonical Unambiguity synchronized left-to-right walks from an initial pair (q s, q s ) d 6 d 8 pat => d 5 case exp of d 7 match mrules r 7 r 5 r 8 r 6 d 7 d 6 d 8 pat => d 5 case exp of match r 5 r 8 r 6 mrules r 7 shift: mas

90 Mutual Accessibility Relations between pairs of states of Γ/, (q 1, q 2 ) Noncanonical Unambiguity synchronized left-to-right walks from an initial pair (q s, q s ) d 6 d 8 pat => d 5 case exp of d 7 match mrules r 7 r 5 r 8 r 6 d 7 d 6 d 8 pat => d 5 case exp of match r 5 r 8 r 6 mrules r 7 reduce: mar

91 Mutual Accessibility Relations between pairs of states of Γ/, (q 1, q 2 ) Noncanonical Unambiguity synchronized left-to-right walks from an initial pair (q s, q s ) d 6 d 8 pat => d 5 case exp of d 7 match mrules r 7 r 5 r 8 r 6 d 7 d 6 d 8 pat => d 5 case exp of match r 5 r 8 r 6 mrules r 7 conflict: mac

92 NU( ) Noncanonical Unambiguity ma=mas mae mac mar G is noncanonically unambiguous if there does not exist a relation (q s, q s ) ma (q f, q f ) that uses mac at some step Computation in O( Γ/ 2 ) in space

93 Comparisons Noncanonical Unambiguity Regular Unambiguity RU( ) Bounded-length detection schemes LR(k) and LR-Regular (LR(Π)) Horizontal and vertical ambiguity (HVRU( ))

94 Bounded-length detection [Gorn, 1963, Cheung and Uzgalis, 1995, Schröer, 2001, Jampana, 2005] Noncanonical Unambiguity generate sentences not conservative prefix m prevents from false positives in sentences of length < m need to generate a 2n +1 to find G n 4 ambiguous, but G n 4 NU(item 0) S A B n a, A Aaa a, B 1 aa, B 2 B 1 B 1,..., B n B n 1 B n 1 (G n 4 )

95 LR(k) and LR-Regular Noncanonical Unambiguity [Knuth, 1965, Hunt III et al., 1975, Čulik and Cohen, 1973, Heilbrunner, 1983] conservative tests define item Π s.t. LR(Π) NU(item Π ) need a LR(2 n ) test to prove G n 3 unambiguous, but G n 3 NU(item 0) S A B n, A Aaa a, B 1 aa, B 2 B 1 B 1,..., B n B n 1 B n 1 (G n 3 )

96 Implementation For the whole SML grammar: Experimental Results conflicts in the LALR(1) parser sml.y: conflicts: 223 shift/reduce, 35 reduce/reduce Our tool: 89 potential ambiguities with LR(1) precision detected For the SML grammar fragment: 2 potential ambiguities with LR(0) precision detected: (match -> mrule., match -> match. mrule ) (match -> match. mrule, match -> match mrule. ) NU(item 1 ) correctly identifies 87% of our unambiguous grammars 73% of the non-lalr(1) ones

97 Summary Experimental Results conservative ambiguity detection provably better than several other techniques also experimentally better

98 Conclusion Closing Comments Main issues in parser development: nondeterminism ambiguity in particular Deterministic parsers for larger classes of grammars Ambiguity detection algorithm

99 Directions for Future Work Future Work Linear time parsing for NU( ) grammars? Improved implementation Noncanonical languages Regular approximations

100 Future Work Thanks!

101 References Our Issue Shift/Reduce Conflict GNU Bison state 20 6 exp: "case" exp "of" match. 8 match: match. mrule shift, and go to state 24 [reduce using rule 6 (exp)]

102 References Our Issue Shift/Reduce Conflict Which action to choose? fvalbind match match mrule mrule pat exp pat exp... of SOME y => filterp(r, y :: l ) NONE => filterp(r, l)

103 References Our Issue Shift/Reduce Conflict Which action to choose? Reduce? fvalbind sfvalbind exp match mrule sfvalbind... pat exp error! vid of SOME y => filterp(r, y :: l ) NONE => filterp(r, l)

104 References Our Issue Shift/Reduce Conflict Which action to choose? Shift? fvalbind match match mrule mrule pat exp pat exp... of SOME y => filterp(r, y :: l ) NONE => filterp(r, l)

105 References Our Issue Shift/Reduce Conflict Which action to choose? fvalbind fvalbind sfvalbind exp match mrule sfvalbind pat exp atpats exp... NONE=> filterp(r, l) filterp ([], l ) = rev l

106 References Our Issue Shift/Reduce Conflict Which action to choose? Reduce? fvalbind fvalbind sfvalbind exp match mrule sfvalbind pat exp atpats exp... NONE=> filterp(r, l) filterp ([], l ) = rev l

107 References Our Issue Shift/Reduce Conflict Which action to choose? Shift? fvalbind fvalbind sfvalbind exp match match mrule... pat exp pat exp error! NONE=> filterp(r, l) filterp ([], l ) = rev l fvalbind

108 References Unbounded Lookahead sfvb mrule vid atpats =... pat =>... atpat vid atpat......

109 References Limitations Ambiguity Report grambiguity [Brabrand et al., 2007] *** horizontal ambiguity at E[plus]: Exp <--> + Exp ambiguous string: "x+x+x" ANTLRWorks [Parr, 2007]

110 References Other Limitations memory requirements: a solution could be a NLALR test dynamic disambiguation: inverse problem, some means to deciding equivalence needed

111 References H. J. S. Basten. Ambiguity detection methods for context-free grammars. Master s thesis, Centrum voor Wiskunde en Informatica, Universiteit van Amsterdam, Aug P. Boullier. Supertagging: A non-statistical parsing-based approach. In IWPT 03, pages 55 65, URL ftp://ftp.inria.fr/inria/projects/atoll/ Pierre.Boullier/supertaggeur final.pdf. C. Brabrand, R. Giegerich, and A. Møller. Analyzing ambiguity of context-free grammars. In J. Holub and J. Žd árek, editors, CIAA 07, URL brabrand/grambiguity/. To appear in Lecture Notes in Computer Science. D. G. Cantor. On the ambiguity problem of Backus

If-Then-Else Problem (a motivating example for LR grammars)

If-Then-Else Problem (a motivating example for LR grammars) If-Then-Else Problem (a motivating example for LR grammars) If x then y else z If a then if b then c else d this is analogous to a bracket notation when left brackets >= right brackets: [ [ ] ([ i ] j,

More information

CS143 Handout 08 Summer 2008 July 02, 2007 Bottom-Up Parsing

CS143 Handout 08 Summer 2008 July 02, 2007 Bottom-Up Parsing CS143 Handout 08 Summer 2008 July 02, 2007 Bottom-Up Parsing Handout written by Maggie Johnson and revised by Julie Zelenski. Bottom-up parsing As the name suggests, bottom-up parsing works in the opposite

More information

Pushdown automata. Informatics 2A: Lecture 9. Alex Simpson. 3 October, 2014. School of Informatics University of Edinburgh [email protected].

Pushdown automata. Informatics 2A: Lecture 9. Alex Simpson. 3 October, 2014. School of Informatics University of Edinburgh als@inf.ed.ac. Pushdown automata Informatics 2A: Lecture 9 Alex Simpson School of Informatics University of Edinburgh [email protected] 3 October, 2014 1 / 17 Recap of lecture 8 Context-free languages are defined by context-free

More information

How to make the computer understand? Lecture 15: Putting it all together. Example (Output assembly code) Example (input program) Anatomy of a Computer

How to make the computer understand? Lecture 15: Putting it all together. Example (Output assembly code) Example (input program) Anatomy of a Computer How to make the computer understand? Fall 2005 Lecture 15: Putting it all together From parsing to code generation Write a program using a programming language Microprocessors talk in assembly language

More information

Bottom-Up Syntax Analysis LR - metódy

Bottom-Up Syntax Analysis LR - metódy Bottom-Up Syntax Analysis LR - metódy Ján Šturc Shift-reduce parsing LR methods (Left-to-right, Righ most derivation) SLR, Canonical LR, LALR Other special cases: Operator-precedence parsing Backward deterministic

More information

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing The scanner (or lexical analyzer) of a compiler processes the source program, recognizing

More information

Syntaktická analýza. Ján Šturc. Zima 208

Syntaktická analýza. Ján Šturc. Zima 208 Syntaktická analýza Ján Šturc Zima 208 Position of a Parser in the Compiler Model 2 The parser The task of the parser is to check syntax The syntax-directed translation stage in the compiler s front-end

More information

Introduction. Compiler Design CSE 504. Overview. Programming problems are easier to solve in high-level languages

Introduction. Compiler Design CSE 504. Overview. Programming problems are easier to solve in high-level languages Introduction Compiler esign CSE 504 1 Overview 2 3 Phases of Translation ast modifled: Mon Jan 28 2013 at 17:19:57 EST Version: 1.5 23:45:54 2013/01/28 Compiled at 11:48 on 2015/01/28 Compiler esign Introduction

More information

Scanning and parsing. Topics. Announcements Pick a partner by Monday Makeup lecture will be on Monday August 29th at 3pm

Scanning and parsing. Topics. Announcements Pick a partner by Monday Makeup lecture will be on Monday August 29th at 3pm Scanning and Parsing Announcements Pick a partner by Monday Makeup lecture will be on Monday August 29th at 3pm Today Outline of planned topics for course Overall structure of a compiler Lexical analysis

More information

Scanner. tokens scanner parser IR. source code. errors

Scanner. tokens scanner parser IR. source code. errors Scanner source code tokens scanner parser IR errors maps characters into tokens the basic unit of syntax x = x + y; becomes = + ; character string value for a token is a lexeme

More information

Bottom-Up Parsing. An Introductory Example

Bottom-Up Parsing. An Introductory Example Bottom-Up Parsing Bottom-up parsing is more general than top-down parsing Just as efficient Builds on ideas in top-down parsing Bottom-up is the preferred method in practice Reading: Section 4.5 An Introductory

More information

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. CSC467 Compilers and Interpreters Fall Semester, 2005

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. CSC467 Compilers and Interpreters Fall Semester, 2005 University of Toronto Department of Electrical and Computer Engineering Midterm Examination CSC467 Compilers and Interpreters Fall Semester, 2005 Time and date: TBA Location: TBA Print your name and ID

More information

A Programming Language Where the Syntax and Semantics Are Mutable at Runtime

A Programming Language Where the Syntax and Semantics Are Mutable at Runtime DEPARTMENT OF COMPUTER SCIENCE A Programming Language Where the Syntax and Semantics Are Mutable at Runtime Christopher Graham Seaton A dissertation submitted to the University of Bristol in accordance

More information

Formal Grammars and Languages

Formal Grammars and Languages Formal Grammars and Languages Tao Jiang Department of Computer Science McMaster University Hamilton, Ontario L8S 4K1, Canada Bala Ravikumar Department of Computer Science University of Rhode Island Kingston,

More information

Compiler I: Syntax Analysis Human Thought

Compiler I: Syntax Analysis Human Thought Course map Compiler I: Syntax Analysis Human Thought Abstract design Chapters 9, 12 H.L. Language & Operating Sys. Compiler Chapters 10-11 Virtual Machine Software hierarchy Translator Chapters 7-8 Assembly

More information

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, 2010. Class 4 Nancy Lynch

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, 2010. Class 4 Nancy Lynch 6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, 2010 Class 4 Nancy Lynch Today Two more models of computation: Nondeterministic Finite Automata (NFAs)

More information

Joint Tactical Radio System Standard. JTRS Platform Adapter Interface Standard Version 1.3.3

Joint Tactical Radio System Standard. JTRS Platform Adapter Interface Standard Version 1.3.3 Joint Tactical Radio System Standard JTRS Platform Adapter Interface Standard Version: 1.3.3 Statement A- Approved for public release; distribution is unlimited (17 July 2013). i Revision History Version

More information

Lecture 9. Semantic Analysis Scoping and Symbol Table

Lecture 9. Semantic Analysis Scoping and Symbol Table Lecture 9. Semantic Analysis Scoping and Symbol Table Wei Le 2015.10 Outline Semantic analysis Scoping The Role of Symbol Table Implementing a Symbol Table Semantic Analysis Parser builds abstract syntax

More information

Unified Language for Network Security Policy Implementation

Unified Language for Network Security Policy Implementation Unified Language for Network Security Policy Implementation Dmitry Chernyavskiy Information Security Faculty National Research Nuclear University MEPhI Moscow, Russia [email protected] Natalia Miloslavskaya

More information

Compiler Construction

Compiler Construction Compiler Construction Niklaus Wirth This is a slightly revised version of the book published by Addison-Wesley in 1996 ISBN 0-201-40353-6 Zürich, February 2014 Preface This book has emerged from my lecture

More information

The Halting Problem is Undecidable

The Halting Problem is Undecidable 185 Corollary G = { M, w w L(M) } is not Turing-recognizable. Proof. = ERR, where ERR is the easy to decide language: ERR = { x { 0, 1 }* x does not have a prefix that is a valid code for a Turing machine

More information

Compiler Design July 2004

Compiler Design July 2004 irst Prev Next Last CS432/CSL 728: Compiler Design July 2004 S. Arun-Kumar [email protected] Department of Computer Science and ngineering I. I.. Delhi, Hauz Khas, New Delhi 110 016. July 30, 2004

More information

SRM UNIVERSITY FACULTY OF ENGINEERING & TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF SOFTWARE ENGINEERING COURSE PLAN

SRM UNIVERSITY FACULTY OF ENGINEERING & TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF SOFTWARE ENGINEERING COURSE PLAN Course Code : CS0355 SRM UNIVERSITY FACULTY OF ENGINEERING & TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF SOFTWARE ENGINEERING COURSE PLAN Course Title : THEORY OF COMPUTATION Semester : VI Course : June

More information

CS5310 Algorithms 3 credit hours 2 hours lecture and 2 hours recitation every week

CS5310 Algorithms 3 credit hours 2 hours lecture and 2 hours recitation every week CS5310 Algorithms 3 credit hours 2 hours lecture and 2 hours recitation every week This course is a continuation of the study of data structures and algorithms, emphasizing methods useful in practice.

More information

Computer Architecture Syllabus of Qualifying Examination

Computer Architecture Syllabus of Qualifying Examination Computer Architecture Syllabus of Qualifying Examination PhD in Engineering with a focus in Computer Science Reference course: CS 5200 Computer Architecture, College of EAS, UCCS Created by Prof. Xiaobo

More information

Intel Assembler. Project administration. Non-standard project. Project administration: Repository

Intel Assembler. Project administration. Non-standard project. Project administration: Repository Lecture 14 Project, Assembler and Exam Source code Compiler phases and program representations Frontend Lexical analysis (scanning) Backend Immediate code generation Today Project Emma Söderberg Revised

More information

CSCI 3136 Principles of Programming Languages

CSCI 3136 Principles of Programming Languages CSCI 3136 Principles of Programming Languages Faculty of Computer Science Dalhousie University Winter 2013 CSCI 3136 Principles of Programming Languages Faculty of Computer Science Dalhousie University

More information

Compiler Construction

Compiler Construction Compiler Construction Regular expressions Scanning Görel Hedin Reviderad 2013 01 23.a 2013 Compiler Construction 2013 F02-1 Compiler overview source code lexical analysis tokens intermediate code generation

More information

Model 2.4 Faculty member + student

Model 2.4 Faculty member + student Model 2.4 Faculty member + student Course syllabus for Formal languages and Automata Theory. Faculty member information: Name of faculty member responsible for the course Office Hours Office Number Email

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design i About the Tutorial A compiler translates the codes written in one language to some other language without changing the meaning of the program. It is also expected that a compiler should make the target

More information

SML/NJ Language Processing Tools: User Guide. Aaron Turon [email protected] John Reppy [email protected]

SML/NJ Language Processing Tools: User Guide. Aaron Turon adrassi@gmail.com John Reppy jhr@cs.chicago.edu SML/NJ Language Processing Tools: User Guide Aaron Turon [email protected] John Reppy [email protected] Revised: February 2015 ii Copyright c 2011. Fellowship of SML/NJ. All rights reserved. This document

More information

The Optimum One-Pass Strategy for Juliet

The Optimum One-Pass Strategy for Juliet Master s Thesis One-Pass Strategies for Context-Free Games Christian Cöster August 2015 Examiners: Prof. Dr. Thomas Schwentick Prof. Dr. Christoph Buchheim Technische Universität Dortmund Fakultät für

More information

Course Manual Automata & Complexity 2015

Course Manual Automata & Complexity 2015 Course Manual Automata & Complexity 2015 Course code: Course homepage: Coordinator: Teachers lectures: Teacher exercise classes: Credits: X_401049 http://www.cs.vu.nl/~tcs/ac prof. dr. W.J. Fokkink home:

More information

1. Nondeterministically guess a solution (called a certificate) 2. Check whether the solution solves the problem (called verification)

1. Nondeterministically guess a solution (called a certificate) 2. Check whether the solution solves the problem (called verification) Some N P problems Computer scientists have studied many N P problems, that is, problems that can be solved nondeterministically in polynomial time. Traditionally complexity question are studied as languages:

More information

Turing Machines: An Introduction

Turing Machines: An Introduction CIT 596 Theory of Computation 1 We have seen several abstract models of computing devices: Deterministic Finite Automata, Nondeterministic Finite Automata, Nondeterministic Finite Automata with ɛ-transitions,

More information

CS 341: Foundations of Computer Science II elearning Section Syllabus, Spring 2015

CS 341: Foundations of Computer Science II elearning Section Syllabus, Spring 2015 CS 341: Foundations of Computer Science II elearning Section Syllabus, Spring 2015 Course Info Instructor: Prof. Marvin K. Nakayama Office: GITC 4312 Phone: 973-596-3398 E-mail: [email protected] (Be sure

More information

Context free grammars and predictive parsing

Context free grammars and predictive parsing Context free grammars and predictive parsing Programming Language Concepts and Implementation Fall 2012, Lecture 6 Context free grammars Next week: LR parsing Describing programming language syntax Ambiguities

More information

Implementation of Recursively Enumerable Languages using Universal Turing Machine in JFLAP

Implementation of Recursively Enumerable Languages using Universal Turing Machine in JFLAP International Journal of Information and Computation Technology. ISSN 0974-2239 Volume 4, Number 1 (2014), pp. 79-84 International Research Publications House http://www. irphouse.com /ijict.htm Implementation

More information

Ambiguity, closure properties, Overview of ambiguity, and Chomsky s standard form

Ambiguity, closure properties, Overview of ambiguity, and Chomsky s standard form Ambiguity, closure properties, and Chomsky s normal form Overview of ambiguity, and Chomsky s standard form The notion of ambiguity Convention: we assume that in every substitution, the leftmost remaining

More information

Today s Agenda. Automata and Logic. Quiz 4 Temporal Logic. Introduction Buchi Automata Linear Time Logic Summary

Today s Agenda. Automata and Logic. Quiz 4 Temporal Logic. Introduction Buchi Automata Linear Time Logic Summary Today s Agenda Quiz 4 Temporal Logic Formal Methods in Software Engineering 1 Automata and Logic Introduction Buchi Automata Linear Time Logic Summary Formal Methods in Software Engineering 2 1 Buchi Automata

More information

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Formal Languages and Automata Theory - Regular Expressions and Finite Automata - Formal Languages and Automata Theory - Regular Expressions and Finite Automata - Samarjit Chakraborty Computer Engineering and Networks Laboratory Swiss Federal Institute of Technology (ETH) Zürich March

More information

SOLUTION Trial Test Grammar & Parsing Deficiency Course for the Master in Software Technology Programme Utrecht University

SOLUTION Trial Test Grammar & Parsing Deficiency Course for the Master in Software Technology Programme Utrecht University SOLUTION Trial Test Grammar & Parsing Deficiency Course for the Master in Software Technology Programme Utrecht University Year 2004/2005 1. (a) LM is a language that consists of sentences of L continued

More information

LZ77. Example 2.10: Let T = badadadabaab and assume d max and l max are large. phrase b a d adadab aa b

LZ77. Example 2.10: Let T = badadadabaab and assume d max and l max are large. phrase b a d adadab aa b LZ77 The original LZ77 algorithm works as follows: A phrase T j starting at a position i is encoded as a triple of the form distance, length, symbol. A triple d, l, s means that: T j = T [i...i + l] =

More information

Grammars and Parsing. 2. A finite nonterminal alphabet N. Symbols in this alphabet are variables of the grammar.

Grammars and Parsing. 2. A finite nonterminal alphabet N. Symbols in this alphabet are variables of the grammar. 4 Grammars and Parsing Formally a language is a set of finite-length strings over a finite alphabet. Because most interesting languages are infinite sets, we cannot define such languages by enumerating

More information

Introduction to Automata Theory. Reading: Chapter 1

Introduction to Automata Theory. Reading: Chapter 1 Introduction to Automata Theory Reading: Chapter 1 1 What is Automata Theory? Study of abstract computing devices, or machines Automaton = an abstract computing device Note: A device need not even be a

More information

Overview of E0222: Automata and Computability

Overview of E0222: Automata and Computability Overview of E0222: Automata and Computability Deepak D Souza Department of Computer Science and Automation Indian Institute of Science, Bangalore. August 3, 2011 What this course is about What we study

More information

Philadelphia University Faculty of Information Technology Department of Computer Science First Semester, 2007/2008.

Philadelphia University Faculty of Information Technology Department of Computer Science First Semester, 2007/2008. Philadelphia University Faculty of Information Technology Department of Computer Science First Semester, 2007/2008 Course Syllabus Course Title: Theory of Computation Course Level: 3 Lecture Time: Course

More information

Voice Driven Animation System

Voice Driven Animation System Voice Driven Animation System Zhijin Wang Department of Computer Science University of British Columbia Abstract The goal of this term project is to develop a voice driven animation system that could take

More information

Pushdown Automata. place the input head on the leftmost input symbol. while symbol read = b and pile contains discs advance head remove disc from pile

Pushdown Automata. place the input head on the leftmost input symbol. while symbol read = b and pile contains discs advance head remove disc from pile Pushdown Automata In the last section we found that restricting the computational power of computing devices produced solvable decision problems for the class of sets accepted by finite automata. But along

More information

Design Patterns in Parsing

Design Patterns in Parsing Abstract Axel T. Schreiner Department of Computer Science Rochester Institute of Technology 102 Lomb Memorial Drive Rochester NY 14623-5608 USA [email protected] Design Patterns in Parsing James E. Heliotis

More information

Automata and Computability. Solutions to Exercises

Automata and Computability. Solutions to Exercises Automata and Computability Solutions to Exercises Fall 25 Alexis Maciel Department of Computer Science Clarkson University Copyright c 25 Alexis Maciel ii Contents Preface vii Introduction 2 Finite Automata

More information

NFAs with Tagged Transitions, their Conversion to Deterministic Automata and Application to Regular Expressions

NFAs with Tagged Transitions, their Conversion to Deterministic Automata and Application to Regular Expressions NFAs with Tagged Transitions, their Conversion to Deterministic Automata and Application to Regular Expressions Ville Laurikari Helsinki University of Technology Laboratory of Computer Science PL 9700,

More information

Organization of DSLE part. Overview of DSLE. Model driven software engineering. Engineering. Tooling. Topics:

Organization of DSLE part. Overview of DSLE. Model driven software engineering. Engineering. Tooling. Topics: Organization of DSLE part Domain Specific Language Engineering Tooling Eclipse plus EMF Xtext, Xtend, Xpand, QVTo and ATL Prof.dr. Mark van den Brand GLT 2010/11 Topics: Meta-modeling Model transformations

More information

Lexical analysis FORMAL LANGUAGES AND COMPILERS. Floriano Scioscia. Formal Languages and Compilers A.Y. 2015/2016

Lexical analysis FORMAL LANGUAGES AND COMPILERS. Floriano Scioscia. Formal Languages and Compilers A.Y. 2015/2016 Master s Degree Course in Computer Engineering Formal Languages FORMAL LANGUAGES AND COMPILERS Lexical analysis Floriano Scioscia 1 Introductive terminological distinction Lexical string or lexeme = meaningful

More information

ω-automata Automata that accept (or reject) words of infinite length. Languages of infinite words appear:

ω-automata Automata that accept (or reject) words of infinite length. Languages of infinite words appear: ω-automata ω-automata Automata that accept (or reject) words of infinite length. Languages of infinite words appear: in verification, as encodings of non-terminating executions of a program. in arithmetic,

More information

Informatique Fondamentale IMA S8

Informatique Fondamentale IMA S8 Informatique Fondamentale IMA S8 Cours 1 - Intro + schedule + finite state machines Laure Gonnord http://laure.gonnord.org/pro/teaching/ [email protected] Université Lille 1 - Polytech Lille

More information

Basic Parsing Algorithms Chart Parsing

Basic Parsing Algorithms Chart Parsing Basic Parsing Algorithms Chart Parsing Seminar Recent Advances in Parsing Technology WS 2011/2012 Anna Schmidt Talk Outline Chart Parsing Basics Chart Parsing Algorithms Earley Algorithm CKY Algorithm

More information

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 7 Scanner Parser Project Wednesday, September 7 DUE: Wednesday, September 21 This

More information

Efficient Monitoring of Parametric Context-Free Patterns

Efficient Monitoring of Parametric Context-Free Patterns Efficient Monitoring of Parametric Context-Free Patterns Patrick O Neil Meredith and Dongyun Jin and Feng Chen and Grigore Roşu University of Illinois at Urbana-Champaign {pmeredit, djin3, fengchen, grosu}@cs.uiuc.edu

More information

Fast nondeterministic recognition of context-free languages using two queues

Fast nondeterministic recognition of context-free languages using two queues Fast nondeterministic recognition of context-free languages using two queues Burton Rosenberg University of Miami Abstract We show how to accept a context-free language nondeterministically in O( n log

More information

Two-dimensional Languages

Two-dimensional Languages Charles University Faculty of Mathematics and Physics Mgr. Daniel Průša Two-dimensional Languages Doctoral Thesis Supervisor: Martin Plátek, CSc. Prague, 2004 Acknowledgements The results presented in

More information

Textual Modeling Languages

Textual Modeling Languages Textual Modeling Languages Slides 4-31 and 38-40 of this lecture are reused from the Model Engineering course at TU Vienna with the kind permission of Prof. Gerti Kappel (head of the Business Informatics

More information

Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy

Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy Kim S. Larsen Odense University Abstract For many years, regular expressions with back referencing have been used in a variety

More information

Yacc: Yet Another Compiler-Compiler

Yacc: Yet Another Compiler-Compiler Stephen C. Johnson ABSTRACT Computer program input generally has some structure in fact, every computer program that does input can be thought of as defining an input language which it accepts. An input

More information

TU e. Advanced Algorithms: experimentation project. The problem: load balancing with bounded look-ahead. Input: integer m 2: number of machines

TU e. Advanced Algorithms: experimentation project. The problem: load balancing with bounded look-ahead. Input: integer m 2: number of machines The problem: load balancing with bounded look-ahead Input: integer m 2: number of machines integer k 0: the look-ahead numbers t 1,..., t n : the job sizes Problem: assign jobs to machines machine to which

More information

CA4003 - Compiler Construction

CA4003 - Compiler Construction CA4003 - Compiler Construction David Sinclair Overview This module will cover the compilation process, reading and parsing a structured language, storing it in an appropriate data structure, analysing

More information

A COMBINED FINE-GRAINED AND ROLE-BASED ACCESS CONTROL MECHANISM HONGI CHANDRA TJAN. Bachelor of Science. Oklahoma State University

A COMBINED FINE-GRAINED AND ROLE-BASED ACCESS CONTROL MECHANISM HONGI CHANDRA TJAN. Bachelor of Science. Oklahoma State University A COMBINED FINE-GRAINED AND ROLE-BASED ACCESS CONTROL MECHANISM By HONGI CHANDRA TJAN Bachelor of Science Oklahoma State University Stillwater, Oklahoma 200 Submitted to the faculty of the Graduate College

More information

Semantic Analysis: Types and Type Checking

Semantic Analysis: Types and Type Checking Semantic Analysis Semantic Analysis: Types and Type Checking CS 471 October 10, 2007 Source code Lexical Analysis tokens Syntactic Analysis AST Semantic Analysis AST Intermediate Code Gen lexical errors

More information

How To Compare A Markov Algorithm To A Turing Machine

How To Compare A Markov Algorithm To A Turing Machine Markov Algorithm CHEN Yuanmi December 18, 2007 1 Abstract Markov Algorithm can be understood as a priority string rewriting system. In this short paper we give the definition of Markov algorithm and also

More information

Semester Review. CSC 301, Fall 2015

Semester Review. CSC 301, Fall 2015 Semester Review CSC 301, Fall 2015 Programming Language Classes There are many different programming language classes, but four classes or paradigms stand out:! Imperative Languages! assignment and iteration!

More information

PROPERTECHNIQUEOFSOFTWARE INSPECTIONUSING GUARDED COMMANDLANGUAGE

PROPERTECHNIQUEOFSOFTWARE INSPECTIONUSING GUARDED COMMANDLANGUAGE International Journal of Computer ScienceandCommunication Vol. 2, No. 1, January-June2011, pp. 153-157 PROPERTECHNIQUEOFSOFTWARE INSPECTIONUSING GUARDED COMMANDLANGUAGE Neeraj Kumar Singhania University,

More information

136 CHAPTER 4. INDUCTION, GRAPHS AND TREES

136 CHAPTER 4. INDUCTION, GRAPHS AND TREES 136 TER 4. INDUCTION, GRHS ND TREES 4.3 Graphs In this chapter we introduce a fundamental structural idea of discrete mathematics, that of a graph. Many situations in the applications of discrete mathematics

More information

Software Engineering and Service Design: courses in ITMO University

Software Engineering and Service Design: courses in ITMO University Software Engineering and Service Design: courses in ITMO University Igor Buzhinsky [email protected] Computer Technologies Department Department of Computer Science and Information Systems December

More information

Automata and Formal Languages

Automata and Formal Languages Automata and Formal Languages Winter 2009-2010 Yacov Hel-Or 1 What this course is all about This course is about mathematical models of computation We ll study different machine models (finite automata,

More information

Natural Language to Relational Query by Using Parsing Compiler

Natural Language to Relational Query by Using Parsing Compiler Available Online at www.ijcsmc.com International Journal of Computer Science and Mobile Computing A Monthly Journal of Computer Science and Information Technology IJCSMC, Vol. 4, Issue. 3, March 2015,

More information

Automata Theory. Şubat 2006 Tuğrul Yılmaz Ankara Üniversitesi

Automata Theory. Şubat 2006 Tuğrul Yılmaz Ankara Üniversitesi Automata Theory Automata theory is the study of abstract computing devices. A. M. Turing studied an abstract machine that had all the capabilities of today s computers. Turing s goal was to describe the

More information

C Compiler Targeting the Java Virtual Machine

C Compiler Targeting the Java Virtual Machine C Compiler Targeting the Java Virtual Machine Jack Pien Senior Honors Thesis (Advisor: Javed A. Aslam) Dartmouth College Computer Science Technical Report PCS-TR98-334 May 30, 1998 Abstract One of the

More information

Parsing Beyond Context-Free Grammars: Introduction

Parsing Beyond Context-Free Grammars: Introduction Parsing Beyond Context-Free Grammars: Introduction Laura Kallmeyer Heinrich-Heine-Universität Düsseldorf Sommersemester 2016 Parsing Beyond CFG 1 Introduction Overview 1. CFG and natural languages 2. Polynomial

More information

Honors Class (Foundations of) Informatics. Tom Verhoeff. Department of Mathematics & Computer Science Software Engineering & Technology

Honors Class (Foundations of) Informatics. Tom Verhoeff. Department of Mathematics & Computer Science Software Engineering & Technology Honors Class (Foundations of) Informatics Tom Verhoeff Department of Mathematics & Computer Science Software Engineering & Technology www.win.tue.nl/~wstomv/edu/hci c 2011, T. Verhoeff @ TUE.NL 1/20 Information

More information

Lecture 2: Universality

Lecture 2: Universality CS 710: Complexity Theory 1/21/2010 Lecture 2: Universality Instructor: Dieter van Melkebeek Scribe: Tyson Williams In this lecture, we introduce the notion of a universal machine, develop efficient universal

More information

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Scanner-Parser Project Thursday, Feb 7 DUE: Wednesday, Feb 20, 9:00 pm This project

More information

FIRST and FOLLOW sets a necessary preliminary to constructing the LL(1) parsing table

FIRST and FOLLOW sets a necessary preliminary to constructing the LL(1) parsing table FIRST and FOLLOW sets a necessary preliminary to constructing the LL(1) parsing table Remember: A predictive parser can only be built for an LL(1) grammar. A grammar is not LL(1) if it is: 1. Left recursive,

More information

Parsing by Example. Diplomarbeit der Philosophisch-naturwissenschaftlichen Fakultät der Universität Bern. vorgelegt von.

Parsing by Example. Diplomarbeit der Philosophisch-naturwissenschaftlichen Fakultät der Universität Bern. vorgelegt von. Parsing by Example Diplomarbeit der Philosophisch-naturwissenschaftlichen Fakultät der Universität Bern vorgelegt von Markus Kobel März 2005 Leiter der Arbeit: Prof. Dr. Oscar Nierstrasz Prof. Dr. Horst

More information

Adaptive LL(*) Parsing: The Power of Dynamic Analysis

Adaptive LL(*) Parsing: The Power of Dynamic Analysis Adaptive LL(*) Parsing: The Power of Dynamic Analysis Terence Parr University of San Francisco [email protected] Sam Harwell University of Texas at Austin [email protected] Kathleen Fisher Tufts University

More information

[Refer Slide Time: 05:10]

[Refer Slide Time: 05:10] Principles of Programming Languages Prof: S. Arun Kumar Department of Computer Science and Engineering Indian Institute of Technology Delhi Lecture no 7 Lecture Title: Syntactic Classes Welcome to lecture

More information

Implementing Programming Languages. Aarne Ranta

Implementing Programming Languages. Aarne Ranta Implementing Programming Languages Aarne Ranta February 6, 2012 2 Contents 1 What is a programming language implementation 11 1.1 From language to binary..................... 11 1.2 Levels of languages........................

More information

Outline of today s lecture

Outline of today s lecture Outline of today s lecture Generative grammar Simple context free grammars Probabilistic CFGs Formalism power requirements Parsing Modelling syntactic structure of phrases and sentences. Why is it useful?

More information