Notes on the implementation of CSC, a javascript interactive fiction engine:
CSC will have two components: a parser/compiler that turns scripts into JSON files, and a runtime engine that takes the JSON files and runs the game. The runtime engine can either run in the browser as an HTML file, or run in the terminal with node.js (and for randomtests).
Technically the JSON files will be independent of the javascript runtime, so it would be theoretically possible to do something like compile it to zcode or glulx (not that I've ever thought of doing it, or that it was one of the impetuses for this project in the first place...).
Organization of the JSON files: each "line" of text is an object, which potentially contains fields for text, goto, conditionals, etc. Arithmetic and boolean expressions are represented as arrays of tokens in reverse Polish notation (probably inefficient; might compile it down in the future). Scenes are arrays of line objects. Labels are represented separately as a map of label name to line number.
Parsing strategy: very basic; I'm not going to bother writing a formal grammar lol (I considered writing a grammar in antlr but it seems to be more trouble than it's worth). It's much easier to just read the first token of a line and see if it matches a keyword or special character, and run a method based on the keyword match.
Runtime strategy: game engine keeps track of state (including current scene + line), decides which line to see next, reads the line, converts the line object to a text string, keep going until hitting a choice or a page_break, at which point it displays the text block. Saving will be built-in and easy.
Compilation: I'll probably start with a command-line compiler using node + browserify (specifically based on how Dendry does it). Have user-editable html/css templates. I also want to make a web-based compiler that can take in uploaded scripts and templates and convert them to html. But I want to try implementing this feature in dendry first.
Features that already diverge from choicescript:
There will be an actual order-of-precedence parser for the arithmetic expressions - no use of ridiculous parentheses. This is the first thing I implemented in fact.















