com.github.gchudnov.bscript.lang.ast

Type members

Classlikes

abstract class AST
Companion:
object
object AST
Companion:
class
final case class Access(a: LValue, b: LValue, evalType: Type, promoteToType: Option[Type]) extends LValue

Access a field of a Struct

Access a field of a Struct

To access members of a struct like a.x, we trigger two ref operations. The first ref operation looks up a to figure out what type it is. The second ref then resolves x within a’s scope (upon seeing the . node). We match (possibly nested) member access expressions, e.g.:

   "a", "a.b", "a.b.c", and so on

Given «expr».x, member need’s «expr»’s type because it must look up x with the scope of «expr».

Companion:
object
object Access
Companion:
class
final case class Add(lhs: Expr, rhs: Expr, evalType: Type, promoteToType: Option[Type]) extends BinOp

Addition

Addition

 a + b;
Companion:
object
object Add
Companion:
class
final case class And(lhs: Expr, rhs: Expr, evalType: Type, promoteToType: Option[Type]) extends LogicOp

Logic And

Logic And

 a AND b;
Companion:
object
object And
Companion:
class
trait Ann

Annotation to apply to an AST element

Annotation to apply to an AST element

final case class ArgDecl(aType: Type, name: String, symbol: Symbol, evalType: Type, promoteToType: Option[Type]) extends Decl

Argument Declaration

Argument Declaration

Companion:
object
object ArgDecl
Companion:
class
final case class Assign(id: LValue, expr: Expr, evalType: Type, promoteToType: Option[Type]) extends Expr

Assigns a value to the variable that already exists.

Assigns a value to the variable that already exists.

 int x; // defined before

 x = 10 + 2; // assignment here
Companion:
object
object Assign
Companion:
class
final class AstException(message: String) extends LangException
Companion:
object
Companion:
class
abstract class BinOp extends Expr

Binary Operation

Binary Operation

 +, -, *, /
final case class Block(statements: List[Expr], symbol: Symbol, evalType: Type, promoteToType: Option[Type]) extends Expr

Block of code

Block of code

Contains zero or more statements

 {
   int x;
   { ... } // <- nested block

   long y = { "alice"; 1 + 2; }; // here last value is returned and assigned to `y`
 }
Value parameters:
statements

Statements included in the block

Companion:
object
object Block
Companion:
class
final case class BoolVal(value: Boolean, evalType: Type, promoteToType: Option[Type]) extends ConstVal

Boolean Literal

Boolean Literal

 true, false
Companion:
object
object BoolVal
Companion:
class
final case class Call(id: Symbol, args: Seq[Expr], evalType: Type, promoteToType: Option[Type]) extends Expr

Method (Function) Call

Method (Function) Call

 f(i);
Value parameters:
args

A list of arguments to pass

id

Symbol of the method to call

Companion:
object
object Call
Companion:
class
final case class ComAnn(value: String) extends Ann

Comment applied to AST

Comment applied to AST

final case class CompiledExpr(callback: Any => Either[Throwable, Any], retType: Type, evalType: Type, promoteToType: Option[Type]) extends Expr

Compile Expression to reuse functionality implemented in JVM

Compile Expression to reuse functionality implemented in JVM

The callback has a signature: Any => Either[Throwable, Any], inside of the callback there should be a pattern match and depending on the interpreter, Any is interpreted in a particular way, e.g. for InterpretVisitor: it is (InterpretState) => Either[Throwable, InterpretState]

Companion:
object
Companion:
class
abstract class ConstVal extends Expr

Any Constant Variable

Any Constant Variable

final case class DateTimeVal(value: OffsetDateTime, evalType: Type, promoteToType: Option[Type]) extends ConstVal

DateTime Literal

DateTime Literal

 "2007-12-03T10:15:30+01:00"
Companion:
object
Companion:
class
final case class DateVal(value: LocalDate, evalType: Type, promoteToType: Option[Type]) extends ConstVal

Date Literal

Date Literal

 2021-10-12
Companion:
object
object DateVal
Companion:
class
final case class DecimalVal(value: BigDecimal, evalType: Type, promoteToType: Option[Type]) extends ConstVal

Decimal Literal

Decimal Literal

 3.3
Companion:
object
object DecimalVal
Companion:
class
abstract class Decl extends Expr with HasSymbol with HasName
final case class Div(lhs: Expr, rhs: Expr, evalType: Type, promoteToType: Option[Type]) extends BinOp

Division

Division

 a / b
Companion:
object
object Div
Companion:
class
final case class DoubleVal(value: Double, evalType: Type, promoteToType: Option[Type]) extends ConstVal

Double Literal

Double Literal

 12.34
Companion:
object
object DoubleVal
Companion:
class
abstract class EqOp extends Expr

Equality Operation

Equality Operation

 !=, ==
final case class Equal(lhs: Expr, rhs: Expr, evalType: Type, promoteToType: Option[Type]) extends EqOp

Equality

Equality

 ==
Companion:
object
object Equal
Companion:
class
abstract class Expr extends Stat with HasStaticTypeSafety

Expression

Expression

Expressions are a special kind of Statement.

final case class FieldDecl(fType: Type, name: String, symbol: Symbol, evalType: Type, promoteToType: Option[Type]) extends Decl

Field Declaration in a Struct.

Field Declaration in a Struct.

 struct X {
   int x;
   float y;
 }
Companion:
object
object FieldDecl
Companion:
class
final case class FloatVal(value: Float, evalType: Type, promoteToType: Option[Type]) extends ConstVal

Float Literal

Float Literal

 12.34f
Companion:
object
object FloatVal
Companion:
class
final case class Greater(lhs: Expr, rhs: Expr, evalType: Type, promoteToType: Option[Type]) extends RelOp

Greater-Than

Greater-Than

 >
Companion:
object
object Greater
Companion:
class
final case class GreaterEqual(lhs: Expr, rhs: Expr, evalType: Type, promoteToType: Option[Type]) extends RelOp

Greater-Than OR Equal

Greater-Than OR Equal

 >=
Companion:
object
Companion:
class

Used for collections

Used for collections

Reference to an evalType

Reference to an evalType

The type of the value computed by the expression

trait HasName

Reference to promoteToType

Reference to promoteToType

The type we need to promote current type to before evaluation. If None - the promotion is not needed.

Aggregates both evalType and promoteToType to enforce static typing.

Aggregates both evalType and promoteToType to enforce static typing.

trait HasSymbol

Reference to a symbol

Reference to a symbol

final case class If(cond: Expr, then1: Expr, else1: Option[Expr], evalType: Type, promoteToType: Option[Type]) extends Expr

If Condition

If Condition

 if(cond) then { ... } else { ... }
 if(cond) then { ... }

 int x = if(conf) then { 1+2; } else { 2*5; }
Companion:
object
object If
Companion:
class
final case class Init(iType: Type, evalType: Type, promoteToType: Option[Type]) extends Expr

Initialization Node

Initialization Node

Used to init variable to the default value.

 int x; // here in AST, Init() is used to initialize the int var to 0.
Companion:
object
object Init
Companion:
class
final case class IntVal(value: Int, evalType: Type, promoteToType: Option[Type]) extends ConstVal

Int Literal

Int Literal

 12
Companion:
object
object IntVal
Companion:
class
abstract class LValue extends Expr
final case class Less(lhs: Expr, rhs: Expr, evalType: Type, promoteToType: Option[Type]) extends RelOp

Less-Than

Less-Than

 <
Companion:
object
object Less
Companion:
class
final case class LessEqual(lhs: Expr, rhs: Expr, evalType: Type, promoteToType: Option[Type]) extends RelOp

Less-Than OR Equal

Less-Than OR Equal

 <=
Companion:
object
object LessEqual
Companion:
class
abstract class LogicOp extends Expr

Logic Operation

Logic Operation

 AND, OR
final case class LongVal(value: Long, evalType: Type, promoteToType: Option[Type]) extends ConstVal

Long Literal

Long Literal

 12
Companion:
object
object LongVal
Companion:
class
final case class MethodDecl(retType: Type, name: String, params: Seq[ArgDecl], body: Block, symbol: Symbol, evalType: Type, promoteToType: Option[Type], annotations: Seq[Ann]) extends Decl

