Improve parser - generate prims from globals
[clnl] / src / main / parse.lisp
index eaaa3fe1d5fdf70c82d43c77431caacfaf5e7dea..c4270190c3c10654f7d517d86442833969c0ebc8 100644 (file)
 (defun prim-structure-prim (prim) (getf prim :structure-prim))
 (defun prim-is-infix (prim) (getf prim :infix))
 
-(defun find-prim (symb) (find symb *prims* :key #'prim-name))
+(defun find-prim (symb)
+ (or
+  (find symb *prims* :key #'prim-name)
+  (find symb *dynamic-prims* :key #'prim-name)))
 
 ; Make this only as complicated as it needs to be, letting it grow
 ; as we take on more and more of the language
  "PARSE LEXED-AST &optional DYNAMIC-PRIMS => AST
 
   DYNAMIC-PRIMS: DYNAMIC-PRIM*
+  DYNAMIC-PRIM: (:name NAME :args ARGS :infix INFIX)
+  ARGS: ARG*
 
 ARGUMENTS AND VALUES:
 
   LEXED-AST: An ambigious ast
   AST: An unambigious ast that can be transpiled
-  DYNAMIC-PRIM: A prim not statically defined
+  NAME: A symbol in the keyword package
+  INFIX: Boolean denoting whether the prim is infix
+  ARG: A list of symbols denoting the type of argument
 
 DESCRIPTION:
 
@@ -54,6 +61,9 @@ DESCRIPTION:
   things not statically defined by the NetLogo language, be they user defined
   procedures or generated primitives from breed declarations.
 
+  The possible values for ARG are :agentset, :boolean, :number, :command-block,
+  or t for wildcard.
+
   The need for a parser between the lexer and the transpiler is because NetLogo
   needs two passes to turn into something that can be used.  This is the only entry
   point into this module, and should probably remain that way.
@@ -210,6 +220,7 @@ DESCRIPTION:
 (defprim :hatch (:number :command-block))
 (defprim :let (t t))
 (defprim :if (:boolean :command-block))
+(defprim :if-else (:boolean :command-block :command-block))
 (defprim :ifelse (:boolean :command-block :command-block))
 (defprim :label ())
 (defprim :label-color ())
@@ -251,18 +262,6 @@ DESCRIPTION:
 
 ; Placeholder prims that should be populated in dynamic prims
 
-; Generated by globals/widgets
-(defprim :grass ())
-(defprim :initial-number-sheep ())
-(defprim :initial-number-wolves ())
-(defprim :sheep-gain-from-food ())
-(defprim :wolf-gain-from-food ())
-(defprim :sheep-reproduce ())
-(defprim :wolf-reproduce ())
-(defprim :grass? ())
-(defprim :grass-regrowth-time ())
-(defprim :show-energy? ())
-
 ; Generated by procedures
 (defprim :move ())
 (defprim :eat-grass ())
@@ -273,10 +272,6 @@ DESCRIPTION:
 (defprim :grow-grass ())
 (defprim :display-labels ())
 
-; Generated by *-own
-(defprim :countdown ())
-(defprim :energy ())
-
 ; Generated by a let
 (defprim :prey ())