Ver código fonte

Change comment string to take advantage of LISP syntax highlighting

Matt Coles 9 anos atrás
pai
commit
fdf39c3008
3 arquivos alterados com 17 adições e 17 exclusões
  1. 2 2
      README.md
  2. 2 2
      compiler.js
  3. 13 13
      example.mc

+ 2 - 2
README.md

3
 A basic compiler based off of @thejameskyle's super-tiny-compiler, compiles a simple LISP-esque syntax into runnable JS.
3
 A basic compiler based off of @thejameskyle's super-tiny-compiler, compiles a simple LISP-esque syntax into runnable JS.
4
 
4
 
5
 Currently supports a few built-ins, `add`, `subtract`, `assign`, `def` and `log`. Hopefully these are self-explanatory, or at least 
5
 Currently supports a few built-ins, `add`, `subtract`, `assign`, `def` and `log`. Hopefully these are self-explanatory, or at least 
6
-they should be from `example.mc`. A `#` denotes that the rest of the line (until the compiler sees `\n`) as a comment and 
7
-means that it will not be compiled, these may **not** be used within brackets (eg a function definition).
6
+they should be from `example.mc`. A `;` denotes that the rest of the line (until the compiler sees `\n`) as a comment and 
7
+means that it will not be compiled.
8
 
8
 
9
 The compiler runs like `node compiler.js file.mc` where `file.mc` is the file you wish to compile, and this will produce an
9
 The compiler runs like `node compiler.js file.mc` where `file.mc` is the file you wish to compile, and this will produce an
10
 `output.js` which requires `stdlib.js` to be in the same directory when running for now at least.
10
 `output.js` which requires `stdlib.js` to be in the same directory when running for now at least.

+ 2 - 2
compiler.js

17
       pos++
17
       pos++
18
       continue
18
       continue
19
     }
19
     }
20
-    let whitespace = /[#\s]/
20
+    let whitespace = /[;\s]/
21
     if (whitespace.test(char)) {
21
     if (whitespace.test(char)) {
22
-      if (char === '#') {
22
+      if (char === ';') {
23
         comment = ''
23
         comment = ''
24
         while (char !== '\n') {
24
         while (char !== '\n') {
25
           comment += char
25
           comment += char

+ 13 - 13
example.mc

1
-# This is a test program
2
-(assign twelve 12) # This assigns the variable twelve, to the number literal 12
3
-(assign myvar (add twelve (subtract 6 2))) # This assigns the variable myvar, to the result of adding the variable twelve to the result of subtracting 2 from 6
4
-(log myvar) # This logs the value of myvar
5
-(log 6) # This logs the number literal 6
6
-(assign twelve myvar) # This reassigns the variable twelve to the value of the variable myvar
7
-(log twelve) # This logs the new value of the variable twelve
8
-# An example function definition
9
-(def myF 
1
+; This is a test program
2
+(assign twelve 12) ; This assigns the variable twelve, to the number literal 12
3
+(assign myvar (add twelve (subtract 6 2))) ; This assigns the variable myvar, to the result of adding the variable twelve to the result of subtracting 2 from 6
4
+(log myvar) ; This logs the value of myvar
5
+(log 6) ; This logs the number literal 6
6
+(assign twelve myvar) ; This reassigns the variable twelve to the value of the variable myvar
7
+(log twelve) ; This logs the new value of the variable twelve
8
+; An example function definition
9
+(def myF ; Anywhere is a valid position for a comment!
10
   (log 0) 
10
   (log 0) 
11
   (log twelve) 
11
   (log twelve) 
12
   (log 6) 
12
   (log 6) 
14
   (assign scopelol (add twelve 5)) 
14
   (assign scopelol (add twelve 5)) 
15
   (log scopelol)
15
   (log scopelol)
16
 )
16
 )
17
-(def argTest (log $1) (log $2)) # Functions take an unlimited number of arguments that can be referred to by $n
18
-(myF) # Calling an argument-less function
17
+(def argTest (log $1) (log $2)) ; Functions take an unlimited number of arguments that can be referred to by $n
18
+(myF) ; Calling an argument-less function
19
 (log 0)
19
 (log 0)
20
 (log 0)
20
 (log 0)
21
+(log 1)
21
 (log 0)
22
 (log 0)
22
 (log 0)
23
 (log 0)
23
 (log 0)
24
 (log 0)
24
-(log 0)
25
-(argTest 43 scopelol) # Custom functions with arguments are called like any other
25
+(argTest 43 scopelol) ; Custom functions with arguments are called like any other