Skip to content

Instantly share code, notes, and snippets.

@farcaller
Created November 16, 2012 17:02
Show Gist options
  • Save farcaller/4088991 to your computer and use it in GitHub Desktop.
Save farcaller/4088991 to your computer and use it in GitHub Desktop.
% rspec -f doc
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
Rly::LRTable
attaches the lookahead symbols to grammar rules (PENDING: verify that values in LRItem#lookaheads are meaningful)
computes the READS() relation (p,A) READS (t,C)
computes the LR(0) sets of item function
computes the follow sets given a set of LR(0) items, a set of non-terminal transitions, a readset, and an include set
creates a dictionary containing all of the non-terminals that might produce an empty production.
determines the lookback and includes relations
computes the LR(0) goto function goto(I,X) where I is a set of LR(0) items and X is a grammar symbol
finds all of the non-terminal transitions
parses the table
computes the read sets given a set of LR(0) items
computes the DR(p,A) relationships for non-terminal transitions
computes the LR(0) closure operation on I, where I is a set of LR(0) items
Rly::Grammar
has a default terminal -- error
rejects terminals named in lowercase
should generate parser.out same as Ply does (PENDING: thx to python dicts we have a different order of states. ideas?)
requires a list of terminals to be initialized
Start symbol specs
sets start symbol based on first production if it is not specified explicitly
sets zero rule to :S' -> :start
sets start symbol if it is specified explicitly
accepts only existing non-terminal as a start
adds 0 to start rule nonterminals
Production specs
does not allow duplicate rules
adds production to the list of productions referenced by names
adds production number to referenced non-terminals
registers one-char terminals
raises ArgumentError if one-char terminal is not actually an one char
adds production number to referenced terminals
rejects productions not named in lowercase
calculates production precedence based on rightmost terminal
adds production to the list of productions
adds production to the list of non-terminals
returns a Production object when adding production
rejects production named :error
defaults precedence to [:right, 0]
LR table generation specs
builds correct FIRST table
sets LR items to correct default values
builds correct FOLLOW table
builds LR items for grammar
Precedence specs
does not allow setting precedence several times for same terminal
does not allow to set precedence after any productions have been added
allows setting only :left, :right or :noassoc precedence associations
allows to set precedence
Rly::Production
has a length same as length of its symbols
converts to_s as source -> symbols
builds a list of unique symbols
Rly::Lex
Lexer with literals defined
outputs literal tokens
Lexer with no error handler
raises an error, if there is no possible tokens defined
raises an error, if there are no suitable tokens
Basic lexer
outputs tokens one by one
has a list of defined tokens
Lexer with ignores defined
honours ignores list
Lexer with error handler
calls an error function if it is available, which can skip a token
calls an error function if it is available, which returns a fixed token
Lexer with token that has a block given
calls a block to further process a token
Lexer with unnamed token and block given
processes but don't output tokens without a name
Pending:
Rly::LRTable attaches the lookahead symbols to grammar rules
# verify that values in LRItem#lookaheads are meaningful
# ./spec/parse/lr_table_spec.rb:195
Rly::Grammar should generate parser.out same as Ply does
# thx to python dicts we have a different order of states. ideas?
# ./spec/parse/grammar_spec.rb:217
Finished in 0.01856 seconds
55 examples, 0 failures, 2 pending
Randomized with seed 43146
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment