Added callable/storable modifiers to grammar
Still gotta add logic for them in the compiler.
This commit is contained in:
parent
5fa362cac1
commit
b57c70ee9d
5 changed files with 37 additions and 64 deletions
|
@ -3,8 +3,8 @@ using System.Linq;
|
|||
|
||||
namespace arookas {
|
||||
class sunBuiltinDeclaration : sunNode {
|
||||
public sunIdentifier Builtin { get { return this[0] as sunIdentifier; } }
|
||||
public sunParameterList Parameters { get { return this[1] as sunParameterList; } }
|
||||
public sunIdentifier Builtin { get { return this[1] as sunIdentifier; } }
|
||||
public sunParameterList Parameters { get { return this[2] as sunParameterList; } }
|
||||
|
||||
public sunBuiltinDeclaration(sunSourceLocation location)
|
||||
: base(location) { }
|
||||
|
@ -15,9 +15,9 @@ namespace arookas {
|
|||
}
|
||||
|
||||
class sunFunctionDefinition : sunNode {
|
||||
public sunIdentifier Function { get { return this[0] as sunIdentifier; } }
|
||||
public sunParameterList Parameters { get { return this[1] as sunParameterList; } }
|
||||
public sunNode Body { get { return this[2]; } }
|
||||
public sunIdentifier Function { get { return this[1] as sunIdentifier; } }
|
||||
public sunParameterList Parameters { get { return this[2] as sunParameterList; } }
|
||||
public sunNode Body { get { return this[3]; } }
|
||||
|
||||
public sunFunctionDefinition(sunSourceLocation location)
|
||||
: base(location) { }
|
||||
|
|
6
ssc/ast/nodes.keywords.cs
Normal file
6
ssc/ast/nodes.keywords.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace arookas {
|
||||
class sunConstKeyword : sunNode {
|
||||
public sunConstKeyword(sunSourceLocation location)
|
||||
: base(location) { }
|
||||
}
|
||||
}
|
|
@ -22,7 +22,7 @@
|
|||
}
|
||||
|
||||
class sunVariableDeclaration : sunNode {
|
||||
public sunIdentifier Variable { get { return this[0] as sunIdentifier; } }
|
||||
public sunIdentifier Variable { get { return this[1] as sunIdentifier; } }
|
||||
|
||||
public sunVariableDeclaration(sunSourceLocation location)
|
||||
: base(location) { }
|
||||
|
@ -33,9 +33,9 @@
|
|||
}
|
||||
|
||||
class sunVariableDefinition : sunNode {
|
||||
public sunIdentifier Variable { get { return this[0] as sunIdentifier; } }
|
||||
public sunAssign Operator { get { return this[1] as sunAssign; } }
|
||||
public sunExpression Expression { get { return this[2] as sunExpression; } }
|
||||
public sunIdentifier Variable { get { return this[1] as sunIdentifier; } }
|
||||
public sunAssign Operator { get { return this[2] as sunAssign; } }
|
||||
public sunExpression Expression { get { return this[3] as sunExpression; } }
|
||||
|
||||
public sunVariableDefinition(sunSourceLocation location)
|
||||
: base(location) { }
|
||||
|
@ -47,9 +47,9 @@
|
|||
}
|
||||
|
||||
class sunStorableAssignment : sunNode {
|
||||
public sunIdentifier Storable { get { return this[0] as sunIdentifier; } }
|
||||
public sunAssign Operator { get { return this[1] as sunAssign; } }
|
||||
public sunExpression Expression { get { return this[2] as sunExpression; } }
|
||||
public sunIdentifier Storable { get { return this[1] as sunIdentifier; } }
|
||||
public sunAssign Operator { get { return this[2] as sunAssign; } }
|
||||
public sunExpression Expression { get { return this[3] as sunExpression; } }
|
||||
|
||||
public sunStorableAssignment(sunSourceLocation location)
|
||||
: base(location) { }
|
||||
|
@ -64,8 +64,8 @@
|
|||
}
|
||||
|
||||
class sunConstantDefinition : sunNode {
|
||||
public sunIdentifier Constant { get { return this[0] as sunIdentifier; } }
|
||||
public sunExpression Expression { get { return this[2] as sunExpression; } }
|
||||
public sunIdentifier Constant { get { return this[1] as sunIdentifier; } }
|
||||
public sunExpression Expression { get { return this[3] as sunExpression; } }
|
||||
|
||||
public sunConstantDefinition(sunSourceLocation location)
|
||||
: base(location) { }
|
||||
|
|
|
@ -207,52 +207,15 @@ namespace arookas {
|
|||
case __sunConstants.BREAK_STATEMENT: return new sunBreak(location);
|
||||
case __sunConstants.CONTINUE_STATEMENT: return new sunContinue(location);
|
||||
}
|
||||
|
||||
// cleanup keywords punctuation
|
||||
switch (GetId(node)) {
|
||||
// keywords
|
||||
case __sunConstants.IMPORT:
|
||||
case __sunConstants.BUILTIN:
|
||||
case __sunConstants.FUNCTION:
|
||||
case __sunConstants.VAR:
|
||||
case __sunConstants.CONST:
|
||||
|
||||
case __sunConstants.IF:
|
||||
case __sunConstants.ELSE:
|
||||
case __sunConstants.DO:
|
||||
case __sunConstants.WHILE:
|
||||
case __sunConstants.FOR:
|
||||
|
||||
case __sunConstants.RETURN:
|
||||
case __sunConstants.BREAK:
|
||||
case __sunConstants.CONTINUE:
|
||||
|
||||
case __sunConstants.YIELD:
|
||||
case __sunConstants.EXIT:
|
||||
case __sunConstants.LOCK:
|
||||
case __sunConstants.UNLOCK:
|
||||
case __sunConstants.INT:
|
||||
case __sunConstants.FLOAT:
|
||||
case __sunConstants.TYPEOF:
|
||||
|
||||
case __sunConstants.TRUE:
|
||||
case __sunConstants.FALSE:
|
||||
|
||||
// punctuation
|
||||
case __sunConstants.L_BRACE:
|
||||
case __sunConstants.R_BRACE:
|
||||
case __sunConstants.L_PAREN:
|
||||
case __sunConstants.R_PAREN:
|
||||
case __sunConstants.L_BRACKET:
|
||||
case __sunConstants.R_BRACKET:
|
||||
case __sunConstants.COLON:
|
||||
case __sunConstants.SEMICOLON:
|
||||
case __sunConstants.COMMA:
|
||||
case __sunConstants.DOT:
|
||||
case __sunConstants.ELLIPSIS:
|
||||
case __sunConstants.QMARK: {
|
||||
return null;
|
||||
|
||||
// keywords
|
||||
if (id == __sunConstants.CONST) {
|
||||
switch (parent) {
|
||||
case __sunConstants.FUNCTION_MODIFIERS:
|
||||
case __sunConstants.BUILTIN_MODIFIERS: {
|
||||
return new sunConstKeyword(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// emergency fallback
|
||||
|
|
|
@ -178,12 +178,14 @@ float_cast = FLOAT L_PAREN expression R_PAREN;
|
|||
typeof_cast = TYPEOF L_PAREN expression R_PAREN;
|
||||
|
||||
// constants
|
||||
const_definition = CONST IDENTIFIER ASSIGN expression;
|
||||
const_definition = const_modifiers IDENTIFIER ASSIGN expression;
|
||||
const_modifiers = [LOCAL] CONST;
|
||||
|
||||
// variables
|
||||
variable_reference = IDENTIFIER; // used in expressions
|
||||
variable_declaration = VAR IDENTIFIER;
|
||||
variable_definition = VAR IDENTIFIER ASSIGN expression;
|
||||
variable_declaration = variable_modifiers IDENTIFIER;
|
||||
variable_definition = variable_modifiers IDENTIFIER ASSIGN expression;
|
||||
variable_modifiers = [LOCAL] VAR;
|
||||
variable_assignment = IDENTIFIER assignment_operator expression;
|
||||
variable_augment = postfix_augment | prefix_augment;
|
||||
|
||||
|
@ -191,14 +193,16 @@ postfix_augment = IDENTIFIER augment_operator;
|
|||
prefix_augment = augment_operator IDENTIFIER;
|
||||
|
||||
// functions
|
||||
function_definition = FUNCTION IDENTIFIER parameter_list statement_block;
|
||||
function_definition = function_modifiers IDENTIFIER parameter_list statement_block;
|
||||
function_modifiers = [LOCAL] [CONST] FUNCTION;
|
||||
function_call = IDENTIFIER argument_list;
|
||||
|
||||
parameter_list = L_PAREN [IDENTIFIER {COMMA IDENTIFIER} [COMMA ELLIPSIS] | ELLIPSIS] R_PAREN; // e.g. (a, b, ...)
|
||||
argument_list = L_PAREN [expression {COMMA expression}] R_PAREN;
|
||||
|
||||
// builtins
|
||||
builtin_declaration = BUILTIN IDENTIFIER parameter_list;
|
||||
builtin_declaration = builtin_modifiers IDENTIFIER parameter_list;
|
||||
builtin_modifiers = [LOCAL] [CONST] BUILTIN;
|
||||
|
||||
// flow control
|
||||
if_statement = IF expression statement [ELSE statement];
|
||||
|
|
Loading…
Reference in a new issue