mirror of
https://github.com/Ed94/LangStudies.git
synced 2025-01-21 20:13:45 -08:00
EOI: Lecture 13 complete
This commit is contained in:
parent
a6c99fcfa6
commit
88644a95df
@ -136,6 +136,11 @@ func eval( ast ):
|
||||
NType.op_LesserEqual:
|
||||
return eval( ast.arg(1) ) <= eval( ast.arg(2) )
|
||||
|
||||
NType.op_Equal:
|
||||
return eval( ast.arg(1) ) == eval( ast.arg(2) )
|
||||
NType.op_NotEqual:
|
||||
return eval( ast.arg(1) ) != eval( ast.arg(2) )
|
||||
|
||||
NType.fn_Print :
|
||||
return eval_Print( ast )
|
||||
|
||||
@ -226,10 +231,10 @@ func eval_Numeric( ast ):
|
||||
return result
|
||||
|
||||
if ast.type() == NType.op_Sub:
|
||||
if ast.num_args() == 2:
|
||||
if ast.num_args() < 2:
|
||||
return -eval( ast.arg(1) )
|
||||
|
||||
var result = 0.0; var index = 1
|
||||
var result = eval( ast.arg(1) ); var index = 2
|
||||
|
||||
while index <= ast.num_args():
|
||||
result -= eval( ast.arg(index) )
|
||||
@ -247,11 +252,11 @@ func eval_Numeric( ast ):
|
||||
return result
|
||||
|
||||
if ast.type() == NType.op_Div:
|
||||
var result = 1.0; var index = 1
|
||||
var result = eval( ast.arg(1) ); var index = 2
|
||||
|
||||
while index <= ast.num_args():
|
||||
result /= eval( ast.arg(index) )
|
||||
result += 1
|
||||
index += 1
|
||||
|
||||
return result
|
||||
|
||||
|
@ -37,8 +37,9 @@ const TType : Dictionary = \
|
||||
literal_String = "Literal: String",
|
||||
|
||||
op_Assgin = "Assignment",
|
||||
op_Numeric = "op_Numeric",
|
||||
op_Relational = "op_Relational",
|
||||
op_Numeric = "Numeric Operation",
|
||||
op_Relational = "Relational Operation",
|
||||
op_Equality = "Equality Operation",
|
||||
|
||||
fn_Print = "Print",
|
||||
|
||||
@ -72,6 +73,7 @@ const Spec : Dictionary = \
|
||||
TType.op_Assgin : "start \"set\"",
|
||||
TType.op_Numeric : "start set(+ \\- * /)",
|
||||
TType.op_Relational : "start set(> <) =.repeat(0-1)",
|
||||
TType.op_Equality : "start \\!.repeat(0-1) =",
|
||||
|
||||
TType.fn_Print : "start \"print\"",
|
||||
|
||||
|
@ -43,6 +43,8 @@ const NType = \
|
||||
op_GreaterEqual = ">=",
|
||||
op_Lesser = "<",
|
||||
op_LesserEqual = "<=",
|
||||
op_Equal = "=",
|
||||
op_NotEqual = "!=",
|
||||
|
||||
fn_Print = "Print",
|
||||
fn_User = "User Function",
|
||||
@ -190,6 +192,14 @@ func parse_Expression():
|
||||
node = parse_op_Numeric()
|
||||
TType.op_Relational:
|
||||
node = parse_op_Relational()
|
||||
TType.op_Equality:
|
||||
node = ASTNode.new()
|
||||
match NextToken.Value:
|
||||
NType.op_Equal:
|
||||
node.set_Type(NType.op_Equal)
|
||||
NType.op_NotEqual:
|
||||
node.set_Type(NType.op_NotEqual)
|
||||
eat(TType.op_Equality)
|
||||
TType.identifier:
|
||||
node = parse_op_Fn()
|
||||
TType.def_Start:
|
||||
|
Loading…
x
Reference in New Issue
Block a user