Advertisement
polygraph

sql_grammar

May 5th, 2022
2,148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 1.63 KB | None | 0 0
  1. s --> [select],x, [from],x,w,gr_by.
  2. x --> a,y.
  3. y-->[","],a,y.
  4. y-->[].
  5. a-->[id],["."],[id].
  6. a-->[id].
  7. a-->[num].
  8. a-->["("],s,[")"].
  9. cmp_op-->[">"].
  10. cmp_op-->["<"].
  11. cmp_op-->["="].
  12. cmp_op-->["<>"].
  13. cmp_op-->["NOT"], cmp_op.
  14. %sub_op-->["IN"].
  15. %sub_op-->["NOT"], sub_op.
  16. cmp-->a, cmp_op, a.
  17. cmp-->cmp, ["AND"], cmp.
  18. cmp-->cmp, ["OR"], cmp.
  19. w-->[where], cmp.
  20. w-->[].
  21. gr_by-->[].
  22. gr_by-->[group_by], [id], list_gr_by.
  23. list_gr_by-->[","],[id], list_gr_by.
  24. list_gr_by -->[].
  25.  
  26.  
  27. c-->[create_table], [id], list.
  28. list-->[].
  29. list-->["("], field ,[")"].
  30. field-->[id], type, attrib, list1.
  31. list1-->[].
  32. list1-->[","],field.
  33. type-->[int].
  34. type-->[float].
  35. type-->[char], ["("], [num], [")"].
  36. attrib-->[auto_increment],attrib.
  37. attrib-->[primary_key],attrib.
  38. attrib-->[foreight_key],attrib.
  39. attrib-->[not_null],attrib.
  40. attrib-->[null],attrib.
  41. attrib-->[].
  42.  
  43.  
  44.  
  45.  
  46. /** <examples>
  47. ?- (s([select,id,".",id, from, id,",",id], [])).
  48. ?- cmp([id,".",id, ">", id,".",id], []).
  49. ?- (s([select,id,".",id, from, id,",",id, where, id, "=", num, "AND", id,".",id, "=", "(", select,id,".",id, from, id,",",id, where, id,".",id, "<", id,".",id, ")"], [])).
  50. ?- (s([select,id,".",id, from, id,",",id, where, id, "=", num, "AND", id,".",id,"NOT" ,"=", "(", select,id,".",id, from, id,",",id, where, id,".",id, "<", id,".",id, ")"], [])).
  51. ?- c([create_table, id, "(",id, int,")"],[])
  52. ?- c([create_table, id, "(",id, int,",",id, int, auto_increment,")"],[])
  53. ?- (s([select,id,".",id, from, id,",",id, where, id, "=", num, "AND", id,".",id,"NOT" ,"=", "(", select,id,".",id, from, id,",",id, where, id,".",id, "<", id,".",id, ")", group_by, id,",", id], [])).
  54. */
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement