]> git.mdlowis.com Git - proto/sclpl-rb.git/commitdiff
added bare minimum constant parsing (only ints)
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 30 Jul 2019 17:47:23 +0000 (13:47 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 30 Jul 2019 17:47:23 +0000 (13:47 -0400)
compile.rb
example.src

index db7151c21d916ef0ad4a742142229a8d7c1c0cd0..aa3186a2e2a7bca253f82ca3ebf62855cd0f99a6 100755 (executable)
@@ -145,8 +145,23 @@ class Lexer
 end
 
 class Parser
+  LEVELS = {
+    none:     0,
+    assign:   1,
+    or:       2,
+    and:      3,
+    equality: 4,
+    compare:  5,
+    term:     6,
+    factor:   7,
+    unary:    8,
+    call:     9,
+    primary: 10,
+  }
+
   def initialize(path)
     @lex = Lexer.new(path)
+    @prev = nil
     @next = nil
   end
 
@@ -179,15 +194,19 @@ class Parser
     defs
   end
 
+  private
+
   def topdef(defs)
     dectype = declaration(defs)
     if dectype == :fun then
       expect("{")
+      value = expression()
       expect("}")
     else
       expect("=")
-      expect(:int)
+      value = expression()
     end
+    pp value
   end
 
   def declaration(syms)
@@ -223,7 +242,20 @@ class Parser
     end
   end
 
-  private
+  def parseLevel(level)
+  end
+
+  def expression()
+    constant()
+  end
+
+  def constant()
+    if (peek().type == :int)
+      AST::Value.new(Type::Int, consume().text.to_i)
+    else
+      error("not a valid constant")
+    end
+  end
 
   def error(str)
     raise str
@@ -240,6 +272,7 @@ class Parser
 
   def accept(type)
     if (matches(type))
+      @prev = @next
       @next = nil
       true
     else
index 5bc65b9ef835078ff0a9077a4406bc4aad121f8c..c5b48c177e210ababab867c05929198d9476d18c 100644 (file)
@@ -7,5 +7,5 @@ provides {
 let foo int = 42
 
 fun main(args string[]) int {
-
+  42
 }