rley 0.0.06 → 0.0.07

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzBkOTQ2MmQ2MDcxZGFjZTM5YzNlZGY5NDg1MTFhOWVjYzFjNWFkYg==
4
+ OWUyN2U0MzRhZWM3Y2MxZWU4Y2JjZWJmYjVkMGNmMmFlYzY5ODRlYQ==
5
5
  data.tar.gz: !binary |-
6
- ZjEwNzMyNWRjMmUxMGU1YjJmYzQxODg5NjA4M2YzNWU4NmVhNzcyYw==
6
+ YWUzOGE1NjVhZjY3MjU1YzBhYzZkMTA5MTIwZjg2M2NlYWEwYjdjOQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MWNhOTQyOGQ3NzcwMzcxY2FlYTgzMWJhMGNlYmQzYzM2ZTAwNjdlZjJkOGE1
10
- ODZiODkxMGFlNzc5NjUxNzA3OTVjNzFkNzY1NGQ2MTc4MDRjMTg0YWRhODc5
11
- ZTU3NDhjZmY3ZDE2YjM3NmRjZjA0MTVmNjNmZGQxYmE4YTg5YmM=
9
+ ZTE4NDdmNmRjZmEzNTM0OTJkZTVkMTc5OGUyMWEyNTE4ZTZkYzUxYThhYzBk
10
+ YTE1ZjAyM2IzNDhjZGNiMTYwNGNlNWM3ZDYwNDBlYjM5NDlmNDcwNWNkZWI2
11
+ M2MyODVkNjcwYzM5ZDgwMzVhMDY4ZjFhYWZlNjU2ZGYxYjQ3YjI=
12
12
  data.tar.gz: !binary |-
13
- MzQ2MmRkMjIyMWQxZGI1MTBmOTdhMDY1ZTYxYjc0MGExZGJjZjFkMjZlOTM3
14
- MTk0NjdhMjUwNjAwYWQzMzBlOTdhNzg5ZmFlNWFjNjlhOWM3ZjMxMWJlOTFj
15
- NjVlODk3NjBkYTQ3OTFjODBlMjQ2ZjZjNTA5ZGIxZjdiYWIxYzA=
13
+ MWQ3ZTFhNjBiMmZlZGZmOWRlMzgzNjQyMWI5OTkwNjBjMzdkYmI3NDU0NzZh
14
+ MWQ3Y2JlNmU3MDU3NGVmZDBhN2EyNWY2M2RhNjNlNDUwNjJhMzI0M2UwZGM4
15
+ MzI0OGI3YjI5ZWM3ZDVhZDU3MTlkNjdhZGE4OWZkYWIyMGIwNTI=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ### 0.0.07 / 2014-11-14
2
+ * [CHANGE] spec file of `EarleyParser` class: Test added. Parser works with simple expression grammar.
3
+
1
4
  ### 0.0.06 / 2014-11-13
2
5
  * [CHANGE] File `README.md`: Added roadmap section.
3
6
  * [FIX] `EarleyParser#parse`: prevent call to `scanning` method after last token encountered.
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Rley # Module used as a namespace
5
5
  # The version number of the gem.
6
- Version = '0.0.06'
6
+ Version = '0.0.07'
7
7
 
8
8
  # Brief description of the gem.
9
9
  Description = "Ruby implementation of the Earley's parsing algorithm"
@@ -33,7 +33,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
33
33
  end
34
34
  =end
35
35
 
36
- # Grammar 1: A very simple language
36
+ # Grammar 1: A very simple language
37
37
  # (based on example in N. Wirth "Compiler Construction" book, p. 6)
38
38
  # S ::= A.
39
39
  # A ::= "a" A "c".
@@ -85,7 +85,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
85
85
  let(:prod_P) { Syntax::Production.new(nt_P, [nt_S]) }
86
86
  let(:prod_S1) { Syntax::Production.new(nt_S, [nt_S, plus, nt_M]) }
87
87
  let(:prod_S2) { Syntax::Production.new(nt_S, [nt_M]) }
88
- let(:prod_M1) { Syntax::Production.new(nt_M, [nt_M, star, nt_M]) }
88
+ let(:prod_M1) { Syntax::Production.new(nt_M, [nt_M, star, nt_T]) }
89
89
  let(:prod_M2) { Syntax::Production.new(nt_M, [nt_T]) }
90
90
  let(:prod_T) { Syntax::Production.new(nt_T, [integer]) }
91
91
  let(:grammar_expr) do
@@ -244,13 +244,13 @@ module Rley # Open this namespace to avoid module qualifier prefixes
244
244
  ]
245
245
  compare_state_set(state_set_5, expectations)
246
246
  end
247
-
247
+
248
248
  it 'should parse a valid simple expression' do
249
249
  instance = EarleyParser.new(grammar_expr)
250
250
  parse_result = instance.parse(grm2_tokens)
251
251
  expect(parse_result.success?).to eq(true)
252
-
253
- ######################
252
+
253
+ ###################### S(0): . 2 + 3 * 4
254
254
  # Expectation chart[0]:
