Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SableCC STUPS
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
stups
SableCC STUPS
Commits
75b83131
Commit
75b83131
authored
3 years ago
by
dgelessus
Browse files
Options
Downloads
Patches
Plain Diff
Use generics in LR1Collection
parent
c394250a
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/sablecc/sablecc/Grammar.java
+1
-3
1 addition, 3 deletions
src/main/java/org/sablecc/sablecc/Grammar.java
src/main/java/org/sablecc/sablecc/LR1Collection.java
+18
-24
18 additions, 24 deletions
src/main/java/org/sablecc/sablecc/LR1Collection.java
with
19 additions
and
27 deletions
src/main/java/org/sablecc/sablecc/Grammar.java
+
1
−
3
View file @
75b83131
...
@@ -112,9 +112,7 @@ public final class Grammar
...
@@ -112,9 +112,7 @@ public final class Grammar
LR0Item
[]
items
=
sets
[
i
].
items
();
LR0Item
[]
items
=
sets
[
i
].
items
();
for
(
int
j
=
0
;
j
<
items
.
length
;
j
++)
for
(
int
j
=
0
;
j
<
items
.
length
;
j
++)
{
{
Symbol
[]
lookaheads
=
((
SymbolSet
)
collection
.
lookaheads
[
i
].
Symbol
[]
lookaheads
=
collection
.
lookaheads
[
i
].
get
(
items
[
j
]).
getSymbols
();
get
(
items
[
j
])).
getSymbols
();
for
(
int
k
=
0
;
k
<
lookaheads
.
length
;
k
++)
for
(
int
k
=
0
;
k
<
lookaheads
.
length
;
k
++)
{
{
...
...
This diff is collapsed.
Click to expand it.
src/main/java/org/sablecc/sablecc/LR1Collection.java
+
18
−
24
View file @
75b83131
...
@@ -8,14 +8,13 @@
...
@@ -8,14 +8,13 @@
package
org.sablecc.sablecc
;
package
org.sablecc.sablecc
;
import
java.util.Vector
;
import
java.util.Vector
;
import
java.util.Enumeration
;
import
java.util.*
;
import
java.util.*
;
final
class
LR1Collection
final
class
LR1Collection
{
{
final
LR0Collection
collection
;
final
LR0Collection
collection
;
final
TreeMap
[]
lookaheads
;
final
TreeMap
<
LR0Item
,
SymbolSet
>
[]
lookaheads
;
private
final
TreeMap
[]
propagation
;
private
final
TreeMap
<
LR0Item
,
Vector
<
LR0ItemAndSetPair
>>
[]
propagation
;
LR1Collection
(
LR0ItemSet
set
LR1Collection
(
LR0ItemSet
set
)
)
...
@@ -25,25 +24,25 @@ final class LR1Collection
...
@@ -25,25 +24,25 @@ final class LR1Collection
// Initialize lookaheads to nothing, propagation to nothing
// Initialize lookaheads to nothing, propagation to nothing
LR0ItemSet
[]
sets
=
collection
.
sets
();
LR0ItemSet
[]
sets
=
collection
.
sets
();
lookaheads
=
new
TreeMap
[
sets
.
length
];
lookaheads
=
(
TreeMap
<
LR0Item
,
SymbolSet
>[])
new
TreeMap
<?,
?>
[
sets
.
length
];
propagation
=
new
TreeMap
[
sets
.
length
];
propagation
=
(
TreeMap
<
LR0Item
,
Vector
<
LR0ItemAndSetPair
>>[])
new
TreeMap
<?,
?>
[
sets
.
length
];
for
(
int
i
=
0
;
i
<
sets
.
length
;
i
++)
for
(
int
i
=
0
;
i
<
sets
.
length
;
i
++)
{
{
System
.
out
.
print
(
"."
);
System
.
out
.
print
(
"."
);
lookaheads
[
i
]
=
new
TreeMap
();
lookaheads
[
i
]
=
new
TreeMap
<>
();
propagation
[
i
]
=
new
TreeMap
();
propagation
[
i
]
=
new
TreeMap
<>
();
LR0Item
[]
items
=
sets
[
i
].
items
();
LR0Item
[]
items
=
sets
[
i
].
items
();
for
(
int
j
=
0
;
j
<
items
.
length
;
j
++)
for
(
int
j
=
0
;
j
<
items
.
length
;
j
++)
{
{
lookaheads
[
i
].
put
(
items
[
j
],
new
SymbolSet
());
lookaheads
[
i
].
put
(
items
[
j
],
new
SymbolSet
());
propagation
[
i
].
put
(
items
[
j
],
new
Vector
(
0
));
propagation
[
i
].
put
(
items
[
j
],
new
Vector
<
LR0ItemAndSetPair
>
(
0
));
}
}
}
}
System
.
out
.
println
();
System
.
out
.
println
();
((
SymbolSet
)
lookaheads
[
0
].
get
(
set
.
items
()[
0
])
)
.
setTerminal
(
Grammar
.
eof
);
lookaheads
[
0
].
get
(
set
.
items
()[
0
]).
setTerminal
(
Grammar
.
eof
);
for
(
int
i
=
0
;
i
<
sets
.
length
;
i
++)
for
(
int
i
=
0
;
i
<
sets
.
length
;
i
++)
{
{
...
@@ -73,17 +72,16 @@ final class LR1Collection
...
@@ -73,17 +72,16 @@ final class LR1Collection
if
(
destination
!=
null
)
if
(
destination
!=
null
)
{
{
((
SymbolSet
)
lookaheads
[
destination
.
intValue
()].
lookaheads
[
destination
.
intValue
()].
get
get
(
new
LR0Item
(
closure
[
k
].
lr0Item
.
production
,
(
new
LR0Item
(
closure
[
k
].
lr0Item
.
production
,
closure
[
k
].
lr0Item
.
position
+
1
))
)
.
closure
[
k
].
lr0Item
.
position
+
1
)).
setTerminal
(
closure
[
k
].
terminal
);
setTerminal
(
closure
[
k
].
terminal
);
/*
((SymbolSet)
lookaheads[collection.GOTO(i,
/*lookaheads[collection.GOTO(i,
Production.production(closure[k].lr0Item.production).
Production.production(closure[k].lr0Item.production).
rightside(closure[k].lr0Item.position)).intValue()].
rightside(closure[k].lr0Item.position)).intValue()].
get(new LR0Item(closure[k].lr0Item.production,
get(new LR0Item(closure[k].lr0Item.production,
closure[k].lr0Item.position + 1))
)
.
closure[k].lr0Item.position + 1)).
setTerminal(closure[k].terminal);*/
setTerminal(closure[k].terminal);*/
}
}
}
}
...
@@ -101,13 +99,13 @@ final class LR1Collection
...
@@ -101,13 +99,13 @@ final class LR1Collection
if
(
destination
!=
null
)
if
(
destination
!=
null
)
{
{
((
Vector
)
propagation
[
i
].
get
(
items
[
j
])
)
.
propagation
[
i
].
get
(
items
[
j
]).
addElement
(
new
LR0ItemAndSetPair
(
addElement
(
new
LR0ItemAndSetPair
(
new
LR0Item
(
closure
[
k
].
lr0Item
.
production
,
new
LR0Item
(
closure
[
k
].
lr0Item
.
production
,
closure
[
k
].
lr0Item
.
position
+
1
),
closure
[
k
].
lr0Item
.
position
+
1
),
destination
.
intValue
()));
destination
.
intValue
()));
/*
((Vector)
propagation[i].get(items[j])
)
.
/*propagation[i].get(items[j]).
addElement(new LR0ItemAndSetPair(
addElement(new LR0ItemAndSetPair(
new LR0Item(closure[k].lr0Item.production,
new LR0Item(closure[k].lr0Item.production,
closure[k].lr0Item.position + 1),
closure[k].lr0Item.position + 1),
...
@@ -133,15 +131,11 @@ final class LR1Collection
...
@@ -133,15 +131,11 @@ final class LR1Collection
for
(
int
j
=
0
;
j
<
items
.
length
;
j
++)
for
(
int
j
=
0
;
j
<
items
.
length
;
j
++)
{
{
for
(
Enumeration
e
=
((
Vector
)
propagation
[
i
].
get
(
items
[
j
])).
for
(
LR0ItemAndSetPair
pair
:
propagation
[
i
].
get
(
items
[
j
]))
elements
();
e
.
hasMoreElements
();)
{
{
LR0ItemAndSetPair
pair
=
(
LR0ItemAndSetPair
)
e
.
nextElement
();
SymbolSet
before
=
lookaheads
[
pair
.
set
].
get
(
pair
.
item
).
clone
();
SymbolSet
before
=
((
SymbolSet
)
lookaheads
[
pair
.
set
].
get
(
pair
.
item
)).
clone
();
lookaheads
[
pair
.
set
].
get
(
pair
.
item
).
or
(
lookaheads
[
i
].
get
(
items
[
j
]));
((
SymbolSet
)
lookaheads
[
pair
.
set
].
get
(
pair
.
item
)).
or
((
SymbolSet
)
lookaheads
[
i
].
get
(
items
[
j
]));
if
(!
before
.
equals
(
lookaheads
[
pair
.
set
].
get
(
pair
.
item
)))
if
(!
before
.
equals
(
lookaheads
[
pair
.
set
].
get
(
pair
.
item
)))
{
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment