4 ms·
If we disregard the macros I think lisp's syntax is the abstract syntax tree. Could we say that concetanative languages like forth have no syntax. It seems to
by terminalcommand 9y ago
If we disregard the macros I think lisp's syntax is the abstract syntax tree.
Could we say that concetanative languages like forth have no syntax. It seems to me there is no AST in those languages, just a stack.
I'm not formally trained in CS, so that's my own individual opinnion.
- thaumasiotes 9y agoForth is written as a syntax tree in exactly the manner of Lisp. There are two differences, neither of which affects the fact that you express the AST directly: 1. Lisp is written preorder; Forth is written postorder. 2. The number of children a node in your Lisp AST has is marked explicitly, by parentheses, whereas the number of children a node in your Forth AST has is defined externally. There is no difference between a Lisp-style (+ (* 3 5 8) (+ 4 1)) and a Forth-style 3 5 8 * * 4 1 + + except that the * in Forth-style can't take a variable number of arguments. But if you added parens to Forth, it could: ((3 5 8 *) (4 1 +) +)
- white-flame 9y agoor take the number of args as another parameter. Assuming N* multiplies N items from the stack: 3 5 8 3 N* 4 1 + + The equivalent of (+ (* 3 5 8) 4 1) could be 3 5 8 3 N* 4 1 3 N+
- kazinator 9y agoThat isn't a syntax tree. > the number of children a node in your Forth AST has is defined externally and that's basically why. Here's a 1000 node AST: foo / \ Where are the rest of the nodes? Oh, they are defined externally.
- lispm 9y agoLisp has built-in syntax for example in the form of special operators. LET is an example. LET provides bindings for variables: LET a list of bindings a sequence of declarations a sequence of expressions (LET ((a 1) (b 2) c) (declare (integer a)) (declare (type (integer 0 100) b) (setq c (+ a b)) (expt c 2)) The EBNF syntax for LET is: let ({var | (var [init-form])}*) declaration* form* DECLARATION and FORM have more syntax. If Lisp sees a LET form which does not use above syntax, then it is a syntax error. A compiler or interpreter will tell you that. The compiler will detect that at compile time. The following forms are all errors: (let a 10 (+ a 10)) (let (a 10) (+ a 10)) ; 10 is not an identifier (LET (((A) 10)) (+ a 10)) ; (a) is not an identifier (let ((a 10)) (+ a 10) (declare (integer a))) ; declaration at wrong place (let ((a = 10)) (a + 10)) ; Lisp has no infix operators...