Skip to content

Commit 023c202

Browse files
committed
Removed dead code.
1 parent 669952a commit 023c202

File tree

5 files changed

+28
-34
lines changed

5 files changed

+28
-34
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ jobs:
7272
run: |
7373
python3 futhark-tests \
7474
--test-type=stuck \
75-
--grammar-size=1000
75+
--grammar-size=1000 \
76+
--lookback=1 \
77+
--lookahead=1
7678
7779
- name: Run parse test
7880
shell: bash

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cabal run parallel-parser -- grammars/paper_grammar.cg -q 1 -k 1
2222
```
2323
This will create the Futhark source file `paper_grammar.fut` which contains the actual parser which is a function `parse`. This function takes as input an array of indexes assigned to terminals and maps this to an array of indexes assigned to the productions. The indexes are assigned in the order they are defined. For this example the indexes for the terminals would be `0` is `a`, `1` is `b`, `2` is `c` and `3` is `$`. For the productions `0` is `T' -> T $`, `1` is `T -> R`, `2` is `T -> a T c`, `3` is `R -> `, `4` is `R -> b R`.
2424

25-
A leftmost derivable string from this grammar is `aabbbcc$` which corresponds to the indexes `[0, 0, 1, 1, 1, 2, 2, 3]`. When parsing this array the resulting productions sequence is `[0, 2, 2, 1, 4, 4, 4, 3]`.
25+
A leftmost derivable string from this grammar is `aabbbcc$` which corresponds to the indexes `[0, 0, 1, 1, 1, 2, 2, 3]`. When parsing this array the resulting production sequence is `[0, 2, 2, 1, 4, 4, 4, 3]`.
2626

2727
If an input is given that cannot be parsed then the empty array is returned.
2828

app/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ grammarError grammar
100100
| not $ null p_dups = Just [i|The given grammar contains duplicate productions because of #{p_dups_str}.|]
101101
| isLeftRecursive grammar = Just [i|The given grammar contains left recursion.|]
102102
| not $ null left_factors = Just [i|The given grammar contains productions that has common left factors due to the following nonterminals #{left_factors_str}.|]
103-
| rightNullableDoubleNT grammar = Just [i|The given grammar is able to derive two consecutive nonterminals that are the same and nullable.|]
103+
| rightNullableDoubleNT grammar = Just [i|The given grammar should not be able to derive two consecutive nullable nonterminals that are the same where the tail is nullable.|]
104104
| not $ null nonproductive = Just [i|The given grammar contains nonproductive productions due to the following nonterminals #{nonproductive_str}.|]
105105
| otherwise = Nothing
106106
where

futhark-tests/__main__.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ def generate_random_llp_grammar(
383383
no_duplicates: bool = True,
384384
quiet: bool = False):
385385

386+
generated_count = 0
386387
while True:
387388
filename = f'{name}.fut'
388389
grammar = generate_grammar(
@@ -409,32 +410,41 @@ def generate_random_llp_grammar(
409410
could_create = True
410411
except subprocess.CalledProcessError:
411412
pass
413+
412414

415+
generated_count += 1
416+
413417
if os.path.exists(f'{filename}') and could_create:
414418
if not quiet:
415419
print(f'{filename} contains a parser for the grammar: {grammar}.')
416-
return name, grammar
420+
return name, grammar, generated_count
417421

418-
def stuck_test(number_of_grammars: int):
422+
def stuck_test(number_of_grammars: int, q: int = 1, k: int = 1):
423+
count = 0
419424
for i in range(number_of_grammars):
420425
with DeleteNew():
421426
filename = f'temp_{i}'
422-
generate_random_llp_grammar(
427+
_, _, generated_count = generate_random_llp_grammar(
423428
filename,
424429
3,
425430
3,
426431
3,
427432
3,
428-
no_direct_left_recursion=True,
429-
no_duplicates=True
433+
q=q,
434+
k=k,
435+
no_direct_left_recursion=False,
436+
no_duplicates=False
430437
)
438+
count += generated_count
431439
time.sleep(0.05)
440+
acceptance_percent = 100 * number_of_grammars / count
441+
print(f'{acceptance_percent:.02f}% of grammars were accepted.')
432442

433-
def stuck_test_timed(number_of_grammars: int):
443+
def stuck_test_timed(number_of_grammars: int, q: int = 1, k: int = 1):
434444
p = multiprocessing.Process(
435445
target=stuck_test,
436446
name="stuck_check",
437-
args=(number_of_grammars,)
447+
args=(number_of_grammars, q, k)
438448
)
439449
p.start()
440450
p.join(18000) # 5 hours.
@@ -502,7 +512,7 @@ def generate_parser_test(
502512
) for i in range(number_of_grammars)
503513
)
504514

505-
for name, grammar in grammars:
515+
for name, grammar, _ in grammars:
506516
valid_strings = grammar.leftmost_derivations_index(
507517
valid_string_length
508518
)
@@ -557,8 +567,12 @@ def main():
557567
), "The parallel-parser binaries does not exists."
558568
elif args.test_type == 'stuck':
559569
assert args.grammar_size is not None, "grammar-size must be set."
570+
assert args.lookback is not None, "lookback must be set."
571+
assert args.lookahead is not None, "lookahead must be set."
560572
assert 0 == stuck_test_timed(
561-
number_of_grammars=args.grammar_size
573+
number_of_grammars=args.grammar_size,
574+
q=args.lookback,
575+
k=args.lookahead
562576
), "The parser probably got stuck while creating some grammar."
563577
elif args.test_type == 'parse':
564578
assert args.grammar_size is not None, "grammar-size must be set."

src/ParallelParser/LLP.hs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -845,34 +845,12 @@ llpParserTable = do
845845
let psls_table = psls collection -- filterAdmissiblePairs q k grammar $
846846
let unwrapped = (\[a] -> a) . Set.toList <$> psls_table
847847
let parsed = Map.mapWithKey auxiliary unwrapped
848-
is_ambiguous <- isAmbiguous
849848
let result
850-
| is_ambiguous = Nothing
851849
| isNothing maybe_table = Nothing
852850
| any ((/= 1) . Set.size) psls_table = Nothing
853851
| otherwise = Just parsed
854852
return result
855853

856-
isAmbiguous ::
857-
(Ord nt, Ord t, Show nt, Show t, NFData t, NFData nt) =>
858-
State (LlpContext nt t) Bool
859-
isAmbiguous = do
860-
ctx <- get
861-
let grammar = theGrammar ctx
862-
let prods = productions grammar
863-
let prods_map = toProductionsMap prods
864-
let isNullable = nullable grammar
865-
let nullable_prods_map = List.filter isNullable <$> prods_map
866-
let nullable_prods_count_map = List.length <$> nullable_prods_map
867-
let over_one_nullable_prod = any (1<) nullable_prods_count_map
868-
first_set_map <- mapM (mapM useFirst) prods_map
869-
let firsts_union = unionsIfDisjoint <$> first_set_map
870-
let overlapping_first_sets = any isNothing firsts_union
871-
let not_nullable_prods_map = List.filter (not . isNullable) <$> prods_map
872-
return $
873-
over_one_nullable_prod ||
874-
overlapping_first_sets
875-
876854
-- | Given a lsit create all the pairs with q lookback and k lookahead which
877855
-- will be used as keys in the table.
878856
pairLookup :: (Ord t, Show t) => Map ([t], [t]) v -> Int -> Int -> [t] -> [Maybe v]

0 commit comments

Comments
 (0)