255
255
  # (1) P -> . S, 0 # start rule
256
256
  # (2) S -> . S "+" M, 0 # predict from (1)
@@ -268,8 +268,83 @@ module Rley # Open this namespace to avoid module qualifier prefixes
268
268
  ]
269
269
  compare_state_set(parse_result.chart[0], expectations)
270
270
 
271
+ ###################### S(1): 2 . + 3 * 4
272
+ # Expectation chart[1]:
273
+ # (1) T -> integer ., 0 # scan from S(0) 6
274
+ # (2) M -> T ., 0 # complete from (1) and S(0) 5
275
+ # (3) S -> M ., 0 # complete from (2) and S(0) 3
276
+ # (4) M -> M . "*" T, 0 # complete from (2) and S(0) 4
277
+ # (5) P -> S ., 0 # complete from (4) and S(0) 1
278
+ # (6) S -> S . "+" M, 0 # complete from (4) and S(0) 2
279
+ expectations = [
280
+ { origin: 0, production: prod_T, dot: -1 },
281
+ { origin: 0, production: prod_M2, dot: -1 },
282
+ { origin: 0, production: prod_S2, dot: -1 },
283
+ { origin: 0, production: prod_M1, dot: 1 },
284
+ { origin: 0, production: prod_P, dot: -1 },
285
+ { origin: 0, production: prod_S1, dot: 1 },
286
+ ]
287
+ compare_state_set(parse_result.chart[1], expectations)
288
+
289
+
290
+ ###################### S(2): 2 + . 3 * 4
291
+ # Expectation chart[2]:
292
+ # (1) S -> S "+" . M, 0 # scan from S(1) 6
293
+ # (2) M -> . M "*" T, 2 # predict from (1)
294
+ # (3) M -> . T, 2 # predict from (1)
295
+ # (4) T -> . integer, 2 # predict from (3)
296
+ expectations = [
297
+ { origin: 0, production: prod_S1, dot: 2 },
298
+ { origin: 2, production: prod_M1, dot: 0 },
299
+ { origin: 2, production: prod_M2, dot: 0 },
300
+ { origin: 2, production: prod_T, dot: 0 },
301
+ ]
302
+ compare_state_set(parse_result.chart[2], expectations)
303
+
304
+ ###################### S(3): 2 + 3 . * 4
305
+ # Expectation chart[3]:
306
+ # (1) T -> integer ., 2 # scan from S(2) 4
307
+ # (2) M -> T ., 2 # complete from (1) and S(2) 3
308
+ # (3) S -> S "+" M ., 0 # complete from (1) and S(2) 1
309
+ # (4) M -> M . "*" T, 2 # complete from (2) and S(2) 2
310
+ # (5) P -> S ., 0 # complete from (4) and S(0) 1
311
+ expectations = [
312
+ { origin: 2, production: prod_T, dot: -1 },
313
+ { origin: 2, production: prod_M2, dot: -1 },
314
+ { origin: 0, production: prod_S1, dot: -1 },
315
+ { origin: 2, production: prod_M1, dot: 1 },
316
+ { origin: 0, production: prod_P, dot: -1 }
317
+ ]
318
+ compare_state_set(parse_result.chart[3], expectations)
319
+
320
+ ###################### S(4): 2 + 3 * . 4
321
+ # Expectation chart[4]:
322
+ # (1) M -> M "*" . T, 2 # scan from S(3) 4
323
+ # (2) T -> . number, 4 # predict from (1)
324
+
325
+ expectations = [
326
+ { origin: 2, production: prod_M1, dot: 2 },
327
+ { origin: 4, production: prod_T, dot: 0 },
328
+ ]
329
+ compare_state_set(parse_result.chart[4], expectations)
330
+
331
+ ###################### S(5): 2 + 3 * 4 .
332
+ # Expectation chart[5]:
333
+ # (1) T -> number ., 4 # scan from S(4) 2
334
+ # (2) M -> M "*" T ., 2 # complete from (1) and S(4) 1
335
+ # (3) S -> S "+" M ., 0 # complete from (2) and S(2) 1
336
+ # (4) M -> M . "*" T, 2 # complete from (2) and S(2) 2
337
+ # (5) P -> S ., 0 # complete from (3) and S(2) 2
338
+ expectations = [
339
+ { origin: 4, production: prod_T, dot: -1 },
340
+ { origin: 2, production: prod_M1, dot: -1 },
341
+ { origin: 0, production: prod_S1, dot: -1 },
342
+ { origin: 2, production: prod_M1, dot: 1 },
343
+ { origin: 0, production: prod_P, dot: -1 }
344
+ ]
345
+ compare_state_set(parse_result.chart[5], expectations)
271
346
  end
272
-
347
+
273
348
 
274
349
  it 'should parse an invalid simple input' do
275
350
  # Parse an erroneous input (b is missing)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rley
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.06
4
+ version: 0.0.07
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-13 00:00:00.000000000 Z
11
+ date: 2014-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake