summaryrefslogtreecommitdiff
path: root/dice-lang/lang-process.md
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-10-27 21:40:28 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-10-27 21:40:28 -0400
commite13a6981bd278c2cfc3b5ecb2517367b117f7a52 (patch)
treec6a07aef91b5412a2f345316ccaa2fa8d0972e19 /dice-lang/lang-process.md
parentbb27392419549bb40cbc4f194e38f471d2b9f63d (diff)
Work on documentation
Continued work on documenting how exactly the language works
Diffstat (limited to 'dice-lang/lang-process.md')
-rw-r--r--dice-lang/lang-process.md62
1 files changed, 62 insertions, 0 deletions
diff --git a/dice-lang/lang-process.md b/dice-lang/lang-process.md
new file mode 100644
index 0000000..3504738
--- /dev/null
+++ b/dice-lang/lang-process.md
@@ -0,0 +1,62 @@
+# Top level reader loop
+First, a command is read in from the user under a prompt
+
+Next, it is checked if the first token of the command (split on " ")
+corresponds to an action name
+* If it does, the corresponding action is executed, and the next command is
+ read
+* If it doesn't, the command is parsed as a language command and executed
+
+This continues until the command "quit" (non case-sensitive) is read
+
+# Known actions
+The currently implemented actions are:
+* env: print out the contents of the enviroment. Takes no arguments
+* inline: inline variables out of the definition of specified variables. Takes
+ at least two arguments
+ * The first is the name of the variable to do inlining in
+ * The second is the name of the variable to bind the inlined expression to
+ * The third and following are the names of the variables to inline in the
+ variable you are inlining
+
+## Details on inlining
+
+
+# Parsing language commands
+Once it is decided to parse a command as a language command, it goes through
+four steps:
+* Preparation
+* AST Building
+* AST Transformation
+* AST Evaluation
+
+# Command preparation
+Command preparation means turning the raw space-seperated tokens into tokens
+suitable for feeding the AST builder. It involves the following steps:
+* The first is operator expansion, which turns a token like 4+4 into the three
+ tokens 4, +, and 4
+* The next is token deaffixation which turns a token like (4 into the tokens (
+ and 4. However, ((4 will become (( 4, not ( ( 4, because (( is a different
+ nesting level than (
+* Next, any blank tokens that have been created as a result of the process are
+ disposed of
+* Finally, the entire expression is shunted, turning it from infix notation to
+ postfix notation. The only real special thing about this is that (( is a
+ different nesting level than (. The token precedence levels are (sorted from
+ lower to higher precedence):
+ * Math precedence
+ * + & -
+ * * & /
+ *
+ * Dice precedence
+ * d
+ * c
+ * Expression precedence
+ * =>
+ * :=
+
+# AST Building
+AST building is a slightly more complex process, as the tree is traversed
+twice: once to build the tree, and then again to convert the tokens from
+strings into data tokens. The only really finicky part about the first tree is
+arrays, because arrays are still in infix form at this point.