Method Declaration

Method Declaration

Companion:
object
object MethodDecl
Companion:
class
final case class Mod(lhs: Expr, rhs: Expr, evalType: Type, promoteToType: Option[Type]) extends BinOp

Modulo

Modulo

 a % b
Companion:
object
object Mod
Companion:
class
final case class Mul(lhs: Expr, rhs: Expr, evalType: Type, promoteToType: Option[Type]) extends BinOp

Multiplication

Multiplication

 a * b
Companion:
object
object Mul
Companion:
class
final case class Not(expr: Expr, evalType: Type, promoteToType: Option[Type]) extends UnLogicOp

Not

Not

 ! expr;
Companion:
object
object Not
Companion:
class
final case class NotEqual(lhs: Expr, rhs: Expr, evalType: Type, promoteToType: Option[Type]) extends EqOp

Not Equality

Not Equality

 !=
Companion:
object
object NotEqual
Companion:
class
final case class NothingVal(evalType: Type, promoteToType: Option[Type]) extends ConstVal
Companion:
object
object NothingVal
Companion:
class
final case class Or(lhs: Expr, rhs: Expr, evalType: Type, promoteToType: Option[Type]) extends LogicOp

Logic Or

Logic Or

 a OR b;
Companion:
object
object Or
Companion:
class
abstract class RelOp extends Expr

Relational Operation

Relational Operation

 <, >, <=, >=
abstract class Stat extends AST
final case class StdAnn() extends Ann

Marks code, related to standard-library.

Marks code, related to standard-library.

Used, for example, to prevent serialization of [std] functions.

Companion:
object
object StdAnn
Companion:
class
final case class StrVal(value: String, evalType: Type, promoteToType: Option[Type]) extends ConstVal

String Literal

String Literal

 "a"
Companion:
object
object StrVal
Companion:
class
final case class StructDecl(name: String, fields: Seq[FieldDecl], symbol: Symbol, evalType: Type, promoteToType: Option[Type]) extends Decl

Struct Declaration

Struct Declaration

Companion:
object
object StructDecl
Companion:
class
final case class StructVal(sType: Type, value: Map[String, Expr], symbol: Symbol, evalType: Type, promoteToType: Option[Type]) extends ConstVal

Struct Initializer

Struct Initializer

 struct A {
   a: int
   b: string
 };

 A = { a: 1, b: "hello" };
Companion:
object
object StructVal
Companion:
class
final case class Sub(lhs: Expr, rhs: Expr, evalType: Type, promoteToType: Option[Type]) extends BinOp

Subtract

Subtract

 a - b;
Companion:
object
object Sub
Companion:
class
abstract class UnLogicOp extends Expr

Unary Logic Operation

Unary Logic Operation

abstract class UnOp extends Expr

Unary Operation

Unary Operation

final case class UnaryMinus(expr: Expr, evalType: Type, promoteToType: Option[Type]) extends UnOp

Unary Minus

Unary Minus

 -10
Companion:
object
object UnaryMinus
Companion:
class
final case class Var(symbol: Symbol, evalType: Type, promoteToType: Option[Type]) extends LValue

Reference to a variable

Reference to a variable

 x;
Companion:
object
object Var
Companion:
class
final case class VarDecl(vType: Type, name: String, expr: Expr, symbol: Symbol, evalType: Type, promoteToType: Option[Type]) extends Decl

Variable Declaration

Variable Declaration

The AST for int i; would have VARDECL at the root and int and i as children.

 int x;
 float y = 10;
Companion:
object
object VarDecl
Companion:
class
final case class Vec(elements: Seq[Expr], elementType: Type, evalType: Type, promoteToType: Option[Type]) extends Expr with HasElementType

Collection (Vector)

Collection (Vector)

 [1, 2, 3, 4, 5]
Value parameters:
elements

Elements of the collection

Companion:
object
object Vec
Companion:
class
case class VoidVal(evalType: Type, promoteToType: Option[Type]) extends ConstVal

Void Literal

Void Literal

Companion:
object
object VoidVal
Companion:
class