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
64498cc6
Commit
64498cc6
authored
Jan 30, 2020
by
Alexandru Dura
Browse files
Make the node labels accessible from outside the package
parent
7863c686
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/se/lth/sep/Grammar.java
View file @
64498cc6
...
@@ -8,6 +8,7 @@ public class Grammar {
...
@@ -8,6 +8,7 @@ public class Grammar {
private
HashMap
<
Category
,
Integer
>
cat2int
=
new
HashMap
<>();
private
HashMap
<
Category
,
Integer
>
cat2int
=
new
HashMap
<>();
private
HashMap
<
Integer
,
Category
>
int2cat
=
new
HashMap
<>();
private
HashMap
<
Integer
,
Category
>
int2cat
=
new
HashMap
<>();
private
HashMap
<
Category
,
ArrayList
<
Rule
>>
grammarRules
=
new
HashMap
<>();
private
HashMap
<
Category
,
ArrayList
<
Rule
>>
grammarRules
=
new
HashMap
<>();
private
HashMap
<
EarleyRule
,
Rule
>
earleyRule2GrammarRule
=
new
HashMap
<>();
private
int
nonTermIndex
=
1
;
private
int
nonTermIndex
=
1
;
private
int
termIndex
=
-
1
;
private
int
termIndex
=
-
1
;
...
@@ -65,7 +66,9 @@ public class Grammar {
...
@@ -65,7 +66,9 @@ public class Grammar {
for
(
int
j
=
0
;
j
<
body
.
length
;
++
j
)
{
for
(
int
j
=
0
;
j
<
body
.
length
;
++
j
)
{
body
[
j
]
=
cat2int
.
get
(
b
.
getBody
().
get
(
j
));
body
[
j
]
=
cat2int
.
get
(
b
.
getBody
().
get
(
j
));
}
}
eBodies
.
add
(
new
EarleyRule
(
i
,
body
));
EarleyRule
eRule
=
new
EarleyRule
(
i
,
body
);
earleyRule2GrammarRule
.
put
(
eRule
,
b
);
eBodies
.
add
(
eRule
);
}
}
rules
.
add
(
eBodies
);
rules
.
add
(
eBodies
);
}
}
...
@@ -97,4 +100,11 @@ public class Grammar {
...
@@ -97,4 +100,11 @@ public class Grammar {
throw
new
EarleyException
(
"Category not present in the gramamr"
);
throw
new
EarleyException
(
"Category not present in the gramamr"
);
return
i
;
return
i
;
}
}
public
Rule
getRule
(
EarleyRule
rule
)
{
Rule
r
=
earleyRule2GrammarRule
.
get
(
rule
);
if
(
r
==
null
)
throw
new
EarleyException
(
"Rule not preset in the grammar"
);
return
r
;
}
}
}
src/main/java/se/lth/sep/NodeLabel.java
View file @
64498cc6
...
@@ -20,49 +20,3 @@ public abstract class NodeLabel {
...
@@ -20,49 +20,3 @@ public abstract class NodeLabel {
public
abstract
String
prettyPrint
(
Grammar
info
);
public
abstract
String
prettyPrint
(
Grammar
info
);
}
}
class
ItemLabel
extends
NodeLabel
{
DottedRule
item
;
public
ItemLabel
(
DottedRule
item
,
int
start
,
int
end
)
{
super
(
start
,
end
);
this
.
item
=
item
;
}
@Override
public
boolean
equals
(
Object
other
)
{
if
(!
super
.
equals
(
other
))
return
false
;
return
(
other
instanceof
ItemLabel
)
&&
item
.
equals
(((
ItemLabel
)
other
).
item
);
}
@Override
public
int
hashCode
()
{
return
super
.
hashCode
()
*
31
+
item
.
hashCode
();
}
public
String
prettyPrint
(
Grammar
info
)
{
return
item
.
prettyPrint
(
info
)
+
", "
+
super
.
start
+
", "
+
super
.
end
;
}
}
class
SymbolLabel
extends
NodeLabel
{
int
symbol
;
public
SymbolLabel
(
int
symbol
,
int
start
,
int
end
)
{
super
(
start
,
end
);
this
.
symbol
=
symbol
;
}
@Override
public
boolean
equals
(
Object
other
)
{
if
(!
super
.
equals
(
other
))
return
false
;
return
(
other
instanceof
SymbolLabel
)
&&
((
SymbolLabel
)
other
).
symbol
==
symbol
;
}
@Override
public
int
hashCode
()
{
return
super
.
hashCode
()
*
31
+
symbol
;
}
public
String
prettyPrint
(
Grammar
info
)
{
return
info
.
getCategory
(
symbol
).
toString
()
+
", "
+
super
.
start
+
", "
+
super
.
end
;
}
}
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