UNPKG

horatio

Version:

A javascript compiler for the Shakespeare Programming Language

2,145 lines (1,704 loc) 127 kB
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ /** * Horatio AST * @namespace */ /** * @memberof Horatio.AST * @param {Horatio.AST.Comment} comment * @param {Array.<Horatio.AST.Declaration>} declarations * @param {Array.<Horatio.AST.Part>} parts */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Program = (function () { function Program(comment, declarations, parts) { _classCallCheck(this, Program); this.comment = comment; this.declarations = declarations; this.parts = parts; } _createClass(Program, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitProgram(this, arg); } }]); return Program; })(); /** * @memberof Horatio.AST * @param {Horatio.AST.Character} character * @param {Horatio.AST.Comment} comment */ var Declaration = (function () { function Declaration(character, comment) { _classCallCheck(this, Declaration); this.character = character; this.comment = comment; } _createClass(Declaration, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitDeclaration(this, arg); } }]); return Declaration; })(); /** * @memberof Horatio.AST * @param {Horatio.AST.Numeral} numeral * @param {Horatio.AST.Comment} comment * @param {Array.<Horatio.AST.Subpart>} subparts */ var Part = (function () { function Part(numeral, comment, subparts) { _classCallCheck(this, Part); this.numeral = numeral; this.comment = comment; this.subparts = subparts; } _createClass(Part, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitPart(this, arg); } }]); return Part; })(); /** * @memberof Horatio.AST * @param {Horatio.AST.Numeral} numeral * @param {Horatio.AST.Comment} comment * @param {Horatio.AST.Stage} stage */ var Subpart = (function () { function Subpart(numeral, comment, stage) { _classCallCheck(this, Subpart); this.numeral = numeral; this.comment = comment; this.stage = stage; } _createClass(Subpart, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitSubpart(this, arg); } }]); return Subpart; })(); /** * @memberof Horatio.AST * @param {Horatio.AST.Dialogue} dialogue * @param {Horatio.AST.Enter|Horatio.AST.Exit|Horatio.AST.exeunt} start_presence * @param {Horatio.AST.Enter|Horatio.AST.Exit|Horatio.AST.exeunt} end_presence */ var Stage = (function () { function Stage(dialogue, start_presence, end_presence) { _classCallCheck(this, Stage); this.dialogue = dialogue; this.start_presence = start_presence; this.end_presence = end_presence; } _createClass(Stage, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitStage(this, arg); } }]); return Stage; })(); /** * @memberof Horatio.AST * @param {Horatio.AST.Character} character_1 * @param {Horatio.AST.Character} character_2 */ var Enter = (function () { function Enter(character_1, character_2) { _classCallCheck(this, Enter); this.character_1 = character_1; this.character_2 = character_2; } _createClass(Enter, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitEnter(this, arg); } }]); return Enter; })(); /** * @memberof Horatio.AST * @param {Horatio.AST.Character} character */ var Exit = (function () { function Exit(character) { _classCallCheck(this, Exit); this.character = character; } _createClass(Exit, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitExit(this, arg); } }]); return Exit; })(); /** * @memberof Horatio.AST * @param {Horatio.AST.Character} character_1 * @param {Horatio.AST.Character} character_2 */ var Exeunt = (function () { function Exeunt(character_1, character_2) { _classCallCheck(this, Exeunt); this.character_1 = character_1; this.character_2 = character_2; } _createClass(Exeunt, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitExeunt(this, arg); } }]); return Exeunt; })(); /** * @memberof Horatio.AST * @param {Array.<Horatio.AST.Line>} lines */ var Dialogue = (function () { function Dialogue(lines) { _classCallCheck(this, Dialogue); this.lines = lines; } _createClass(Dialogue, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitDialogue(this, arg); } }]); return Dialogue; })(); /** * @memberof Horatio.AST * @param {Horatio.AST.Character} character * @param {Array.<Horatio.AST.Sentences>} sentences */ var Line = (function () { function Line(character, sentences) { _classCallCheck(this, Line); this.character = character; this.sentences = sentences; } _createClass(Line, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitLine(this, arg); } }]); return Line; })(); /** * @memberof Horatio.AST * @param {Horatio.AST.Numeral} numeral */ var Goto = (function () { function Goto(numeral) { _classCallCheck(this, Goto); this.numeral = numeral; } _createClass(Goto, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitGoto(this, arg); } }]); return Goto; })(); /** * @memberof Horatio.AST */ var AssignmentSentence = (function () { function AssignmentSentence(be, value) { _classCallCheck(this, AssignmentSentence); this.be = be; this.value = value; } _createClass(AssignmentSentence, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitAssignmentSentence(this, arg); } }]); return AssignmentSentence; })(); /** * @memberof Horatio.AST */ var QuestionSentence = (function () { function QuestionSentence(be, comparison, value) { _classCallCheck(this, QuestionSentence); this.be = be; this.comparison = comparison; this.value = value; } _createClass(QuestionSentence, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitQuestionSentence(this, arg); } }]); return QuestionSentence; })(); /** * @memberof Horatio.AST */ var ResponseSentence = (function () { function ResponseSentence(goto) { _classCallCheck(this, ResponseSentence); this.goto = goto; } _createClass(ResponseSentence, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitResponseSentence(this, arg); } }]); return ResponseSentence; })(); /** * @memberof Horatio.AST */ var GotoSentence = (function () { function GotoSentence(goto) { _classCallCheck(this, GotoSentence); this.goto = goto; } _createClass(GotoSentence, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitGotoSentence(this, arg); } }]); return GotoSentence; })(); /** * @memberof Horatio.AST */ var IntegerInputSentence = (function () { function IntegerInputSentence(sequence) { _classCallCheck(this, IntegerInputSentence); this.sequence = sequence; } _createClass(IntegerInputSentence, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitIntegerInputSentence(this, arg); } }]); return IntegerInputSentence; })(); /** * @memberof Horatio.AST */ var CharInputSentence = (function () { function CharInputSentence(sequence) { _classCallCheck(this, CharInputSentence); this.sequence = sequence; } _createClass(CharInputSentence, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitCharInputSentence(this, arg); } }]); return CharInputSentence; })(); /** * @memberof Horatio.AST */ var IntegerOutputSentence = (function () { function IntegerOutputSentence(sequence) { _classCallCheck(this, IntegerOutputSentence); this.sequence = sequence; } _createClass(IntegerOutputSentence, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitIntegerOutputSentence(this, arg); } }]); return IntegerOutputSentence; })(); /** * @memberof Horatio.AST */ var CharOutputSentence = (function () { function CharOutputSentence(sequence) { _classCallCheck(this, CharOutputSentence); this.sequence = sequence; } _createClass(CharOutputSentence, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitCharOutputSentence(this, arg); } }]); return CharOutputSentence; })(); /** * @memberof Horatio.AST */ var RememberSentence = (function () { function RememberSentence(pronoun) { _classCallCheck(this, RememberSentence); this.pronoun = pronoun; } _createClass(RememberSentence, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitRememberSentence(this, arg); } }]); return RememberSentence; })(); /** * @memberof Horatio.AST */ var RecallSentence = (function () { function RecallSentence(comment) { _classCallCheck(this, RecallSentence); this.comment = comment; } _createClass(RecallSentence, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitRecallSentence(this, arg); } }]); return RecallSentence; })(); /** * @memberof Horatio.AST */ var PositiveConstantValue = (function () { function PositiveConstantValue(noun, adjectives) { _classCallCheck(this, PositiveConstantValue); this.noun = noun; this.adjectives = adjectives; } _createClass(PositiveConstantValue, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitPositiveConstantValue(this, arg); } }]); return PositiveConstantValue; })(); /** * @memberof Horatio.AST */ var NegativeConstantValue = (function () { function NegativeConstantValue(noun, adjectives) { _classCallCheck(this, NegativeConstantValue); this.noun = noun; this.adjectives = adjectives; } _createClass(NegativeConstantValue, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitNegativeConstantValue(this, arg); } }]); return NegativeConstantValue; })(); /** * @memberof Horatio.AST */ var UnaryOperationValue = (function () { function UnaryOperationValue(operator, value) { _classCallCheck(this, UnaryOperationValue); this.operator = operator; this.value = value; } _createClass(UnaryOperationValue, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitUnaryOperationValue(this, arg); } }]); return UnaryOperationValue; })(); /** * @memberof Horatio.AST */ var ArithmeticOperationValue = (function () { function ArithmeticOperationValue(operator, value_1, value_2) { _classCallCheck(this, ArithmeticOperationValue); this.operator = operator; this.value_1 = value_1; this.value_2 = value_2; } _createClass(ArithmeticOperationValue, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitArithmeticOperationValue(this, arg); } }]); return ArithmeticOperationValue; })(); /** * @memberof Horatio.AST */ var PronounValue = (function () { function PronounValue(pronoun) { _classCallCheck(this, PronounValue); this.pronoun = pronoun; } _createClass(PronounValue, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitPronounValue(this, arg); } }]); return PronounValue; })(); /** * @memberof Horatio.AST */ var GreaterThanComparison = (function () { function GreaterThanComparison(comparative) { _classCallCheck(this, GreaterThanComparison); this.comparative = comparative; } _createClass(GreaterThanComparison, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitGreaterThanComparison(this, arg); } }]); return GreaterThanComparison; })(); /** * @memberof Horatio.AST */ var LesserThanComparison = (function () { function LesserThanComparison(comparative) { _classCallCheck(this, LesserThanComparison); this.comparative = comparative; } _createClass(LesserThanComparison, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitLesserThanComparison(this, arg); } }]); return LesserThanComparison; })(); /** * @memberof Horatio.AST */ var EqualToComparison = (function () { function EqualToComparison(adjective) { _classCallCheck(this, EqualToComparison); this.adjective = adjective; } _createClass(EqualToComparison, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitEqualToComparison(this, arg); } }]); return EqualToComparison; })(); /** * @memberof Horatio.AST */ var InverseComparison = (function () { function InverseComparison(comparison) { _classCallCheck(this, InverseComparison); this.comparison = comparison; } _createClass(InverseComparison, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitInverseComparison(this, arg); } }]); return InverseComparison; })(); /** * @memberof Horatio.AST */ var Comment = (function () { function Comment(sequence) { _classCallCheck(this, Comment); this.sequence = sequence; } _createClass(Comment, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitComment(this, arg); } }]); return Comment; })(); /** * @memberof Horatio.AST */ var Numeral = (function () { function Numeral(sequence) { _classCallCheck(this, Numeral); this.sequence = sequence; } _createClass(Numeral, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitNumeral(this, arg); } }]); return Numeral; })(); /** * @memberof Horatio.AST */ var Character = (function () { function Character(sequence) { _classCallCheck(this, Character); this.sequence = sequence; } _createClass(Character, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitCharacter(this, arg); } }]); return Character; })(); /** * @memberof Horatio.AST */ var FirstPersonPronoun = (function () { function FirstPersonPronoun(sequence) { _classCallCheck(this, FirstPersonPronoun); this.sequence = sequence; } _createClass(FirstPersonPronoun, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitFirstPersonPronoun(this, arg); } }]); return FirstPersonPronoun; })(); /** * @memberof Horatio.AST */ var SecondPersonPronoun = (function () { function SecondPersonPronoun(sequence) { _classCallCheck(this, SecondPersonPronoun); this.sequence = sequence; } _createClass(SecondPersonPronoun, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitSecondPersonPronoun(this, arg); } }]); return SecondPersonPronoun; })(); /** * @memberof Horatio.AST */ var PositiveNoun = (function () { function PositiveNoun(sequence) { _classCallCheck(this, PositiveNoun); this.sequence = sequence; } _createClass(PositiveNoun, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitPositiveNoun(this, arg); } }]); return PositiveNoun; })(); /** * @memberof Horatio.AST */ var NeutralNoun = (function () { function NeutralNoun(sequence) { _classCallCheck(this, NeutralNoun); this.sequence = sequence; } _createClass(NeutralNoun, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitNeutralNoun(this, arg); } }]); return NeutralNoun; })(); /** * @memberof Horatio.AST */ var NegativeNoun = (function () { function NegativeNoun(sequence) { _classCallCheck(this, NegativeNoun); this.sequence = sequence; } _createClass(NegativeNoun, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitNegativeNoun(this, arg); } }]); return NegativeNoun; })(); /** * @memberof Horatio.AST */ var PositiveAdjective = (function () { function PositiveAdjective(sequence) { _classCallCheck(this, PositiveAdjective); this.sequence = sequence; } _createClass(PositiveAdjective, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitPositiveAdjective(this, arg); } }]); return PositiveAdjective; })(); /** * @memberof Horatio.AST */ var NeutralAdjective = (function () { function NeutralAdjective(sequence) { _classCallCheck(this, NeutralAdjective); this.sequence = sequence; } _createClass(NeutralAdjective, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitNeutralAdjective(this, arg); } }]); return NeutralAdjective; })(); /** * @memberof Horatio.AST */ var NegativeAdjective = (function () { function NegativeAdjective(sequence) { _classCallCheck(this, NegativeAdjective); this.sequence = sequence; } _createClass(NegativeAdjective, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitNegativeAdjective(this, arg); } }]); return NegativeAdjective; })(); /** * @memberof Horatio.AST */ var UnaryOperator = (function () { function UnaryOperator(sequence) { _classCallCheck(this, UnaryOperator); this.sequence = sequence; } _createClass(UnaryOperator, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitUnaryOperator(this, arg); } }]); return UnaryOperator; })(); /** * @memberof Horatio.AST */ var ArithmeticOperator = (function () { function ArithmeticOperator(sequence) { _classCallCheck(this, ArithmeticOperator); this.sequence = sequence; } _createClass(ArithmeticOperator, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitArithmeticOperator(this, arg); } }]); return ArithmeticOperator; })(); /** * @memberof Horatio.AST */ var PositiveComparative = (function () { function PositiveComparative(sequence) { _classCallCheck(this, PositiveComparative); this.sequence = sequence; } _createClass(PositiveComparative, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitPositiveComparative(this, arg); } }]); return PositiveComparative; })(); /** * @memberof Horatio.AST */ var NegativeComparative = (function () { function NegativeComparative(sequence) { _classCallCheck(this, NegativeComparative); this.sequence = sequence; } _createClass(NegativeComparative, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitNegativeComparative(this, arg); } }]); return NegativeComparative; })(); /** * @memberof Horatio.AST */ var Be = (function () { function Be(sequence) { _classCallCheck(this, Be); this.sequence = sequence; } _createClass(Be, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitBe(this, arg); } }]); return Be; })(); /** * @memberof Horatio.AST */ var BeComparative = (function () { function BeComparative(sequence) { _classCallCheck(this, BeComparative); this.sequence = sequence; } _createClass(BeComparative, [{ key: "visit", value: function visit(visitor, arg) { return visitor.visitBeComparative(this, arg); } }]); return BeComparative; })(); /** Export */ exports["default"] = { Program: Program, Declaration: Declaration, Part: Part, Subpart: Subpart, Stage: Stage, Enter: Enter, Exit: Exit, Exeunt: Exeunt, Dialogue: Dialogue, Line: Line, Goto: Goto, AssignmentSentence: AssignmentSentence, QuestionSentence: QuestionSentence, ResponseSentence: ResponseSentence, GotoSentence: GotoSentence, IntegerInputSentence: IntegerInputSentence, IntegerOutputSentence: IntegerOutputSentence, CharOutputSentence: CharOutputSentence, RememberSentence: RememberSentence, RecallSentence: RecallSentence, PositiveConstantValue: PositiveConstantValue, NegativeConstantValue: NegativeConstantValue, UnaryOperationValue: UnaryOperationValue, ArithmeticOperationValue: ArithmeticOperationValue, PronounValue: PronounValue, GreaterThanComparison: GreaterThanComparison, LesserThanComparison: LesserThanComparison, EqualToComparison: EqualToComparison, InverseComparison: InverseComparison, Comment: Comment, Numeral: Numeral, Character: Character, FirstPersonPronoun: FirstPersonPronoun, SecondPersonPronoun: SecondPersonPronoun, PositiveNoun: PositiveNoun, NeutralNoun: NeutralNoun, NegativeNoun: NegativeNoun, PositiveAdjective: PositiveAdjective, NeutralAdjective: NeutralAdjective, NegativeAdjective: NegativeAdjective, UnaryOperator: UnaryOperator, ArithmeticOperator: ArithmeticOperator, PositiveComparative: PositiveComparative, NegativeComparative: NegativeComparative, Be: Be, BeComparative: BeComparative }; module.exports = exports["default"]; },{}],2:[function(require,module,exports){ /** * Horatio Program Character */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Character = (function () { function Character(name) { _classCallCheck(this, Character); this._name = name; this._value = null; this._memory = []; } _createClass(Character, [{ key: "name", /** * @returns {string} */ value: function name() { return this._name; } }, { key: "value", /** * @returns {number|null} */ value: function value() { return this._value; } }, { key: "setValue", /** * @param {number} val */ value: function setValue(val) { this._value = val; } }, { key: "memorySize", /** * @returns {number} */ value: function memorySize() { return this.memory.length; } }, { key: "noMemory", /** * @returns {boolean} */ value: function noMemory() { return this.memory.length === 0; } }, { key: "remember", /** * @param {number} */ value: function remember(val) { this._memory.push(val); } }, { key: "recall", /** * set character value from top of stack */ value: function recall() { if (this.noMemory()) { throw new Error("Runtime Error - Trying to recall from empty stack."); } else { this._value = this._memory.pop(); } } }]); return Character; })(); exports["default"] = Character; module.exports = exports["default"]; },{}],3:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; } var _semantics = require('./semantics'); var _semantics2 = _interopRequireDefault(_semantics); /** * Horatio Checker */ var Checker = (function (_Semantics) { _inherits(Checker, _Semantics); function Checker() { _classCallCheck(this, Checker); _get(Object.getPrototypeOf(Checker.prototype), 'constructor', this).call(this); this.characters = {}; this.parts = {}; } _createClass(Checker, [{ key: 'check', /** * Check */ value: function check(program) { program.visit(this, null); } }, { key: 'declared', /** * Character exists */ value: function declared(character) { return this.characters.hasOwnProperty(character); } }, { key: 'onStage', /** * Character on stage */ value: function onStage(character) { if (this.declared(character)) { return this.characters[character]; } else { return false; } } }, { key: 'solo', /** * Solo on stage? */ value: function solo(character) { if (this.declared(character) && this.characters[character]) { for (var k in this.characters) { if (k !== character && this.characters[k] === true) { return false; } } return true; } return false; } }, { key: 'toggleStage', /** * Toggle Stage presence */ value: function toggleStage(character) { if (this.declared(character)) { this.characters[character] = !this.characters[character]; } } }, { key: 'exeuntStage', /** * Exeunt all */ value: function exeuntStage() { for (var c in this.characters) { this.characters[c] = false; } } }, { key: 'sceneExists', /** * Scene exists */ value: function sceneExists(act, scene) { if (!this.parts[act]) { return false; } else { return this.parts[act].indexOf(scene) !== -1; } } }]); return Checker; })(_semantics2['default']); exports['default'] = Checker; module.exports = exports['default']; },{"./semantics":10}],4:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var _parser = require('./parser'); var _parser2 = _interopRequireDefault(_parser); var _checker = require('./checker'); var _checker2 = _interopRequireDefault(_checker); var _encoder = require('./encoder'); var _encoder2 = _interopRequireDefault(_encoder); /** * Compiles SPL into javascript * @memberof Horatio */ var Compiler = (function () { function Compiler(io) { _classCallCheck(this, Compiler); this.io = io; } _createClass(Compiler, [{ key: 'compile', /** * Compile an SPL program * @param {string} input - The input SPL program */ value: function compile(input) { // Parse input var parser = new _parser2['default'](input); // Generate AST var ast = parser.parse(); // Semantic Check var checker = new _checker2['default'](); checker.check(ast); // Code Generation var encoder = new _encoder2['default'](this.io); var program = encoder.encode(ast); return program; } }]); return Compiler; })(); exports['default'] = Compiler; module.exports = exports['default']; },{"./checker":3,"./encoder":5,"./parser":8}],5:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; } var _generator = require('./generator'); var _generator2 = _interopRequireDefault(_generator); var _program = require('./program'); var _program2 = _interopRequireDefault(_program); var _wordlists = require('./wordlists'); var _wordlists2 = _interopRequireDefault(_wordlists); /** * Horatio Encoder */ var Encoder = (function (_Generator) { _inherits(Encoder, _Generator); function Encoder(io) { _classCallCheck(this, Encoder); _get(Object.getPrototypeOf(Encoder.prototype), 'constructor', this).call(this); this.program = new _program2['default'](io); } _createClass(Encoder, [{ key: 'encode', /** * Encode */ value: function encode(program) { program.visit(this, null); return this.program; } }, { key: 'numeralIndex', /** * Get index number from roman numeral */ value: function numeralIndex(numeral) { return _wordlists2['default'].roman_numerals.indexOf(numeral); } }]); return Encoder; })(_generator2['default']); exports['default'] = Encoder; module.exports = exports['default']; },{"./generator":6,"./program":9,"./wordlists":13}],6:[function(require,module,exports){ /** * Horatio Generation Visitor */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Generator = (function () { function Generator() { _classCallCheck(this, Generator); } _createClass(Generator, [{ key: "visitProgram", /** * Program */ value: function visitProgram(program, arg) { var self = this; // declarations program.declarations.forEach(function (declaration) { declaration.visit(self, null); }); // parts program.parts.forEach(function (part) { part.visit(self, null); }); return null; } }, { key: "visitDeclaration", /** * Declaration */ value: function visitDeclaration(declaration, arg) { var c = declaration.character.sequence; this.program.declareCharacter(c); return null; } }, { key: "visitNumeral", /** * Numeral */ value: function visitNumeral(numeral, arg) { var n = this.numeralIndex(numeral.sequence); return n; } }, { key: "visitPart", /** * Part */ value: function visitPart(part, arg) { var self = this; var n = part.numeral.visit(this, arg); var act = this.program.newAct(); part.subparts.forEach(function (subpart) { subpart.visit(self, { act: act }); }); return null; } }, { key: "visitSubpart", /** * Subparts */ value: function visitSubpart(subpart, arg) { var n = subpart.numeral.visit(this, arg); var scene = this.program.newScene(arg.act); subpart.stage.visit(this, { act: arg.act, scene: scene }); return null; } }, { key: "visitStage", /** * Stage */ value: function visitStage(stage, arg) { if (stage.start_presence) stage.start_presence.visit(this, arg); if (stage.dialogue) stage.dialogue.visit(this, arg); if (stage.end_presence) stage.end_presence.visit(this, arg); return null; } }, { key: "visitEnter", /** * Enter */ value: function visitEnter(presence, arg) { var Command = function Command(cname) { var c = cname; return function () { this.enterStage(c); }; }; var c1 = presence.character_1.sequence; this.program.addCommand(arg.act, arg.scene, new Command(c1)); if (presence.character_2) { var c2 = presence.character_2.sequence; this.program.addCommand(arg.act, arg.scene, new Command(c2)); } return null; } }, { key: "visitExit", /** * Exit */ value: function visitExit(presence, arg) { var Command = function Command(cname) { var c = cname; return function () { this.exitStage(c); }; }; var c = presence.character.sequence; this.program.addCommand(arg.act, arg.scene, new Command(c)); return null; } }, { key: "visitExeunt", /** * Exeunt */ value: function visitExeunt(presence, arg) { var Command = function Command() { return function () { this.exeuntStage(); }; }; this.program.addCommand(arg.act, arg.scene, new Command()); return null; } }, { key: "visitDialogue", /** * Dialogue */ value: function visitDialogue(dialogue, arg) { var self = this; dialogue.lines.forEach(function (line) { line.visit(self, arg); }); return null; } }, { key: "visitLine", /** * Line */ value: function visitLine(line, arg) { var self = this; var c = line.character.sequence; arg.character = c; line.sentences.forEach(function (sentence) { sentence.visit(self, arg); }); return null; } }, { key: "visitGoto", /** * Goto */ value: function visitGoto(goto, arg) { var n = goto.numeral.visit(this, arg); return null; } }, { key: "visitAssignmentSentence", /** * Assignment Sentence */ value: function visitAssignmentSentence(assignment, arg) { var Command = function Command(target, value) { var t = target; var v = value; return function () { var target = t.call(this); var val = v.call(this); this.characters[target].setValue(val); }; }; var target = assignment.be.visit(this, arg); var value = assignment.value.visit(this, arg); this.program.addCommand(arg.act, arg.scene, new Command(target, value)); return null; } }, { key: "visitQuestionSentence", /** * Question Sentence */ value: function visitQuestionSentence(question, arg) { var Command = function Command(be, comparative, value) { var b = be; var c = comparative; var v = value; return function () { var character = b.call(this); var a = this.characters[b].value(); var val = v.call(this); var result = c.call(this, a, val); }; }; var be = question.be.visit(this, arg); var comparative = question.comparison.visit(this, arg); var value = question.value.visit(this, arg); this.program.addCommand(arg.act, arg.scene, new Command(be, comparative, value)); return null; } }, { key: "visitResponseSentence", /** * Response Sentence */ value: function visitResponseSentence(response, arg) { response.goto.visit(this, arg); return null; } }, { key: "visitGotoSentence", /** * Goto Sentence */ value: function visitGotoSentence(goto, arg) { goto.goto.visit(this, arg); return null; } }, { key: "visitIntegerInputSentence", /** * Integer Input Sentence */ value: function visitIntegerInputSentence(integer_input, arg) { return null; } }, { key: "visitCharInputSentence", /** * Char Input Sentence */ value: function visitCharInputSentence(char_input, arg) { return null; } }, { key: "visitIntegerOutputSentence", /** * Integer Output Sentence */ value: function visitIntegerOutputSentence(integer_output, arg) { var Command = function Command() { var speaker = arg.character; return function () { var val = this.interlocutor(speaker).value(); this.io.print(val); }; }; this.program.addCommand(arg.act, arg.scene, new Command()); return null; } }, { key: "visitCharOutputSentence", /** * Char Output Sentence */ value: function visitCharOutputSentence(char_output, arg) { var Command = function Command() { var speaker = arg.character; return function () { var val = this.interlocutor(speaker).value(); this.io.print(String.fromCharCode(val)); }; }; this.program.addCommand(arg.act, arg.scene, new Command()); return null; } }, { key: "visitRememberSentence", /** * Remember Sentence */ value: function visitRememberSentence(remember, arg) { var Command = function Command(pronoun) { var speaking = arg.character; var p = pronoun; return function () { var pn = p(); var value = this.characters[pn].value(); this.characters[speaking].remember(value); }; }; var p = remember.pronoun.visit(this, arg); this.program.addCommand(arg.act, arg.scene, new Command(p)); return null; } }, { key: "visitRecallSentence", /** * Recall Sentence */ value: function visitRecallSentence(recall, arg) { var Command = function Command() { var speaking = arg.character; return function () { this.interlocutor(speaking).recall(); }; }; this.program.addCommand(arg.act, arg.scene, new Command()); return null; } }, { key: "visitPositiveConstantValue", /** * Positive Constant Value */ value: function visitPositiveConstantValue(pc_val, arg) { var Command = function Command(num_adjectives) { var exp = num_adjectives; return function () { return Math.pow(2, exp); }; }; var adjectives = pc_val.adjectives; return new Command(adjectives.length); } }, { key: "visitNegativeConstantValue", /** * Negative Constant Value */ value: function visitNegativeConstantValue(nc_val, arg) { var Command = function Command(num_adjectives) { var exp = num_adjectives; return function () { return -1 * Math.pow(2, exp); }; }; var adjectives = nc_val.adjectives; return new Command(adjectives.length); } }, { key: "visitUnaryOperationValue", /** * Unary Operation Value */ value: function visitUnaryOperationValue(unary, arg) { var Command = function Command(operator, value) { var o = operator; var v = value; return function () { var val = v.call(this); return o.call(this, val); }; }; var o = unary.operator.visit(this, arg); var v = unary.value.visit(this, arg); return new Command(o, v); } }, { key: "visitArithmeticOperationValue", /** * Arithmetic Operation Value */ value: function visitArithmeticOperationValue(arithmetic, arg) { var Command = function Command(operator, value1, value2) { var o = operator; var v1 = value1; var v2 = value2; return function () { var val1 = v1.call(this); var val2 = v2.call(this); return o.call(this, val1, val2); }; }; var o = arithmetic.operator.visit(this, arg); var v1 = arithmetic.value_1.visit(this, arg); var v2 = arithmetic.value_2.visit(this, arg); return new Command(o, v1, v2); } }, { key: "visitPronounValue", /** * Pronoun Value */ value: function visitPronounValue(pronoun, arg) { var Command = function Command(p) { var pronoun = p; return function () { var p = pronoun.call(this); return this.characters[p].value(); }; }; var p = pronoun.pronoun.visit(this, arg); return new Command(p); } }, { key: "visitGreaterThanComparison", /** * Greater Than Comparison */ value: function visitGreaterThanComparison(comparison, arg) { var Command = function Command() { return function (a, b) { return a > b; }; }; return new Command(); } }, { key: "visitLesserThanComparison", /** * Lesser Than Comparison */ value: function visitLesserThanComparison(comparison, arg) { var Command = function Command() { return function (a, b) { return a < b; }; }; return new Command(); } }, { key: "visitEqualToComparison", /** * Equal To Comparison */ value: function visitEqualToComparison(comparison, arg) { var Command = function Command() { return function (a, b) { return a === b; }; }; return new Command(); } }, { key: "visitInverseComparison", /** * Inverse Comparison */ value: function visitInverseComparison(comparison, arg) { var Command = function Command(comparison) { var c = comparison; return function (a, b) { return !c(a, b); }; }; var c = comparison.comparison.visit(this, arg); return new Command(c); } }, { key: "visitFirstPersonPronoun", /** * First Person Pronoun */ value: function visitFirstPersonPronoun(fpp, arg) { var Command = function Command() { var speaking = arg.character; return function () { return speaking; }; }; return new Command(); } }, { key: "visitSecondPersonPronoun", /** * Second Person Pronoun */ value: function visitSecondPersonPronoun(spp, arg) { var Command = function Command() { var speaking = arg.character; return function () { return this.interlocutor(speaking).name(); }; }; return new Command(); } }, { key: "visitUnaryOperator", /** * Unary Operator */ value: function visitUnaryOperator(operator, arg) { var Command = function Command(operator) { var o = operator; switch (o) { case "square of": return function (v) { return Math.pow(v, 2); }; case "cube of": return function (v) { return Math.pow(v, 3); }; case "square root of": return function (v) { var sign = v < 0 ? -1 : 1; return sign * Math.floor(Math.sqrt(Math.abs(v))); }; case "factorial of": return function (v) { var sign = v < 0 ? -1 : 1; var num = Math.abs(v); var fv = 1; for (var i = 2; i <= num; i++) { fv = fv * i; } return sign * fv; }; case "twice": return function (v) { return 2 * v; }; } }; var o = operator.sequence; return new Command(o); } }, { key: "visitArithmeticOperator", /** * Arithmetic Operator */ value: function visitArithmeticOperator(operator, arg) { var Command = function Command(operator) { var o = operator; switch (o) { case "sum of": return function (a, b) { return a + b; }; case "difference between": return function (a, b) { return a - b; }; case "product of": return function (a, b) { return a * b; }; case "quotient between": return function (a, b) { return Math.round(a / b); }; case "remainder of the quotient between": return function (a, b) { return a % b; }; } }; var o = operator.sequence; return new Command(o); } }, { key: "visitBe", /** * Be */ value: function visitBe(be, arg) { var Command = function Command(be) { var b = be; var speaking = arg.character; switch (b) { case "Th