Sha256: dc71edc661db2e2416afb90d89877d95e2e9b4b1ab91e9f0ef29e3de5be25143
Contents?: true
Size: 726 Bytes
Versions: 17
Compression:
Stored size: 726 Bytes
Contents
# Purpose: to demonstrate how to build a very simple grammar require 'rley' # Load the gem # A very simple language # It recognizes/generates strings like 'b', 'abc', 'aabcc', 'aaabccc',... # (based on example in N. Wirth's book "Compiler Construction", p. 6) # S ::= A. # A ::= "a" A "c". # A ::= "b". # Let's create the grammar step-by-step with the grammar builder: builder = Rley::Syntax::GrammarBuilder.new builder.add_terminals('a', 'b', 'c') builder.add_production('S' => 'A') builder.add_production('A' => %w(a A c)) builder.add_production('A' => 'b') # And now build the grammar... grammar_abc = builder.grammar # Prove that it is a grammar puts grammar_abc.class.name # End of file
Version data entries
17 entries across 17 versions & 1 rubygems