Raimondi

truth_table.vim

Oct 18th, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 2.55 KB | None | 0 0
  1. source ../plugin/vimpeg.vim
  2. let p = Vimpeg({'skip_white': 1})
  3.  
  4. " <expression>  ::= '(' <statement> ')' | <statement> | <predicate>
  5. " <statement>   ::= <equivalence> | <implication> | <xor> | <or> | <and> | <not>
  6. " <equivalence> ::= <expression> '<[-=]>' <expression>
  7. " <implication> ::= <expression> '[-=]>' <expression>
  8. " <xor>         ::= <expression> '*' <expression>
  9. " <or>          ::= <expression> '[vV]' <expression> ( '[vV]' <expression> )*
  10. " <and>         ::= <expression> '[&^]' <expression> ( '[&^]' <expression> )*
  11. " <not>         ::= '[~!]' <expression>
  12. " <predicate>   ::= '[a-uA-U]' | '[w-zW-Z]'
  13.  
  14. " '~p', 'p', 'p ^ q', 'p v q', 'p => q', 'p <-> q', 'p ^ (q => r)'
  15. "let expr = p.or([p.and([p.e('('), 'statement', p.e(')')]), 'statement', 'predicate'],
  16. let expr = p.or(['equivalence', 'implication', 'xor', 'or', 'and', 'not', 'predicate'],
  17.       \{'id': 'expression', 'on_match': 'Expression'})
  18. "call p.or(['equivalence', 'implication', 'xor', 'or', 'and', 'not'],
  19. "let expr =  p.or(['and', 'not', 'predicate'],
  20. "      \{'id': 'statement', 'on_match': 'Statement'})
  21. call p.and(['predicate', p.e('<[-=]>'), 'predicate'],
  22.       \{'id': 'equivalence', 'on_match': 'Equivalence'})
  23. call p.and(['predicate', p.e('[-=]>'), 'predicate'],
  24.       \{'id': 'implication', 'on_match' : 'Implication'})
  25. call p.and(['predicate', p.e('*'), 'predicate', p.maybe_many([p.e('*'), 'predicate'])],
  26.       \{'id': 'xor', 'on_match': 'Xor'})
  27. call p.and(['predicate', p.e('[vV∨]'), 'predicate'],
  28.       \{'id': 'or', 'on_match': 'Or'})
  29. call p.and(['predicate', p.e('[&∧^]'), 'predicate'],
  30.       \{'id': 'and', 'on_match': 'And'})
  31. call p.and([p.e('[~!¬]'), 'predicate'],
  32.       \{'id': 'not', 'on_match': 'Not'})
  33. call p.e('[a-uA-U]\|[w-zW-Z]',
  34.       \{'id': 'predicate', 'on_match': 'Predicate'})
  35.  
  36. function! Expression(elems)
  37.   echo 'Expression: '.string(a:elems)
  38. endfunction
  39.  
  40. function! Statement(elems)
  41.   echo 'Statement: '.string(a:elems)
  42. endfunction
  43.  
  44. function! Equivalence(elems)
  45.   echo 'Equivalence: '.string(a:elems)
  46. endfunction
  47.  
  48. function! Implication(elems)
  49.   echo 'Implication: '.string(a:elems)
  50. endfunction
  51.  
  52. function! Xor(elems)
  53.   echo 'Xor: '.string(a:elems)
  54. endfunction
  55.  
  56. function! Or(elems)
  57.   echo 'Or: '.string(a:elems)
  58. endfunction
  59.  
  60. function! And(elems)
  61.   echo 'And: '.string(a:elems)
  62. endfunction
  63.  
  64. function! Not(elems)
  65.   echo 'Not: '.string(a:elems)
  66. endfunction
  67.  
  68. function! Predicate(elems)
  69.   echo 'Predicate: '.string(a:elems)
  70. endfunction
  71.  
  72. function! Test(expr)
  73.   return string(g:expr.match(a:expr))
  74. endfunction
  75.  
  76. echo Test('p =>q')
  77.  
  78.  
Advertisement
Add Comment
Please, Sign In to add comment