Skip to content

Commit

Permalink
nitcc: add more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jean Privat <[email protected]>
  • Loading branch information
privat committed Jul 21, 2024
1 parent c4c208d commit a3dd053
Show file tree
Hide file tree
Showing 51 changed files with 500 additions and 2 deletions.
1 change: 1 addition & 0 deletions contrib/nitcc/tests/amb_repeat.input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c x
6 changes: 6 additions & 0 deletions contrib/nitcc/tests/amb_repeat.sablecc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Grammar amb;
Parser
Ignored #10, #32;
s = a | a 'x' ;
a = b | b 'x' ;
b = 'c' ;
1 change: 1 addition & 0 deletions contrib/nitcc/tests/amb_repeat0.input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
4 changes: 4 additions & 0 deletions contrib/nitcc/tests/amb_repeat0.sablecc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Grammar amb;
Parser
Ignored #10, #32;
s = 'hello' | 'hello' ;
Empty file.
6 changes: 6 additions & 0 deletions contrib/nitcc/tests/amb_repeat2.sablecc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Grammar amb;
Parser
Ignored #10, #32;
s = a | Empty ;
a = b | Empty ;
b = 'c' ;
13 changes: 13 additions & 0 deletions contrib/nitcc/tests/calc1.sablecc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Grammar calc;
Lexer
n = ('0'..'9')+ ;
Parser
Ignored #10, #32;
e
= e '+' a
| e '-' a
;
a =
| '(' e ')'
| n
;
1 change: 1 addition & 0 deletions contrib/nitcc/tests/dangling_else.input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
i a i a e a
9 changes: 9 additions & 0 deletions contrib/nitcc/tests/dangling_else.sablecc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Grammar dangling;
Parser
Ignored #10, #32;
ss = s*;
s
= 'i' s 'e' s
| 'i' s
| 'a'
;
1 change: 1 addition & 0 deletions contrib/nitcc/tests/dangling_else2.input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
i a i a e a
14 changes: 14 additions & 0 deletions contrib/nitcc/tests/dangling_else2.sablecc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Grammar dangling;
Parser
Ignored #10, #32;
ss = s*;

s
= 'a'
| 'i' se 'e' s
| 'i' s
;
se
= 'a'
| 'i' se 'e' se
;
5 changes: 5 additions & 0 deletions contrib/nitcc/tests/dangling_end.input
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a id
a id end
a a id end end
a a id end
a a id
9 changes: 9 additions & 0 deletions contrib/nitcc/tests/dangling_end.sablecc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Grammar dangling;
Parser
Ignored #10, #32;
es = e*;
e
= 'a' e 'end'
| 'a' e
| 'id'
;
1 change: 1 addition & 0 deletions contrib/nitcc/tests/dragon_4-55.input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ccdd
5 changes: 5 additions & 0 deletions contrib/nitcc/tests/dragon_4-55.sablecc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Grammar dragon;
Parser
Ignored #10, #32;
s = c c ;
c = 'c' c | 'd' ;
4 changes: 4 additions & 0 deletions contrib/nitcc/tests/oneliner.input
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if id then id
if id then id end
if if id then id then id end
if id then if id then id end
34 changes: 34 additions & 0 deletions contrib/nitcc/tests/oneliner.sablecc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Grammar oneliner;
Lexer
eol = #10 | #13 ;

Parser
Ignored #32;

prog
= stmts
;
stmt
= if_block stmt_or_end
| if_block stmt_else stmt_or_end
| 'id'
;
if_block
= 'if' n? stmt no 'then'
;
stmt_or_end
= stmt 'end'?
| n stmts no 'end'
| no 'end'
;
stmt_else
= stmt 'else'
| n stmts no 'else'
| 'else'
;
stmts
= stmts n stmt
| stmt
;
no = n?;
n = eol+;
42 changes: 42 additions & 0 deletions contrib/nitcc/tests/oneliner2.sablecc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Grammar oneliner;
Lexer
eol = #10 | #13 ;

Parser
Ignored #32;

prog
= stmts
;
stmt
= if_block stmt_or_end
| if_block stmt_else stmt_or_end
| 'id'
;
stmt_with_else
= if_block stmt_else stmt_or_end
| 'id'
;
if_block
= 'if' n? stmt no 'then'
;
stmt_or_end
= stmt 'end'?
| n stmts no 'end'
| no 'end'
;
stmt_end
= stmt 'else'
| n stmts no 'else'
| 'else'
;
stmts_with_else
= stmts_with_else n stmt_with_else
| stmt_with_else
;
stmts
= stmts n stmt
| stmt
;
no = n?;
n = eol+;
1 change: 1 addition & 0 deletions contrib/nitcc/tests/regex0.input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aa|aa*
5 changes: 5 additions & 0 deletions contrib/nitcc/tests/regex0.sablecc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Grammar regex;
Parser
Ignored #10, #32;
e = a | e '|' e | e e | e '*' ;
a = 'a' ;
1 change: 1 addition & 0 deletions contrib/nitcc/tests/regex1.input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aa|aa*
13 changes: 13 additions & 0 deletions contrib/nitcc/tests/regex1.sablecc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Grammar regex;
Parser
Ignored #10, #32;
e
= a
Unary
e '*'
Left
e e
Left
e '|' e
;
a = 'a' ;
1 change: 1 addition & 0 deletions contrib/nitcc/tests/regex2.input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aa|aa*
7 changes: 7 additions & 0 deletions contrib/nitcc/tests/regex2.sablecc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Grammar regex;
Parser
Ignored #10, #32;
e = e '|' e2 | e2;
e2 = e2 e3 | e3 ;
e3 = e4 '*' | e4 ;
e4 = 'a' ;
7 changes: 7 additions & 0 deletions contrib/nitcc/tests/sav/amb_repeat.input.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Start
s_0
a_1
b
'c'@(1:1-1:2)
'x'@(1:3-1:4)
Eof@(2:1-2:1)=''
4 changes: 4 additions & 0 deletions contrib/nitcc/tests/sav/amb_repeat.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SHIFT/REDUCE Conflict on state 3 b for token 'x':
SHIFT on item: a→ b·'x', Eof/'x'
REDUCE on item: a→ b·, Eof/'x'
Error: there is conflicts
4 changes: 4 additions & 0 deletions contrib/nitcc/tests/sav/amb_repeat0.input.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Start
s_0
'hello'@(1:1-1:6)
Eof@(2:1-2:1)=''
4 changes: 4 additions & 0 deletions contrib/nitcc/tests/sav/amb_repeat0.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
REDUCE/REDUCE Conflict on state 2 'hello' for token Eof:
REDUCE on item: s→ 'hello'·, Eof
REDUCE on item: s→ 'hello'·, Eof
Error: there is conflicts
4 changes: 4 additions & 0 deletions contrib/nitcc/tests/sav/amb_repeat2.input.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Start
s_0
a_1
Eof@(1:1-1:1)=''
4 changes: 4 additions & 0 deletions contrib/nitcc/tests/sav/amb_repeat2.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
REDUCE/REDUCE Conflict on state 0 for token Eof:
REDUCE on item: a→·, Eof
REDUCE on item: s→·, Eof
Error: there is conflicts
12 changes: 12 additions & 0 deletions contrib/nitcc/tests/sav/calc0.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Automatic Dangling SHIFT/REDUCE on state 8 e '+' e for token '+':
reduce: e→ e '+' e·, Eof/'+'/'*'/')'
shift: e→ e·'+' e
Automatic Dangling SHIFT/REDUCE on state 8 e '+' e for token '*':
reduce: e→ e '+' e·, Eof/'+'/'*'/')'
shift: e→ e·'*' e
Automatic Dangling SHIFT/REDUCE on state 9 e '*' e for token '+':
reduce: e→ e '*' e·, '+'/'*'/Eof/')'
shift: e→ e·'+' e
Automatic Dangling SHIFT/REDUCE on state 9 e '*' e for token '*':
reduce: e→ e '*' e·, '+'/'*'/Eof/')'
shift: e→ e·'*' e
1 change: 1 addition & 0 deletions contrib/nitcc/tests/sav/calc1.res
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Runtime error: Aborted (./lrautomaton.nit:507)
15 changes: 15 additions & 0 deletions contrib/nitcc/tests/sav/dangling_else.input.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Start
ss
Nodes[Ns]
s_1
'i'@(1:1-1:2)
s_2
'a'@(1:3-1:4)
s_0
'i'@(1:5-1:6)
s_2
'a'@(1:7-1:8)
'e'@(1:9-1:10)
s_2
'a'@(1:11-1:12)
Eof@(2:1-2:1)=''
3 changes: 3 additions & 0 deletions contrib/nitcc/tests/sav/dangling_else.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Automatic Dangling SHIFT/REDUCE on state 8 'i' s for token 'e':
reduce: s→ 'i' s·, Eof/'i'/'a'/'e'
shift: s→ 'i' s·'e' s
15 changes: 15 additions & 0 deletions contrib/nitcc/tests/sav/dangling_else2.input.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Start
ss
Nodes[Ns]
s_2
'i'@(1:1-1:2)
s_0
'a'@(1:3-1:4)
s_1
'i'@(1:5-1:6)
se_0
'a'@(1:7-1:8)
'e'@(1:9-1:10)
s_0
'a'@(1:11-1:12)
Eof@(2:1-2:1)=''
34 changes: 34 additions & 0 deletions contrib/nitcc/tests/sav/dangling_end.input.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Start
es
Nodes[Ne]
e_1
'a'@(1:1-1:2)
e_2
'id'@(1:3-1:5)
e_0
'a'@(2:1-2:2)
e_2
'id'@(2:3-2:5)
'end'@(2:6-2:9)
e_0
'a'@(3:1-3:2)
e_0
'a'@(3:3-3:4)
e_2
'id'@(3:5-3:7)
'end'@(3:8-3:11)
'end'@(3:12-3:15)
e_1
'a'@(4:1-4:2)
e_0
'a'@(4:3-4:4)
e_2
'id'@(4:5-4:7)
'end'@(4:8-4:11)
e_1
'a'@(5:1-5:2)
e_1
'a'@(5:3-5:4)
e_2
'id'@(5:5-5:7)
Eof@(6:1-6:1)=''
3 changes: 3 additions & 0 deletions contrib/nitcc/tests/sav/dangling_end.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Automatic Dangling SHIFT/REDUCE on state 8 'a' e for token 'end':
reduce: e→ 'a' e·, Eof/'a'/'id'/'end'
shift: e→ 'a' e·'end'
11 changes: 11 additions & 0 deletions contrib/nitcc/tests/sav/dragon_4-55.input.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Start
s
c_0
'c'@(1:1-1:2)
c_0
'c'@(1:2-1:3)
c_1
'd'@(1:3-1:4)
c_1
'd'@(1:4-1:5)
Eof@(2:1-2:1)=''
1 change: 0 additions & 1 deletion contrib/nitcc/tests/sav/eq.res
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
Error: there is conflicts
1 change: 0 additions & 1 deletion contrib/nitcc/tests/sav/not_slr.res
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
Error: there is conflicts
Loading

0 comments on commit a3dd053

Please sign in to comment.