Steven! Ragnarök avatar Steven! Ragnarök committed 5894467

In which I talk a lot but get no code written.

Comments (0)

Files changed (1)

 class TopDowner
+	attr_accessor :tree
 	def initialize grammar, token_types
 		@grammar = grammar
 		@token_types = token_types
 		@r_cache = Hash.new
+		@tree = Hash.new
 	end
 
 	def parse string
+		@tree = Hash.new
 		@enumerator = tokenize(string).each
-		@tree = Hash.new
 		recognize [:Program]
 	end
 
 		end
 	end
 
-	# Returns all valid token types of the first terminal in a construct.
-	def first construct
-		#		return [Grammar.has_key? construct && first(Grammar[construct]) ||
-			# construct].flatten
+	# After we get a tokenized string, what should we do. The logic of the topdown
+	# process dictates that we do as follows:
+	# - expand the rules
+	#   - matching input tokens
+	#   	- as predicted by rules
+	# So we've got the rules described by our @grammar and our token types
+	# defined by @token_type. We may want to detect functions as distinct from
+	# regular identifers but I don't want to if I don't have to.
+	# Now that we have our enumerator, what do we do with it?
+	# First we need to build some functions which recognize the first two
+	# symbols for each rule so that we can accurately consume our language.
+	# Now that we have a plan. Let's fuck some shit up!!!!
+	
+	## returns a set of all possible [:first, :second] tokens for a given rule.
+	def first_two rule
+		# Check that rule is a nonterminal.
+		if @grammar.has_key? rule
+			# implement :* behavior
+			if @grammar[rule].include? :*
+				(@grammar)
+			end
+		end
 	end
 
-	## Recognizer ##
-	# Returns a symbol describing what is constructed by the token 
-	# and lookahead. For a token :return and a lookahead :"4", it returns
-	# :ReturnStatement. For a token :lparen and a lookahead :ident it would
-	# return :Arglist.
-
-	def recognize construct
-		case construct
-		# Array means nonliteral.
-		when Array
-			# check for meta-grammar
-			return construct.map {|r| parse @grammar[r] || r}
-		# Symbol means literal
-		when Symbol
-			tkn = @enumerator.next
-			puts tkn
-			if tkn[:type] == construct
-				# Base step of recursion
-				return tkn[:token]
-			else
-				raise ArgumentError.new "Got #{tkn}, expected #{recognizer}"
-			end
-		else raise ArgumentError.new "What the fuck?"
-		end
-	end
 end
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.