Advertisement
Guest User

cs421 group

a guest
Mar 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.57 KB | None | 0 0
  1. bool startstate(string w) //also final state
  2. {
  3. int charpos = 0;
  4. bool result = true; //result of going through bools
  5.  
  6. while(w[charpos] != '\0')
  7. {
  8. switch(w[charpos])
  9. {
  10. case 'a': case 'i': case 'u': case 'e': case 'o':
  11. result = vowels(w, charpos);
  12. break;
  13. case 'n': case 'k': case 'h': case 'm': case 'r': case 'g': case 'b': case 'p':
  14. result = consonants(w, charpos);
  15. break;
  16. case 's':
  17. result = sRoot(w, charpos);
  18. break;
  19. case 'z':
  20. result = zRoot(w, charpos);
  21. break;
  22. case 'j':
  23. result = jRoot(w, charpos);
  24. break;
  25. case 't':
  26. result = tRoot(w, charpos);
  27. break;
  28. case 'd':
  29. result = dRoot(w, charpos);
  30. break;
  31. case 'c':
  32. result = cRoot(w, charpos);
  33. break;
  34. case 'w':
  35. result = wRoot(w, charpos);
  36. break;
  37. case 'y':
  38. result = yRoot(w, charpos);
  39. break;
  40. default: //invalid character
  41. return false;
  42. }
  43. if(w[charpos] == 'E' || w[charpos] == 'I') //WORD2 check
  44. return true;
  45. if(result == false) //failed in bools
  46. return false;
  47. }
  48. return true;
  49. }
  50.  
  51. bool vowels(string w, int& charpos)
  52. {
  53. int state = 0;
  54.  
  55. if(w[charpos + 1] == 'n') //Vn
  56. {
  57. charpos++; charpos++;
  58. return true;
  59. }
  60. else
  61. {
  62. charpos++;
  63. return true;
  64. }
  65. }
  66.  
  67. bool consonants(string w, int& charpos)
  68. {
  69. int state = 0;
  70. char hold = w[charpos];
  71. charpos++;
  72.  
  73. if(state == 0 && w[charpos] == hold && (hold == 'k' || hold == 'p')) //little tsu, CC
  74. {
  75. state = 0;
  76. charpos++;
  77. }
  78. if(state == 0 && (w[charpos] == 'a' || w[charpos] == 'i' || w[charpos] == 'u' || w[charpos] == 'e' || w[charpos] == 'o')) //CV
  79. {
  80. state = 2;
  81. charpos++;
  82. }
  83. if(state == 0 && w[charpos] == 'y') //Cy
  84. {
  85. state = 1;
  86. charpos++;
  87. }
  88. if(state == 1 && (w[charpos] == 'a' || w[charpos] == 'u' || w[charpos] == 'o')) //CyV
  89. {
  90. state = 2;
  91. charpos++;
  92. }
  93. if(state == 2 && w[charpos] == 'n') //-n
  94. {
  95. charpos++;
  96. state = 3;
  97. }
  98. if(state == 2 || state == 3)
  99. return true;
  100. else
  101. return false;
  102. }
  103.  
  104. bool sRoot(string w, int& charpos)
  105. {
  106. int state = 0;
  107. charpos++;
  108.  
  109. if(state == 0 && w[charpos] == 's') //little tsu, ss
  110. {
  111. state = 0;
  112. charpos++;
  113. }
  114. if(state == 0 && w[charpos] == 'h') //sh
  115. {
  116. state = 1;
  117. charpos++;
  118. }
  119. if(state == 1 && (w[charpos] == 'a' || w[charpos] == 'i' || w[charpos] == 'u' || w[charpos] == 'o')) //sha shi shu sho
  120. {
  121. state = 2;
  122. charpos++;
  123. }
  124. if(state == 0 && (w[charpos] == 'a' || w[charpos] == 'u' || w[charpos] == 'e' || w[charpos] == 'o')) //sa su se so
  125. {
  126. state = 2;
  127. charpos++;
  128. }
  129. if(state == 2 && w[charpos] == 'n') //-n
  130. {
  131. state = 3;
  132. charpos++;
  133. }
  134. if(state == 2 || state == 3)
  135. return true;
  136. else
  137. return false;
  138. }
  139.  
  140. bool zRoot(string w, int& charpos)
  141. {
  142. int state = 0;
  143. charpos++;
  144.  
  145. if(state == 0 && (w[charpos] == 'a' || w[charpos] == 'u' || w[charpos] == 'e' || w[charpos] == 'o')) //za zu ze zo
  146. {
  147. state = 1;
  148. charpos++;
  149. }
  150. if(state == 1 && w[charpos] == 'n') //-n
  151. {
  152. state = 2;
  153. charpos++;
  154. }
  155. if(state == 1 || state == 2)
  156. return true;
  157. else
  158. return false;
  159. }
  160. bool jRoot(string w, int& charpos)
  161. {
  162. int state = 0;
  163. charpos++;
  164.  
  165. if(state == 0 && (w[charpos] == 'a' || w[charpos] == 'i' || w[charpos] == 'u' || w[charpos] == 'o')) //ja ji ju jo
  166. {
  167. state = 1;
  168. charpos++;
  169. }
  170. if(state == 1 && w[charpos] == 'n') //-n
  171. {
  172. state = 2;
  173. charpos++;
  174. }
  175. if(state == 1 || state == 2)
  176. return true;
  177. else
  178. return false;
  179. }
  180.  
  181. bool tRoot(string w, int& charpos)
  182. {
  183. int state = 0;
  184. charpos++;
  185.  
  186. if(state == 0 && w[charpos] == 't') //little tsu, tt
  187. {
  188. state = 0;
  189. charpos++;
  190. }
  191. if(state == 0 && w[charpos] == 's') //ts
  192. {
  193. state = 1;
  194. charpos++;
  195. }
  196. if(state == 1 && w[charpos] == 'u') //tsu
  197. {
  198. state = 2;
  199. charpos++;
  200. }
  201. if(state == 0 && (w[charpos] == 'a' || w[charpos] == 'e' || w[charpos] == 'o')) //ta te to
  202. {
  203. state = 2;
  204. charpos++;
  205. }
  206. if(state == 2 && w[charpos] == 'n') //-n
  207. {
  208. state = 3;
  209. charpos++;
  210. }
  211. if(state == 2 || state == 3)
  212. return true;
  213. else
  214. return false;
  215. }
  216. bool dRoot(string w, int& charpos)
  217. {
  218. int state = 0;
  219. charpos++;
  220.  
  221. if(state == 0 && (w[charpos] == 'a' || w[charpos] == 'e' || w[charpos] == 'o')) //da de do
  222. {
  223. state = 1;
  224. charpos++;
  225. }
  226. if(state == 1 && w[charpos] == 'n') //-n
  227. {
  228. state = 2;
  229. charpos++;
  230. }
  231. if(state == 1 || state == 2)
  232. return true;
  233. else
  234. return false;
  235. }
  236. bool cRoot(string w, int& charpos)
  237. {
  238. int state = 0;
  239. charpos++;
  240.  
  241. if(state == 0 && w[charpos] == 'c') //little tsu
  242. {
  243. state = 0;
  244. charpos++;
  245. }
  246. if(state == 0 && w[charpos] == 'h') //ch
  247. {
  248. state = 1;
  249. charpos++;
  250. }
  251. if(state == 1 && (w[charpos] == 'a' || w[charpos] == 'i' || w[charpos] == 'u' || w[charpos] == 'o')) //cha chi chu cho
  252. {
  253. state = 2;
  254. charpos++;
  255. }
  256. if(state == 2 && w[charpos] == 'n') //-n
  257. {
  258. state = 3;
  259. charpos++;
  260. }
  261. if(state == 2 || state == 3)
  262. return true;
  263. else
  264. return false;
  265. }
  266.  
  267.  
  268. bool wRoot(string w, int& charpos)
  269. {
  270. int state = 0;
  271. charpos++;
  272.  
  273. if(state == 0 && w[charpos] == 'a') //wa
  274. {
  275. state = 1;
  276. charpos++;
  277. }
  278. if(state == 1 && w[charpos] == 'n') //wan
  279. {
  280. state = 2;
  281. charpos++;
  282. }
  283. if(state == 1 || state == 2)
  284. return true;
  285. else
  286. return false;
  287. }
  288.  
  289. bool yRoot(string w, int& charpos)
  290. {
  291. int state = 0;
  292. charpos++;
  293.  
  294. if(state == 0 && (w[charpos] == 'a' || w[charpos] == 'u' || w[charpos] == 'o')) //ya yu yo
  295. {
  296. state = 1;
  297. charpos++;
  298. }
  299. if(state == 1 && w[charpos] == 'n') //yan yun yon
  300. {
  301. state = 2;
  302. charpos++;
  303. }
  304. if(state == 1 || state == 2)
  305. return true;
  306. else
  307. return false;
  308. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement