Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions runtime-testsuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>8</release>
<source>9</source>
<target>9</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[type]
Parser

[grammar]
grammar VisitorCalc;

s
@init {
<BuildParseTrees()>
}
@after {
<ToJSON("$ctx"):writeln()>
}
: expr EOF
|
;

expr
: INT # number
| ID # var
| ID '(' ')' # func
| expr (MUL | DIV) expr # multiply
| expr (ADD | SUB) expr # add
;

INT : [0-9]+;
ID : [a-zA-Z_]+ ;
MUL : '*';
DIV : '/';
ADD : '+';
SUB : '-';
WS : [ \t]+ -> channel(HIDDEN);

[start]
s

[input]


[output]
"""{"rules":["s","expr"],"input":"","tokens":[{"type":-1,"line":1,"pos":0,"channel":0,"start":0,"stop":-1}],"tree":"0"}
"""

[skip]
Cpp
CSharp
Dart
Go
JavaScript
PHP
Swift
Python2
Python3
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[type]
Parser

[grammar]
grammar VisitorCalc;

s
@init {
<BuildParseTrees()>
}
@after {
<ToJSON("$ctx"):writeln()>
}
: expr EOF
|
;

expr
: INT # number
| ID # var
| ID '(' ')' # func
| expr (MUL | DIV) expr # multiply
| expr (ADD | SUB) expr # add
;

INT : [0-9]+;
ID : [a-zA-Z_]+ ;
MUL : '*';
DIV : '/';
ADD : '+';
SUB : '-';
WS : [ \t]+ -> channel(HIDDEN);

[start]
s

[input]
1+2

[output]
"""{"rules":["s","expr"],"input":"1+2","tokens":[{"type":3,"line":1,"pos":0,"channel":0,"start":0,"stop":0},{"type":7,"line":1,"pos":1,"channel":0,"start":1,"stop":1},{"type":3,"line":1,"pos":2,"channel":0,"start":2,"stop":2},{"type":-1,"line":1,"pos":3,"channel":0,"start":3,"stop":2}],"tree":{"0":[{"1":[{"1":[0]},1,{"1":[2]}]},3]}}
"""

[skip]
Cpp
CSharp
Dart
Go
JavaScript
PHP
Swift
Python2
Python3
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[type]
Parser

[grammar]
grammar VisitorCalc;

s
: expr EOF
|
;

expr
@init {
<BuildParseTrees()>
}
@after {
<ToJSON("$ctx"):writeln()>
}
: INT # number
| ID # var
| ID '(' ')' # func
| expr (MUL | DIV) expr # multiply
| expr (ADD | SUB) expr # add
;

INT : [0-9]+;
ID : [a-zA-Z_]+ ;
MUL : '*';
DIV : '/';
ADD : '+';
SUB : '-';
WS : [ \t]+ -> channel(HIDDEN);

[start]
expr

[input]
f(

[output]
"""{"rules":["s","expr"],"input":"f(","tokens":[{"type":4,"line":1,"pos":0,"channel":0,"start":0,"stop":0},{"type":1,"line":1,"pos":1,"channel":0,"start":1,"stop":1},{"type":-1,"line":1,"pos":2,"channel":0,"start":2,"stop":1}],"tree":{"1":[0,1,{"error":"<missing ')'>"}]}}
"""

[errors]
"""line 1:2 missing ')' at '<EOF>'
"""

[skip]
Cpp
CSharp
Dart
Go
JavaScript
PHP
Swift
Python2
Python3
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[type]
Parser

[grammar]
grammar Expr;

program
@init {
<BuildParseTrees()>
}
@after {
<ToStringTree("$ctx"):writeln()>
<ToJSON("$ctx"):writeln()>
}
: stat EOF
| def EOF
;

stat: ID '=' expr ';'
| expr ';'
;

def : ID '(' ID (',' ID)* ')' '{' stat* '}' ;

expr: ID
| INT
| func
| 'not' expr
| expr 'and' expr
| expr 'or' expr
;

func : ID '(' expr (',' expr)* ')' ;

INT : [0-9]+ ;
ID: [a-zA-Z_][a-zA-Z_0-9]* ;
WS: [ \t\n\r\f]+ -> skip ;

[start]
program

[input]
f(x, y, z) { x = x and y or z; g(30); }

[output]
"""(program (def f ( x , y , z ) { (stat x = (expr (expr (expr x) and (expr y)) or (expr z)) ;) (stat (expr (func g ( (expr 30) ))) ;) }) <EOF>)
{"rules":["program","stat","def","expr","func"],"input":"f(x, y, z) { x = x and y or z; g(30); }","tokens":[{"type":12,"line":1,"pos":0,"channel":0,"start":0,"stop":0},{"type":3,"line":1,"pos":1,"channel":0,"start":1,"stop":1},{"type":12,"line":1,"pos":2,"channel":0,"start":2,"stop":2},{"type":4,"line":1,"pos":3,"channel":0,"start":3,"stop":3},{"type":12,"line":1,"pos":5,"channel":0,"start":5,"stop":5},{"type":4,"line":1,"pos":6,"channel":0,"start":6,"stop":6},{"type":12,"line":1,"pos":8,"channel":0,"start":8,"stop":8},{"type":5,"line":1,"pos":9,"channel":0,"start":9,"stop":9},{"type":6,"line":1,"pos":11,"channel":0,"start":11,"stop":11},{"type":12,"line":1,"pos":13,"channel":0,"start":13,"stop":13},{"type":1,"line":1,"pos":15,"channel":0,"start":15,"stop":15},{"type":12,"line":1,"pos":17,"channel":0,"start":17,"stop":17},{"type":9,"line":1,"pos":19,"channel":0,"start":19,"stop":21},{"type":12,"line":1,"pos":23,"channel":0,"start":23,"stop":23},{"type":10,"line":1,"pos":25,"channel":0,"start":25,"stop":26},{"type":12,"line":1,"pos":28,"channel":0,"start":28,"stop":28},{"type":2,"line":1,"pos":29,"channel":0,"start":29,"stop":29},{"type":12,"line":1,"pos":31,"channel":0,"start":31,"stop":31},{"type":3,"line":1,"pos":32,"channel":0,"start":32,"stop":32},{"type":11,"line":1,"pos":33,"channel":0,"start":33,"stop":34},{"type":5,"line":1,"pos":35,"channel":0,"start":35,"stop":35},{"type":2,"line":1,"pos":36,"channel":0,"start":36,"stop":36},{"type":7,"line":1,"pos":38,"channel":0,"start":38,"stop":38},{"type":-1,"line":1,"pos":39,"channel":0,"start":39,"stop":38}],"tree":{"0":[{"2":[0,1,2,3,4,5,6,7,8,{"1":[9,10,{"3":[{"3":[{"3":[11]},12,{"3":[13]}]},14,{"3":[15]}]},16]},{"1":[{"3":[{"4":[17,18,{"3":[19]},20]}]},21]},22]},23]}}
"""

[skip]
Cpp
CSharp
Dart
Go
JavaScript
PHP
Swift
Python2
Python3
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[type]
Parser

[grammar]
grammar VisitorCalc;

s
: expr EOF
|
;

expr
@init {
<BuildParseTrees()>
}
@after {
<ToJSON("$ctx"):writeln()>
}
: INT # number
| ID # var
| ID '(' ')' # func
| expr (MUL | DIV) expr # multiply
| expr (ADD | SUB) expr # add
;

INT : [0-9]+;
ID : [a-zA-Z_]+ ;
MUL : '*';
DIV : '/';
ADD : '+';
SUB : '-';
WS : [ \t]+ -> channel(HIDDEN);

[start]
expr

[input]
8

[output]
"""{"rules":["s","expr"],"input":"8","tokens":[{"type":3,"line":1,"pos":0,"channel":0,"start":0,"stop":0},{"type":-1,"line":1,"pos":1,"channel":0,"start":1,"stop":0}],"tree":{"1":[0]}}
"""

[skip]
Cpp
CSharp
Dart
Go
JavaScript
PHP
Swift
Python2
Python3
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[type]
Parser

[grammar]
grammar VisitorCalc;

s
@init {
<BuildParseTrees()>
}
@after {
<ToJSON("$ctx"):writeln()>
}
: expr EOF
|
;

expr
: INT # number
| ID # var
| ID '(' ')' # func
| expr (MUL | DIV) expr # multiply
| expr (ADD | SUB) expr # add
;

INT : [0-9]+;
ID : [a-zA-Z_]+ ;
MUL : '*';
DIV : '/';
ADD : '+';
SUB : '-';
WS : [ \t]+ -> channel(HIDDEN);

[start]
s

[input]
99

[output]
"""{"rules":["s","expr"],"input":"99","tokens":[{"type":3,"line":1,"pos":0,"channel":0,"start":0,"stop":1},{"type":-1,"line":1,"pos":2,"channel":0,"start":2,"stop":1}],"tree":{"0":[{"1":[0]},1]}}
"""

[skip]
Cpp
CSharp
Dart
Go
JavaScript
PHP
Swift
Python2
Python3
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ BailErrorStrategy() ::= <%ErrorHandler = new BailErrorStrategy();%>

ToStringTree(s) ::= <%<s>.ToStringTree(this)%>

ToJSON(s) ::= ""

Column() ::= "this.Column"

Text() ::= "this.Text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ BuildParseTrees() ::= "setBuildParseTree(true);"
BailErrorStrategy() ::= "_errHandler = std::make_shared\<BailErrorStrategy>();"

ToStringTree(s) ::= "<s>->toStringTree(this)"
ToJSON(s) ::= ""

Column() ::= "getCharPositionInLine()"
Text() ::= "getText()"
ValEquals(a,b) ::= "<a> == <b>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ BuildParseTrees() ::= "buildParseTree = true;"
BailErrorStrategy() ::= <%errorHandler = new BailErrorStrategy();%>

ToStringTree(s) ::= <%<s>.toStringTree(parser: this)%>
ToJSON(s) ::= ""

Column() ::= "this.charPositionInLine"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ BuildParseTrees() ::= "p.BuildParseTrees = true"
BailErrorStrategy() ::= <%p.SetErrorHandler(antlr.NewBailErrorStrategy())%>

ToStringTree(s) ::= <%<s>.ToStringTree(nil, p)%>
ToJSON(s) ::= ""

Column() ::= "p.GetCharPositionInLine()"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ BailErrorStrategy() ::= <%setErrorHandler(new BailErrorStrategy());%>

ToStringTree(s) ::= <%<s>.toStringTree(this)%>

ToJSON(s) ::= <%JsonSerializer.toJSON(<s>,this)%>

Column() ::= "this.getCharPositionInLine()"

Text() ::= "this.getText()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ BuildParseTrees() ::= "this.buildParseTrees = true;"
BailErrorStrategy() ::= <%this._errHandler = new antlr4.error.BailErrorStrategy();%>

ToStringTree(s) ::= <%<s>.toStringTree(null, this)%>
ToJSON(s) ::= ""

Column() ::= "this.column"

Expand Down
Loading