Skip to content

Commit cadc7b8

Browse files
committed
syntax changes 2
1 parent c1a9913 commit cadc7b8

12 files changed

Lines changed: 566 additions & 573 deletions

File tree

src/main/antlr/nts.g4

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
//header
2-
/*
3-
@myVar =
4-
5-
*/
6-
71
grammar nts;
82

93
script : statement_list EOF;
104

115
statement_list : statement terminator
12-
| statement_list statement terminator
6+
| statement_list terminator
137
| terminator
148
;
159

1610
statement : assignment_statement
1711
| putField_statement
18-
| function_call
1912
| return_statement
2013
| if_statement
2114
| foreach_statement
15+
| function_call
2216
;
2317

2418
condition_expression : function_call
@@ -37,13 +31,13 @@ comparable_expr : type_bool
3731
| function_call
3832
;
3933

40-
variable_reference : variable=VARIABLE_IDENTIFIER ;
34+
variable_reference : variable=IDENTIFIER ;
4135

4236

4337
putField_statement : fieldOwner=variable_reference '.' field=IDENTIFIER '=' value=rval ;
4438
getField_statement : fieldOwner=variable_reference '.' field=IDENTIFIER ('as' type_cast= IDENTIFIER)?;
4539

46-
assignment_statement : name=VARIABLE_IDENTIFIER '=' value=assignment_values ;
40+
assignment_statement : name=IDENTIFIER '=' value=assignment_values ;
4741

4842
return_statement : RETURN value=rval ;
4943

@@ -83,7 +77,7 @@ if_statement : IF condition_expression terminator statement_list END ;
8377
foreach_statement : FOREACH variable=variable_reference IN collection=iterable terminator statement_list END ;
8478

8579

86-
argument : name=IDENTIFIER '=' value=rval ;
80+
argument : name=IDENTIFIER ':' value=rval ;
8781

8882
newline : CRLF;
8983

@@ -138,7 +132,6 @@ IN: I N;
138132
FUNCTION: ( F N | F U N C T I O N );
139133

140134
IDENTIFIER : [a-zA-Z_][a-zA-Z0-9_]*;
141-
VARIABLE_IDENTIFIER : '@' IDENTIFIER;
142135
fragment DIGIT : ('0'..'9');
143136
INT : [0-9]+;
144137
DOT : '.';

src/main/antlr/script.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+

src/main/java/cz/neumimto/nts/NTScript.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ private LinkedHashMap<String, Variable> getImplementingMethodParams() {
277277
String value = annotation.value();
278278
Class<?> type = parameter.getType();
279279
MethodVariableAccess opcode = MethodVariableAccess.of(new TypeDescription.ForLoadedType(type));
280-
map.put("@" + value, new Variable(i + 1, opcode, type));
280+
map.put(value, new Variable(i + 1, opcode, type));
281281
}
282282
}
283283
return map;

src/main/java/cz/neumimto/nts/bytecode/FnVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public FnVisitor(Set<Object> context) {
2525
@Override
2626
public Object visitFunction_call(ntsParser.Function_callContext ctx) {
2727
String fnName = ctx.function_name.getText();
28-
if (!lambdas.contains("@" + fnName)) {
28+
if (!lambdas.contains(fnName)) {
2929
for (Object o : context) {
3030
if (o instanceof Descriptor d) {
3131
if (d.functionName.equalsIgnoreCase(fnName)) {
@@ -43,7 +43,7 @@ public Object visitFunction_call(ntsParser.Function_callContext ctx) {
4343
@Override
4444
public Object visitAssignment_statement(ntsParser.Assignment_statementContext ctx) {
4545
if (ctx.assignment_values().lambda() != null) {
46-
lambdas.add(ctx.VARIABLE_IDENTIFIER().getText());
46+
lambdas.add(ctx.IDENTIFIER().getText());
4747
}
4848
return super.visitAssignment_statement(ctx);
4949
}

src/main/java/cz/neumimto/nts/bytecode/VisitorImpl.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected StackManipulation previouusInsn() {
3737

3838
@Override
3939
public ScriptContext visitAssignment_statement(ntsParser.Assignment_statementContext ctx) {
40-
TerminalNode variableIdentifier = ctx.VARIABLE_IDENTIFIER();
40+
TerminalNode variableIdentifier = ctx.IDENTIFIER();
4141
Optional<Variable> var = scriptContext.getVariable(variableIdentifier.getText());
4242

4343
Variable variable = var.orElseGet(() -> scriptContext.createNewVariable(variableIdentifier.getText(), ctx.assignment_values()));
@@ -170,6 +170,11 @@ public ScriptContext visitType_double(ntsParser.Type_doubleContext ctx) {
170170
return scriptContext;
171171
}
172172

173+
@Override
174+
public ScriptContext visitAssignment_values(ntsParser.Assignment_valuesContext ctx) {
175+
return super.visitAssignment_values(ctx);
176+
}
177+
173178
protected boolean parseBoolean(String text) {
174179
if (text.equalsIgnoreCase("t") || text.equalsIgnoreCase("true")) {
175180
return true;
@@ -255,8 +260,12 @@ public ScriptContext visitType_enum(ntsParser.Type_enumContext ctx) {
255260

256261
@Override
257262
public ScriptContext visitFunction_call(ntsParser.Function_callContext ctx) {
263+
String line = ctx.getText();
264+
if (ctx.arguments == null) {
265+
return super.visitFunction_call(ctx);
266+
}
258267
String functionName = ctx.function_name.getText();
259-
Optional<Variable> variable = scriptContext.getVariable("@" + functionName);
268+
Optional<Variable> variable = scriptContext.getVariable(functionName);
260269
if (variable.isPresent()) {
261270
Variable variable1 = variable.get();
262271
if (variable1.getRuntimeType() != null && Runnable.class.isAssignableFrom(variable1.getRuntimeType())) {
@@ -333,7 +342,7 @@ public ScriptContext visitFunction_call(ntsParser.Function_callContext ctx) {
333342
}
334343
}
335344
if (parent != null) {
336-
Variable variable1 = scriptContext.currentScope().findVariable(parent.VARIABLE_IDENTIFIER().getText());
345+
Variable variable1 = scriptContext.currentScope().findVariable(parent.IDENTIFIER().getText());
337346
variable1.setRuntimeType(c.getDeclaringClass());
338347
}
339348
} else {
@@ -499,7 +508,7 @@ public ScriptContext visitLambda(ntsParser.LambdaContext ctx) {
499508
List<ntsParser.Variable_referenceContext> variable_referenceContexts = ctx.variable_reference();
500509
Map<String, Variable> fnVars = new TreeMap<>();
501510
for (ntsParser.Variable_referenceContext var : variable_referenceContexts) {
502-
String text = var.VARIABLE_IDENTIFIER().getText();
511+
String text = var.IDENTIFIER().getText();
503512
Optional<Variable> variable = scriptContext.getVariable(text);
504513
if (variable.isEmpty()) {
505514
throw new IllegalStateException("Unknown variable " + text);

src/main/java/cz/neumimto/nts/nts.interp

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

src/main/java/cz/neumimto/nts/nts.tokens

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,50 @@ T__0=1
22
T__1=2
33
T__2=3
44
T__3=4
5-
LITERAL=5
6-
WS=6
7-
SL_COMMENT=7
8-
ASSIGN=8
9-
CRLF=9
10-
RETURN=10
11-
TRUE=11
12-
FALSE=12
13-
PLUS=13
14-
MINUS=14
15-
MUL=15
16-
DIV=16
17-
MOD=17
18-
EXP=18
19-
EQUAL=19
20-
NOT_EQUAL=20
21-
LESS_EQUAL=21
22-
GREATER_EQUAL=22
23-
GREATER=23
24-
LESS=24
25-
IF=25
26-
ELSE=26
27-
END=27
28-
FOREACH=28
29-
IN=29
30-
FUNCTION=30
31-
IDENTIFIER=31
32-
VARIABLE_IDENTIFIER=32
5+
T__4=5
6+
LITERAL=6
7+
WS=7
8+
SL_COMMENT=8
9+
ASSIGN=9
10+
CRLF=10
11+
RETURN=11
12+
TRUE=12
13+
FALSE=13
14+
PLUS=14
15+
MINUS=15
16+
MUL=16
17+
DIV=17
18+
MOD=18
19+
EXP=19
20+
EQUAL=20
21+
NOT_EQUAL=21
22+
LESS_EQUAL=22
23+
GREATER_EQUAL=23
24+
GREATER=24
25+
LESS=25
26+
IF=26
27+
ELSE=27
28+
END=28
29+
FOREACH=29
30+
IN=30
31+
FUNCTION=31
32+
IDENTIFIER=32
3333
INT=33
3434
DOT=34
3535
'as'=1
3636
'('=2
3737
')'=3
3838
','=4
39-
'='=8
40-
'+'=13
41-
'-'=14
42-
'*'=15
43-
'/'=16
44-
'%'=17
45-
'**'=18
46-
'=='=19
47-
'!='=20
48-
'>'=23
49-
'<'=24
39+
':'=5
40+
'='=9
41+
'+'=14
42+
'-'=15
43+
'*'=16
44+
'/'=17
45+
'%'=18
46+
'**'=19
47+
'=='=20
48+
'!='=21
49+
'>'=24
50+
'<'=25
5051
'.'=34

src/main/java/cz/neumimto/nts/ntsLexer.interp

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)