Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:ngokevin/cs480_milestones

  • Loading branch information...
commit 73b8a37f16cec2c4756f882aa4dcd9b4039bd8ea 2 parents fa9581d + 0085b5b
@mythmon mythmon authored
Showing with 220 additions and 11 deletions.
  1. +193 −6 lexer.rb
  2. +27 −5 stutest1.in
View
199 lexer.rb
@@ -34,11 +34,89 @@
end
end while l
- # parentheses
- l = s.scan(/[()]/)
+ # =========================================
+ # PRIMITIVE TYPES (bool, int, real, string)
+ # =========================================
+ # bool
+ l = s.scan(/bool/)
if l
- token = Token.new(:openparen) if l == '('
- token = Token.new(:closeparen) if l == ')'
+ token = Token.new(:bool)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ # int
+ l = s.scan(/int/)
+ if l
+ token = Token.new(:int)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ # real
+ l = s.scan(/real/)
+ if l
+ token = Token.new(:real)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ # string
+ l = s.scan(/string/)
+ if l
+ token = Token.new(:string)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ # ========================================
+ # REAL FUNCTIONS (log, e^n, sin, cos, tan)
+ # ========================================
+
+ # log
+ l = s.scan(/log/)
+ if l
+ token = Token.new(:log)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ # e^n
+ l = s.scan(/e/)
+ if l
+ token = Token.new(:e)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ # sin
+ l = s.scan(/sin/)
+ if l
+ token = Token.new(:sin)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ # cos
+ l = s.scan(/cos/)
+ if l
+ token = Token.new(:cos)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ # tan
+ l = s.scan(/tan/)
+ if l
+ token = Token.new(:tan)
st.try_set(l, token)
tokens << token
next
@@ -93,6 +171,115 @@
next
end
+ # =====================================================
+ # OPERATORS (and, or, not, iff, +, -, *, /, %, ^, =, <)
+ # =====================================================
+ l = s.scan(/and/)
+ if l
+ token = Token.new(:and)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ l = s.scan(/or/)
+ if l
+ token = Token.new(:or)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ l = s.scan(/not/)
+ if l
+ token = Token.new(:not)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ l = s.scan(/iff/)
+ if l
+ token = Token.new(:iff)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ l = s.scan(/\+/)
+ if l
+ token = Token.new(:add)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ l = s.scan(/\-/)
+ if l
+ token = Token.new(:subtract)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ l = s.scan(/\*/)
+ if l
+ token = Token.new(:multiply)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ l = s.scan(/\//)
+ if l
+ token = Token.new(:divide)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ l = s.scan(/\%/)
+ if l
+ token = Token.new(:modulus)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ l = s.scan(/\^/)
+ if l
+ token = Token.new(:power)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ l = s.scan(/\=/)
+ if l
+ token = Token.new(:equals)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ l = s.scan(/\</)
+ if l
+ token = Token.new(:lessthan)
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
+ # parentheses
+ l = s.scan(/[()]/)
+ if l
+ token = Token.new(:openparen) if l == '('
+ token = Token.new(:closeparen) if l == ')'
+ st.try_set(l, token)
+ tokens << token
+ next
+ end
+
# ==========================================
# CONSTANTS (boolean, integer, real, string)
# ==========================================
@@ -108,7 +295,7 @@
end
# reals
- l = s.scan(/\d+\.(\d+)?/)
+ l = s.scan(/\-?\d+\.(\d+)?/)
if l
token = RealToken.new(:real, l.to_f)
st.try_set(l, token)
@@ -117,7 +304,7 @@
end
# integers
- l = s.scan(/\d+/)
+ l = s.scan(/\-?\d+/)
if l
token = IntegerToken.new(:int, l.to_i)
st.try_set(l, token)
View
32 stutest1.in
@@ -1,5 +1,27 @@
-(let ((my_var int) (my_var2 int))
- ((if true false)
- (println ("YEAH" 45))
- (assign my_var 42)
- (assign my_var2 "HEY")))
+(if (((not true) iff true) and (false or true)) (
+ (println (+ - * / ^ 1 -2 3.5 4 5 6))
+ (if ((1(=)1) and ("a"(<)"b")) (
+ (println ("TeSt" + 'In' + G))
+ ))
+))
+
+(let ((my_var1 bool)(my_var2 int)(my_var3 real)(my_var4 string)) (
+ (assign my_var1 true)
+ (assign my_var2 5)
+ (assign my_var3 3.14)
+ (assign my_var4 "test")
+))
+
+(println (log 90.0))
+(println (sin 90.0))
+(println (cos 90.0))
+(println (tan 90.0))
+(println (e 90.0))
+
+(assign i 0)
+(while (i(<)5) (
+ (println (i % 5))
+ (assign i (+ i 1))
+))
+
+(`~!@#$%^&*{}[]:";'<>?,./)

0 comments on commit 73b8a37

Please sign in to comment.
Something went wrong with that request. Please try again.