com.github.gchudnov.bscript.lang.ast
Type members
Classlikes
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
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
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
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
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
DateTime Literal
DateTime Literal
"2007-12-03T10:15:30+01:00"
- Companion:
- object
Decimal Literal
Decimal Literal
3.3
- Companion:
- object
Expression
Expression
Expressions are a special kind of Statement.
Field Declaration in a Struct.
Field Declaration in a Struct.
struct X {
int x;
float y;
}
- Companion:
- object
Reference to an evalType
Reference to an evalType
The type of the value computed by the expression
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.
If Condition
If Condition
if(cond) then { ... } else { ... }
if(cond) then { ... }
int x = if(conf) then { 1+2; } else { 2*5; }
- Companion:
- object
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
Int Literal
Int Literal
12
- Companion:
- object
Long Literal
Long Literal
12
- Companion:
- object
Not
Not
! expr;
- Companion:
- object
Marks code, related to standard-library.
Marks code, related to standard-library.
Used, for example, to prevent serialization of [std] functions.
- Companion:
- object
Struct Initializer
Struct Initializer
struct A {
a: int
b: string
};
A = { a: 1, b: "hello" };
- Companion:
- object
Reference to a variable
Reference to a variable
x;
- Companion:
- object
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
Collection (Vector)
Collection (Vector)
[1, 2, 3, 4, 5]
- Value parameters:
- elements
Elements of the collection
- Companion:
- object
Void Literal
Void Literal
- Companion:
- object