Skip to content
GitLab
Menu
Projects
Groups
Snippets
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
a46b502c
Commit
a46b502c
authored
Jan 27, 2020
by
Alexandru Dura
Browse files
Remove useles interface PrettyPrintingInfo
parent
9ca28de4
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/main/java/DottedRule.java
View file @
a46b502c
...
...
@@ -47,7 +47,7 @@ public class DottedRule {
return
true
;
}
public
String
prettyPrint
(
PrettyPrintingInfo
info
)
{
public
String
prettyPrint
(
Grammar
info
)
{
String
s
=
info
.
getCategory
(
r
.
head
).
toString
()
+
" -> "
;
for
(
int
j
=
0
;
j
<
r
.
body
.
length
;
++
j
)
{
if
(
j
==
dot
)
{
...
...
src/main/java/EarleyItem.java
View file @
a46b502c
...
...
@@ -50,7 +50,7 @@ public class EarleyItem {
return
(
rule
.
hashCode
()
*
31
+
start
)
*
31
+
(
sppf
==
null
?
0
:
sppf
.
hashCode
());
}
public
String
prettyPrint
(
PrettyPrintingInfo
info
)
{
public
String
prettyPrint
(
Grammar
info
)
{
String
s
=
info
.
getCategory
(
rule
.
r
.
head
).
toString
()
+
" -> "
;
for
(
int
j
=
0
;
j
<
rule
.
r
.
body
.
length
;
++
j
)
{
if
(
j
==
rule
.
dot
)
{
...
...
src/main/java/EarleyRule.java
View file @
a46b502c
...
...
@@ -32,7 +32,7 @@ public class EarleyRule implements Comparable<EarleyRule> {
}
}
public
String
prettyPrint
(
PrettyPrintingInfo
info
)
{
public
String
prettyPrint
(
Grammar
info
)
{
String
s
=
info
.
getCategory
(
head
).
toString
()
+
" -> "
;
for
(
int
j
:
body
)
{
s
+=
info
.
getCategory
(
j
).
toString
()
+
" "
;
...
...
src/main/java/Grammar.java
View file @
a46b502c
...
...
@@ -2,7 +2,7 @@ import java.util.ArrayList;
import
java.util.HashMap
;
import
java.util.TreeSet
;
public
class
Grammar
implements
PrettyPrintingInfo
{
public
class
Grammar
{
private
HashMap
<
Category
,
Integer
>
cat2int
=
new
HashMap
<>();
private
HashMap
<
Integer
,
Category
>
int2cat
=
new
HashMap
<>();
private
HashMap
<
Category
,
ArrayList
<
Rule
>>
grammarRules
=
new
HashMap
<>();
...
...
@@ -82,7 +82,6 @@ public class Grammar implements PrettyPrintingInfo {
return
s
;
}
@Override
public
Category
getCategory
(
int
i
)
{
Category
c
=
int2cat
.
get
(
i
);
if
(
c
==
null
)
...
...
src/main/java/NodeLabel.java
View file @
a46b502c
...
...
@@ -16,7 +16,7 @@ public abstract class NodeLabel {
return
31
*
start
+
end
;
}
public
abstract
String
prettyPrint
(
PrettyPrintingInfo
info
);
public
abstract
String
prettyPrint
(
Grammar
info
);
}
class
ItemLabel
extends
NodeLabel
{
...
...
@@ -37,7 +37,7 @@ class ItemLabel extends NodeLabel {
return
super
.
hashCode
()
*
31
+
item
.
hashCode
();
}
public
String
prettyPrint
(
PrettyPrintingInfo
info
)
{
public
String
prettyPrint
(
Grammar
info
)
{
return
item
.
prettyPrint
(
info
)
+
", "
+
super
.
start
+
", "
+
super
.
end
;
}
}
...
...
@@ -60,7 +60,7 @@ class SymbolLabel extends NodeLabel {
return
super
.
hashCode
()
*
31
+
symbol
;
}
public
String
prettyPrint
(
PrettyPrintingInfo
info
)
{
public
String
prettyPrint
(
Grammar
info
)
{
return
info
.
getCategory
(
symbol
).
toString
()
+
", "
+
super
.
start
+
", "
+
super
.
end
;
}
}
src/main/java/PrettyPrintingInfo.java
deleted
100644 → 0
View file @
9ca28de4
interface
PrettyPrintingInfo
{
Category
getCategory
(
int
i
);
}
src/main/java/SPPFNode.java
View file @
a46b502c
...
...
@@ -73,18 +73,17 @@ public class SPPFNode {
children
.
add
(
new
FamilyNode
(
null
,
null
));
}
public
String
prettyPrint
(
PrettyPrintingInfo
info
)
{
public
String
prettyPrint
(
Grammar
info
)
{
return
label
.
prettyPrint
(
info
);
}
public
void
accept
(
SPPFNodeVisitor
visitor
)
{
visitor
.
visit
(
this
);
}
}
interface
SPPFNodeVisitor
{
public
void
visit
(
SPPFNode
.
FamilyNode
familyNode
)
;
public
void
visit
(
SPPFNode
n
);
public
NodeLabel
getLabel
()
{
return
label
;
}
}
class
DotVisitor
implements
SPPFNodeVisitor
{
...
...
@@ -92,9 +91,9 @@ class DotVisitor implements SPPFNodeVisitor {
private
int
nodeID
=
0
;
private
HashMap
<
SPPFNode
,
Integer
>
visitedNodes
=
new
HashMap
<>();
private
HashMap
<
SPPFNode
.
FamilyNode
,
Integer
>
visitedFamilies
=
new
HashMap
<>();
private
PrettyPrintingInfo
info
;
private
Grammar
info
;
public
DotVisitor
(
PrintStream
ps
,
PrettyPrintingInfo
info
)
{
public
DotVisitor
(
PrintStream
ps
,
Grammar
info
)
{
this
.
info
=
info
;
this
.
ps
=
ps
;
}
...
...
Write
Preview
Supports
Markdown
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