Advertisement
Guest User

Untitled

a guest
May 27th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. //Implementation of FSA, via a linked node-like interface.
  2.  
  3. var FSA = (function(){
  4. function FSA(val){
  5. this.val = val;
  6. this.next = null;
  7. }
  8. FSA.prototype.setNext = function(val){
  9. this.next = new FSA(val);
  10. };
  11. //needs to be appended inside controlling object
  12. FSA.prototype.switchState = function(){
  13. if(this.next){
  14. return this.next;
  15. }
  16. };
  17. return FSA;
  18. })();
  19.  
  20. //encapsulating object
  21. var Machine = function(automatan){
  22. this.automatan = automatan;
  23. this.switch = function(){
  24. this.automatan = this.automatan.switchState();
  25. };
  26. };
  27. //automata switching back and forth
  28. /* var a = new FSA(8);
  29. a
  30. => { val: 8, next: null }
  31. a.setNext(4)
  32. a
  33. => { val: 8, next: { val: 4, next: null } }
  34. a.next.setNext(a)
  35. a
  36. => { val: 8, next: { val: 4, next: { val: [Circular], next: null } } }
  37. var c = new Machine(a)
  38. c
  39. => { automatan: { val: 8, next: { val: 4, next: [Object] } }, switch: [Function] }
  40. c.switch()
  41. c
  42. => { automatan: { val: 4, next: { val: [Object], next: null } }, switch: [Function] }
  43. c.switch()
  44. c
  45. => { automatan: { val: { val: 8, next: [Object] }, next: null }, switch: [Function] }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement