mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	* Added mgiannini/sublime-factor as a submodule Provided better color for Fantom Added license for sublime-fantom Specified tm_scope for Fantom * Redirected submodule for Fantom to fork with updated grammar * Triggering build * Updating sublime-fantom submodule * Updated submodule sublime-fantom * Adding Fantom samples
		
			
				
	
	
		
			51 lines
		
	
	
		
			693 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			693 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
/*
 | 
						|
 * Author: Robert Koeninger
 | 
						|
 * License: WTFPL (http://www.wtfpl.net/)
 | 
						|
 */
 | 
						|
 | 
						|
mixin Expr
 | 
						|
{
 | 
						|
  abstract Obj? eval()
 | 
						|
}
 | 
						|
 | 
						|
class Constant : Expr
 | 
						|
{
 | 
						|
  Obj? value
 | 
						|
 | 
						|
  new make(Obj? value) { this.value = value }
 | 
						|
  override Obj? eval() { value }
 | 
						|
}
 | 
						|
 | 
						|
enum class Op
 | 
						|
{
 | 
						|
  plus,
 | 
						|
  minus
 | 
						|
}
 | 
						|
 | 
						|
class Infix : Expr
 | 
						|
{
 | 
						|
  Op op
 | 
						|
  Expr left
 | 
						|
  Expr right
 | 
						|
 | 
						|
  new make(Op op, Expr left, Expr right)
 | 
						|
  {
 | 
						|
    this.op = op
 | 
						|
    this.left = left
 | 
						|
    this.right = right
 | 
						|
  }
 | 
						|
 | 
						|
  override Obj? eval()
 | 
						|
  {
 | 
						|
    switch (op)
 | 
						|
    {
 | 
						|
      case Op.plus:
 | 
						|
        return (Int)left.eval() + (Int)right.eval()
 | 
						|
      case Op.minus:
 | 
						|
        return (Int)left.eval() - (Int)right.eval()
 | 
						|
      default:
 | 
						|
        throw Err("undefined Op")
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 |