X-Git-Url: https://code.consxy.com/gitweb/gitweb.cgi?a=blobdiff_plain;f=src%2Fmain%2Fparse.lisp;h=1e5c30593fed8acc330095f4b90f277e0da0c5fb;hb=d568495;hp=a88d833c493f3b2b1ca6148843238852f953874e;hpb=4a9ed570e6d2c79ac7cac0a6a84d414ee658cd3e;p=clnl diff --git a/src/main/parse.lisp b/src/main/parse.lisp index a88d833..1e5c305 100644 --- a/src/main/parse.lisp +++ b/src/main/parse.lisp @@ -1,4 +1,4 @@ -(in-package #:cl-nl.parser) +(in-package #:clnl-parser) ; Ok, after thinking about this a little, the parser is completely contextual ; based on what has come before. We can't do a contextless parsing, like we @@ -31,6 +31,26 @@ ; Make this only as complicated as it needs to be, letting it grow ; as we take on more and more of the language (defun parse (lexed-ast) + "PARSE LEXED-AST => AST + +ARGUMENTS AND VALUES: + + LEXED-AST: An ambigious ast + AST: An unambigious ast that can be transpiled + +DESCRIPTION: + + PARSE takes a ambigious LEXED-AST and converts it to an unambigious one. + + 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. + + There's also a lot of error checking that the LEXED-AST even makes sense, even + though the lexer obviously thought it did. + + Examples are too numerous and varied, but by inserting an output between + the lexer and this code, a good idea of what goes on can be gotten." (cond ((not lexed-ast) nil) ((numberp (car lexed-ast)) (cons (coerce (car lexed-ast) 'double-float) (parse (cdr lexed-ast)))) @@ -45,7 +65,7 @@ (prim-name prim) (mapcar #'help-arg - (prim-args prim) + (prim-args prim) (butlast parsed-remainder (- (length parsed-remainder) num-args)))) (nthcdr num-args parsed-remainder)))) (t (error "Couldn't parse ~S" lexed-ast)))) @@ -54,8 +74,8 @@ (case arg-type (:command-block (if (not (and (consp arg) (eql 'block (car arg)))) - (error "Required a block, but found a ~A" arg) - (cons :command-block (cdr arg)))) + (error "Required a block, but found a ~A" arg) + (cons :command-block (cdr arg)))) (t arg))) (defun parse-block (tokens) @@ -83,9 +103,12 @@ ; This list of prims will get combined with the mapping to actual code later ; Current list of argument types we accept: ; - :number +; - :agentset +; - :command-block ; - t - any type (defprim :ask (:agentset :command-block)) (defprim :crt (:number)) (defprim :fd (:number)) +(defprim :random-float (:number)) (defprim :show (t)) (defprim :turtles ())