Advertisement
Guest User

Untitled

a guest
Mar 29th, 2014
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.93 KB | None | 0 0
  1. START: A | B;
  2. A: C | D;
  3. B: C | D;
  4. C: T1 | T2;
  5. D: T3 | T4;
  6. T1: 't1';
  7. T2: 't2';
  8. T3: 't3';
  9. T4: 't4';
  10.  
  11. S: NP VP | NPA VP;
  12. NPA: D N | NP PP;
  13. NP: D N | NP PP | NPA;
  14. VP: V NP | VP PP;
  15. PP: P NP;
  16. D: "the" | "a";
  17. P: "in" | "with";
  18. V: "saw";
  19. N: "saw" | "girl" | "boy" | "park" | "telescope";
  20.  
  21. %{
  22. int yylex();
  23. void yyerror(const char* msg);
  24. %}
  25.  
  26. %error-verbose
  27. %glr-parser
  28.  
  29. %token WORD_A "a"
  30. %token WORD_BOY "boy"
  31. %token WORD_GIRL "girl"
  32. %token WORD_IN "in"
  33. %token WORD_LIKED "liked"
  34. %token WORD_PARK "park"
  35. %token WORD_SAW "saw"
  36. %token WORD_TELESCOPE "telescope"
  37. %token WORD_THE "the"
  38. %token WORD_WITH "with"
  39.  
  40. %%
  41. S : NP VP {puts("S: NP VP");} %dprec 1
  42. | NPA VP {puts("S: NPA VP");} %dprec 2
  43. ;
  44. NPA: D N {puts("NPA: D N");} %dprec 3
  45. | NP PP {puts("NPA: NP PP");} %dprec 4
  46. ;
  47. NP : D N {puts("NP: D N");} %dprec 6
  48. | NP PP {puts("NP: NP PP");} %dprec 7
  49. | NPA {puts("NP: NPA");} %dprec 10
  50. ;
  51. VP : V NP {puts("VP: V NP ");} %dprec 11
  52. | VP PP {puts("VP: VP PP");} %dprec 12
  53. ;
  54. PP : P NP {puts("PP: P NP");} %dprec 14
  55. ;
  56. D : "the" {puts("D: the");} %dprec 15
  57. | "a" {puts("D: a");} %dprec 16
  58. ;
  59. P : "in" {puts("P: in");} %dprec 17
  60. | "with" {puts("P: with");} %dprec 18
  61. ;
  62. V : "liked" {puts("V: liked");} %dprec 19
  63. | "saw" {puts("V: saw");} %dprec 20
  64. ;
  65. N : "girl" {puts("N: girl");} %dprec 21
  66. | "boy" {puts("N: boy");} %dprec 22
  67. | "park" {puts("N: park");} %dprec 23
  68. | "saw" {puts("N: saw");} %dprec 24
  69. | "telescope"{puts("N: telescope");} %dprec 25
  70. ;
  71. %%
  72.  
  73. int main(int argc, char** argv) {
  74. printf("yyparse returned %dn", yyparse());
  75. return 0;
  76. }
  77.  
  78. $ make ambig2
  79. bison30 -v -d -o ambig2.c ambig2.y
  80. ambig2.y: warning: 6 shift/reduce conflicts [-Wconflicts-sr]
  81. ambig2.y: warning: 10 reduce/reduce conflicts [-Wconflicts-rr]
  82. gcc-4.8 -ggdb -Wall -D_POSIX_C_SOURCE=200809L -std=c99 -c -o ambig2.o ambig2.c
  83. gcc-4.8 ambig2.o -o ambig2
  84. rm ambig2.o ambig2.c
  85.  
  86. $ ./ambig2 <<<"a boy saw a girl"
  87. D: a
  88. N: boy
  89. NPA: D N
  90. V: saw
  91. D: a
  92. N: girl
  93. NPA: D N
  94. NP: NPA
  95. VP: V NP
  96. S: NPA VP
  97. yyparse returned 0
  98.  
  99. $ ./ambig2 <<<"a saw saw the saw in a saw"
  100. D: a
  101. N: saw
  102. NPA: D N
  103. V: saw
  104. D: the
  105. N: saw
  106. NPA: D N
  107. NP: NPA
  108. VP: V NP
  109. P: in
  110. D: a
  111. N: saw
  112. NPA: D N
  113. NP: NPA
  114. PP: P NP
  115. VP: VP PP
  116. S: NPA VP
  117. yyparse returned 0
  118.  
  119. %%
  120. %%main
  121. #skip "s+"
  122. #skip "[u000du000a]+"
  123. #token 'the' "the"
  124. #token 'a' "a"
  125. #token 'in' "in"
  126. #token 'with' "with"
  127. #token 'saw' "saw"
  128. #token 'girl' "girl"
  129. #token 'boy' "boy"
  130. #token 'park' "park"
  131. #token 'telescope' "telescope"
  132. %%
  133.  
  134. S = NP VP ;
  135. S = NPA VP ;
  136. NPA = D N ;
  137. NPA = NP PP ;
  138. NP = D N ;
  139. NP = NP PP ;
  140. NP = NPA ;
  141. VP = V NP ;
  142. VP = VP PP ;
  143. PP = P NP ;
  144. D = 'the' ;
  145. D = 'a';
  146. P = 'in' ;
  147. P = 'with' ;
  148. V = 'saw' ;
  149. N = 'saw' ;
  150. N = 'girl' ;
  151. N = 'boy' ;
  152. N = 'park' ;
  153. N = 'telescope' ;
  154.  
  155. a boy saw a girln
  156.  
  157. C:DMSDomainssimpenglishToolsParserSource>run ..domainparser ++AST ....Lexeraboysawagirl.txt
  158. simpenglish Domain Parser Version 2.5.15
  159. Copyright (C) 1996-2013 Semantic Designs, Inc; All Rights Reserved; SD Confidential
  160. Powered by DMS (R) Software Reengineering Toolkit
  161. 24 tree nodes in tree.
  162. 3 ambiguity nodes in tree.
  163. (AMBIGUITY<S=11>@simpenglish=31@#1f35140^0{2} Line 1 Column 1 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  164. (S@simpenglish=1@#1f350e0^1#1f35140:1 Line 1 Column 1 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  165. (AMBIGUITY<NP=12>@simpenglish=31@#1f34ba0^1#1f350e0:1{2} Line 1 Column 1 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  166. (NP@simpenglish=5@#1f34b80^1#1f34ba0:1 Line 1 Column 1 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  167. |(D@simpenglish=12@#1f34aa0^2#1f34b80:1#1f34b40:1 Line 1 Column 1 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  168. | ('a'@simpenglish=22@#1f349c0^1#1f34aa0:1[Keyword:0] Line 1 Column 1 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt)'a'
  169. |)D#1f34aa0
  170. |(N@simpenglish=18@#1f34b20^2#1f34b80:2#1f34b40:2 Line 1 Column 3 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  171. | ('boy'@simpenglish=27@#1f34a80^1#1f34b20:1[Keyword:0] Line 1 Column 3 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt)'boy'
  172. |)N#1f34b20
  173. )NP#1f34b80
  174. (NP@simpenglish=7@#1f34c60^1#1f34ba0:2 Line 1 Column 1 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  175. |(NPA@simpenglish=3@#1f34b40^2#1f35040:1#1f34c60:1 Line 1 Column 1 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  176. | (D@simpenglish=12@#1f34aa0^2... [ALREADY PRINTED] ...)
  177. | (N@simpenglish=18@#1f34b20^2... [ALREADY PRINTED] ...)
  178. |)NPA#1f34b40
  179. )NP#1f34c60
  180. )AMBIGUITY#1f34ba0
  181. (VP@simpenglish=8@#1f34fc0^1#1f350e0:2 Line 1 Column 7 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  182. (V@simpenglish=15@#1f34d60^1#1f34fc0:1 Line 1 Column 7 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  183. |('saw'@simpenglish=25@#1f34b00^2#1f34d60:1#1f34d40:1[Keyword:0] Line 1 Column 7 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt)'saw'
  184. )V#1f34d60
  185. (AMBIGUITY<NP=12>@simpenglish=31@#1f34f00^2#1f34f80:2#1f34fc0:2{2} Line 1 Column 11 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  186. |(NP@simpenglish=5@#1f34e60^1#1f34f00:1 Line 1 Column 11 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  187. | (D@simpenglish=12@#1f34da0^2#1f34e60:1#1f34de0:1 Line 1 Column 11 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  188. | ('a'@simpenglish=22@#1f34ce0^1#1f34da0:1[Keyword:0] Line 1 Column 11 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt)'a'
  189. | )D#1f34da0
  190. | (N@simpenglish=17@#1f34dc0^2#1f34e60:2#1f34de0:2 Line 1 Column 13 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  191. | ('girl'@simpenglish=26@#1f34d80^1#1f34dc0:1[Keyword:0] Line 1 Column 13 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt)'girl'
  192. | )N#1f34dc0
  193. |)NP#1f34e60
  194. |(NP@simpenglish=7@#1f34f20^1#1f34f00:2 Line 1 Column 11 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  195. | (NPA@simpenglish=3@#1f34de0^1#1f34f20:1 Line 1 Column 11 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  196. | (D@simpenglish=12@#1f34da0^2... [ALREADY PRINTED] ...)
  197. | (N@simpenglish=17@#1f34dc0^2... [ALREADY PRINTED] ...)
  198. | )NPA#1f34de0
  199. |)NP#1f34f20
  200. )AMBIGUITY#1f34f00
  201. )VP#1f34fc0
  202. )S#1f350e0
  203. (S@simpenglish=2@#1f35040^1#1f35140:2 Line 1 Column 1 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  204. (NPA@simpenglish=3@#1f34b40^2... [ALREADY PRINTED] ...)
  205. (VP@simpenglish=8@#1f34f80^1#1f35040:2 Line 1 Column 7 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  206. (V@simpenglish=15@#1f34d40^1#1f34f80:1 Line 1 Column 7 File C:/DMS/Domains/simpenglish/Tools/Lexer/aboysawagirl.txt
  207. |('saw'@simpenglish=25@#1f34b00^2... [ALREADY PRINTED] ...)
  208. )V#1f34d40
  209. (AMBIGUITY<NP=12>@simpenglish=31@#1f34f00^2... [ALREADY PRINTED] ...)
  210. )VP#1f34f80
  211. )S#1f35040
  212. )AMBIGUITY#1f35140
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement