Browse Source

Initial Base Created

Norikawa 3 years ago
parent
commit
9e8dd4cc1a
6 changed files with 116 additions and 2 deletions
  1. 2
    0
      .gitignore
  2. 2
    2
      LICENSE
  3. 21
    0
      src/cryo.cr
  4. 12
    0
      src/cryo/lexer.cr
  5. 37
    0
      src/cryo/lexer/typers.cr
  6. 42
    0
      src/cryo/scanner.cr

+ 2
- 0
.gitignore View File

@@ -1 +1,3 @@
1 1
 cryo.code-workspace
2
+schema
3
+src/test.cr

+ 2
- 2
LICENSE View File

@@ -1,5 +1,5 @@
1
-[Work Title]
2
-Copyright [Author] [Year]
1
+CryO
2
+Copyright Rick Novile / Norikawa 2019
3 3
 
4 4
 COOPERATIVE SOFTWARE LICENSE
5 5
 

+ 21
- 0
src/cryo.cr View File

@@ -0,0 +1,21 @@
1
+require "./cryo/*"
2
+require "./ext/*"
3
+
4
+module CryO 
5
+    @@keywords = ["if", "cond", "while", "define", "function", "read", "print", "lambda", "undefine"]
6
+    @@boolean = ["true", "false"]
7
+    @@env = Hash(String, String).new
8
+
9
+    def self.env
10
+        return @@env
11
+    end
12
+
13
+    def self.keywords
14
+        return @@keywords
15
+    end
16
+
17
+    def self.boolean
18
+        return @@boolean
19
+    end
20
+
21
+end

+ 12
- 0
src/cryo/lexer.cr View File

@@ -0,0 +1,12 @@
1
+require "./lexer/*"
2
+
3
+module CryO
4
+    class Lexer
5
+        getter current = ""
6
+
7
+        def initialize(str : String)
8
+            @input = CryO::Scanner.new(str)
9
+        end
10
+
11
+    end
12
+end

+ 37
- 0
src/cryo/lexer/typers.cr View File

@@ -0,0 +1,37 @@
1
+module CryO
2
+    class Lexer
3
+        def is_whitespace?(char)
4
+            return "\t\n".index(char) != nil
5
+        end
6
+
7
+        def is_syntax?(char)
8
+            return "(){}[]".index(char) != nil
9
+        end
10
+
11
+        def is_operator?(char)
12
+            return "+-=/*%^&!|<>".index(char) != nil
13
+        end
14
+
15
+        def is_identifier_start?(char)
16
+            return char =~ /[a-z_]/i != nil
17
+        end
18
+
19
+        def is_identifier?(char)
20
+            return is_identifier?(char) || "-!?+0123456789".index(char) != nil
21
+        end
22
+
23
+        def is_number?(char)
24
+            return char =~ /[0-9]/i != nil
25
+        end
26
+
27
+        def is_keyword?(str)
28
+            return CryO.keywords.index(str) != nil
29
+        end
30
+
31
+        def is_function?(str)
32
+            return CryO.env.keys.index(str) != nil
33
+        end
34
+
35
+
36
+    end
37
+end

+ 42
- 0
src/cryo/scanner.cr View File

@@ -0,0 +1,42 @@
1
+module CryO
2
+    class Scanner
3
+        getter offset = 0
4
+        getter column = 1
5
+        getter line = 1
6
+        getter input : String
7
+
8
+        def initialize(str : String)
9
+            @input = str
10
+        end
11
+        
12
+        def peek
13
+            unless end?
14
+                return @input[@offset + 1]
15
+            end
16
+            return error("Scanner.peek(): End of String reached")
17
+        end
18
+
19
+        def next
20
+            unless end?
21
+                result = peek()
22
+                @offset += 1
23
+                if(peek() == "\n")
24
+                    @column = 1
25
+                    @line += 1
26
+                else
27
+                    @column += 1
28
+                end
29
+                return result
30
+            end
31
+            return error("Scanner.next(): End of String reached")
32
+        end
33
+
34
+        def end?
35
+            return @offset >= @input.size - 1
36
+        end
37
+
38
+        def error(msg : String)
39
+            raise "[CryO] " + msg + " at Line " + @line.to_s + ", Column " + @column.to_s
40
+        end
41
+    end
42
+end

Loading…
Cancel
Save