lib/filipinomemes/ruby_parser_patches.rb in filipinomemes-1.0.3 vs lib/filipinomemes/ruby_parser_patches.rb in filipinomemes-1.0.4
- old
+ new
@@ -1,5 +1,8 @@
+# Lexer
+# The Parsing method is explicitly UTF-8 so the Lexer is also explicitly UTF-8
+# Inorder to use the functions of yacc, we need to use BNF Grammar
class Lexer
def parse_number
self.lex_state = :expr_end
if src.scan(/[+-]?0[xXbBdD]\b/)
@@ -20,19 +23,24 @@
# elsif src.scan(/[+-]?[\d_]+\.[\d_]+(e[+-]?[\d_]+)?\b|[+-]?[\d_]+e[+-]?[\d_]+\b/i)
elsif src.scan(/[+-]?[\d_]+\,[\d_]+(e[+-]?[\d_]+)?\b|[+-]?[\d_]+e[+-]?[\d_]+\b/i)
number = src.matched.sub(',', '.')
rb_compile_error 'Invalid numeric format' if number =~ /__/
self.yacc_value = number.to_f
+ #values of token which had a value associated with it.
:tFLOAT
elsif src.scan(/[+-]?[0-9_]+(?![e])/)
int_with_base(10)
else
rb_compile_error 'Bad number format'
end
end
end
+
+# Parser
+# This will transform a piece of code (below are some samples) into an “abstract syntax tree".
+# It will build a structure which represents the semantics of the program.
module RubyParserStuff
class Keyword
wordlist = [
['glhf', %i[kBEGIN kBEGIN], :expr_beg],
['wala_na', %i[kBEGIN kBEGIN], :expr_beg],
@@ -97,21 +105,27 @@
['ako_magisip', %i[kWHILE kWHILE_MOD], :expr_beg],
['alyas', %i[kALIAS kALIAS], :expr_fname],
['__ENCODING__', %i[k__ENCODING__ k__ENCODING__], :expr_end]
].map { |args| KWtable.new(*args) }
+ #KWtable is Keyword Table
+
# :startdoc:
+
original_verbosity = $VERBOSE
$VERBOSE = nil
+ #$VERBOSE will check for errors or warnings on both syntax and those that happen at runtime.
WORDLIST18 = Hash[*wordlist.map { |o| [o.name, o] }.flatten]
WORDLIST19 = Hash[*wordlist.map { |o| [o.name, o] }.flatten]
$VERBOSE = original_verbosity
WORDLIST18.delete '__ENCODING__'
+ #Word array
+ #this returns an array of strings
%w[at
kays hakdog
elsip agik_ginagawa_mue
poreber por
ip agik