Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Alexandru Dura
SPPF Earley Parser
Commits
c4f8d8c0
Commit
c4f8d8c0
authored
Feb 16, 2020
by
Alexandru Dura
Browse files
Add one more test containing lists and gaps
parent
d22d556b
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/se/lth/sep/SPPFNode.java
View file @
c4f8d8c0
...
...
@@ -4,7 +4,7 @@ import java.util.Arrays;
import
java.util.HashSet
;
import
java.util.Set
;
public
class
SPPFNode
{
public
class
SPPFNode
implements
Cloneable
{
static
public
class
FamilyNode
{
private
SPPFNode
[]
child
;
...
...
src/main/java/se/lth/sep/Util.java
View file @
c4f8d8c0
...
...
@@ -70,6 +70,8 @@ class DotVisitor implements SPPFNodeVisitor {
if
(
n
.
getLabel
()
instanceof
ItemLabel
)
{
ps
.
print
(
currentID
+
" [shape=box,color=red,label=\""
+
n
.
prettyPrint
(
info
)
+
"\"];\n"
);
}
else
if
(
n
.
getChildren
().
size
()
>
1
)
{
ps
.
print
(
currentID
+
" [shape=box,color=red,label=\""
+
n
.
prettyPrint
(
info
)
+
"\"];\n"
);
}
else
{
ps
.
print
(
currentID
+
" [shape=box,label=\""
+
n
.
prettyPrint
(
info
)
+
"\"];\n"
);
}
...
...
src/test/java/EarleyParserTest.java
View file @
c4f8d8c0
...
...
@@ -289,4 +289,51 @@ public class EarleyParserTest {
tpr
.
visit
(
root
);
Util
.
dumpParseResult
(
"testJava3-notr.dot"
,
root
,
g
);
}
@Test
public
void
testJava4
()
{
Grammar
g
=
new
Grammar
();
Java14Grammar
.
addRules
(
g
);
EarleyParser
parser
=
new
EarleyParser
(
g
);
Category
str
[]
=
{
Java14Grammar
.
t_CLASS
,
Java14Grammar
.
t_IDENTIFIER
,
Java14Grammar
.
t_LBRACE
,
Java14Grammar
.
t_METAVARID
,
Java14Grammar
.
t_METAVARID
,
Java14Grammar
.
t_LPAREN
,
Java14Grammar
.
t_RPAREN
,
Java14Grammar
.
t_LBRACE
,
Java14Grammar
.
t_METAVARID
,
Java14Grammar
.
t_GAP
,
Java14Grammar
.
t_METAVARID
,
Java14Grammar
.
t_GAP
,
Java14Grammar
.
t_METAVARID
,
Java14Grammar
.
t_RBRACE
,
Java14Grammar
.
t_RBRACE
};
SPPFNode
root
=
parser
.
parse
(
str
,
Java14Grammar
.
n_class_declaration
);
assertNotNull
(
root
);
Util
.
dumpParseResult
(
"testJava4-bt.dot"
,
root
,
g
);
// debinarize
SPPFDebinarizeVisitor
dbv
=
new
SPPFDebinarizeVisitor
();
dbv
.
visit
(
root
);
Util
.
dumpParseResult
(
"testJava4.dot"
,
root
,
g
);
// remove trivial productions
SPPFTrivialProductionRemover
tpr
=
new
SPPFTrivialProductionRemover
(
g
)
{
@Override
public
boolean
isTrivialProduction
(
Category
head
,
Category
body
)
{
String
sig
=
head
.
getName
()
+
"."
+
body
.
getName
();
if
(
body
.
getName
().
equals
(
"METAVARID"
))
return
true
;
if
(
body
.
getName
().
equals
(
"GAP"
))
return
true
;
return
false
;
}
};
tpr
.
visit
(
root
);
Util
.
dumpParseResult
(
"testJava4-notr.dot"
,
root
,
g
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment