Commits

Nzen  committed b5483bd

Small, ineffective changes

Think I corrected the fsa underlying lexer's operation. Not sure about
the utilities that flatTrie's fsa relies on. Misspent my weekend again.
Literally no more time to work on this.

Next actions on lexer: get it to compile, sent an overflowing int to
been_seen. print more from flat_trie. Make those test cases so I_know
what's going on.

  • Participants
  • Parent commits 208e3ce

Comments (0)

Files changed (8)

File FakeTrie.java

 		return ( only_b == 'b' );
 	}
 
+	@Override
+	public void reveal_thyself()
+	{
+		System.out.println( "I'm a fake trie" );
+	}
+
+	@Override
+	public T_Flag check_flag( char a_flag )
+	{
+		// TODO Auto-generated method stub
+		return null;
+	}
+
 }

File FlatTrie.java

 	private StringBuilder rest_stacked; // RENAME to symbols
 	private ArrayList<Integer> skip_list; // RENAME to next ; add(index, thing);
 	private int next_open;
-	private int view_pointer;
+	private int view_pointer; 
 
 	public FlatTrie( String first_char_alphabet, String end_flags )
 	{
 				return check_initial( to_validate );
 			case saving :
 				return save_char( to_validate );
-			case rest :
+			case checking :
 				return check_down_the_trie( view_pointer, to_validate ); // will recur
 		}
 		return T_Flag.f_seen;
 	private T_Flag match_rest( int where )
 	{
 		view_pointer = first_char[ where ];
-		state = T_Flag.rest;
+		state = T_Flag.checking;
 		return T_Flag.f_seen;
 	}
 
 
 	private T_Flag check_down_the_trie( int skip_ind, char hmm )
 	{
+		if ( skip_ind <= 0 )
+			return start_saving( hmm );
 		char presently = rest_stacked.charAt( skip_ind );
 		if ( match( hmm, presently ) )
 			return compare_more( skip_ind );
 		}
 	}
 
-	// only first char can point at 0
+	@Override
+	public T_Flag check_flag( char a_flag )
+	{
+		if ( state == T_Flag.saving )
+			return save_char( a_flag );
+		else
+			return check_down_the_trie( view_pointer, a_flag );
+	}
+
+	// only a single first char can point at 0
 	private boolean more_to_try( int skip_ind )
 	{
 		boolean left = true;
 	{
 		/*
 		for every width until the switch is done, then just symbol & next. Hopefully it all fits.
-		print ledger apace, first_chars to page width, "switch", their jump points, ledger, indicies, "symbol", chars in rest, "next", nothing unless > 0;
+		print ledger apace, first_chars to page width, "switch", their jump points, ledger, indicies,
+				"symbol", chars in rest, "next", nothing unless > 0;
 		*/
+		
+		int half_alpha = sigma.length() / 2 - 1;
+		int new_low = 0;
+		String storage = rest_stacked.toString();
+
+		int first_lim = half_alpha * 2 + 2;
+		while ( new_low < first_lim )
+		{
+			System.out.print( "\nFirst\t" );
+			for ( int a_search = new_low; a_search <= half_alpha; a_search++ )
+				System.out.print( first_char[ a_search ] );
+			System.out.print( "\nrest\t" );
+			for ( int a_search = new_low; a_search <= half_alpha; a_search++ )
+				System.out.print( storage.charAt( a_search ) );
+			System.out.print( "\nrest\t" );
+			for ( int a_search = new_low; a_search <= half_alpha; a_search++ )
+			{
+				boolean used = skip_list.get( a_search ) > 0;
+				char either = used ? int_to_char( skip_list.get( a_search ) ): ' ';
+				System.out.print( either );
+			}
+			System.out.println( );
+			new_low = half_alpha;
+			half_alpha *= 2;
+		}
+	}
 
-		for ( Integer xxx : first_char )
-			System.out.print( xxx );
-		for ( Character xxx : new IterableString( rest_stacked.toString() ) )
-			System.out.print( xxx );
-		for ( int ggg : skip_list )
-			System.out.print( ggg );
+	char int_to_char( Integer number )
+	{
+		return number.toString().charAt( 0 );
 	}
 }
 
 
 public enum L_Flag
 {
-	new_line, new_id, old_id, between
+	new_line, id_text, merge_to_id, between
 }
 		keymode = true;
 	}
 
-	public char lex_the_char( char next )
+	public char lex_char( char next ) // hmm... going to get report where appropriate for the moment
 	{
-		reported = transition_list.report_char_flag( next );
 		switch ( state )
 		{
 		case new_line :
-			return new_line_chosen( next );
-		case new_id :
-			return new_case_chosen( next );
-		case old_id :
-			return old_case_chosen( next );
+			return check_line( next );
+		case id_text :
+			return check_id( next );
 		case between :
-			return between_case_chosen( next );
+			return check_between( next );
 		default :
 			return empty;
 		}
 	}
 
-	private char new_line_chosen( char next )
+	private char check_line( char next )
 	{
-		if ( char_seen() )
+		if ( starts_id( next ) )
 		{
-			state = L_Flag.old_id;
-			return next;
-		}
-		else if ( char_unseen() )
-		{
-			state = L_Flag.new_id;
+			// move to id, emit the char
+			state = L_Flag.id_text;
 			return next;
 		}
 		else
 		}
 	}
 
-	private char new_case_chosen( char next )
+	private char check_id( char next )
 	{
+		if ( keymode )
+			return handle_key_mode( next );
+		// else input mode
 		if ( is_newline( next ) )
 		{
 			state = L_Flag.new_line;
-			buffer = "\n" + proper_flag( L_Flag.new_id );
+			buffer = Character.toString( proper_flag( reported ) ) + next;
 			return multi;
 		}
 		else if ( ends_id( next ) )
 		{
 			state = L_Flag.between;
-			return proper_flag( L_Flag.new_id );
+			return  proper_flag( reported );
 		}
 		else
 		{
+			reported = transition_list.report_char_flag( next );
 			return next;
 		}
 	}
 
-	private char old_case_chosen( char next )
+	private char handle_key_mode( char next )
 	{
-		if ( char_unseen() )
-		{
-			state = L_Flag.new_id;
-			return next;
-		}
-		else if ( char_seen() )
-			return next;
-		else if ( is_newline( next ) )
-		{
-			state = L_Flag.new_line;
-			buffer = "\n" + proper_flag( L_Flag.old_id );
-			return multi;
-		}
+		if ( next == ' ' )
+			transition_list.check_flag( proper_flag( T_Flag.f_unseen ) );
 		else
-		{
-			state = L_Flag.between;
-			return proper_flag( L_Flag.old_id );
-		}
+			transition_list.report_char_flag( next );
+		return next;
 	}
 
-	private char between_case_chosen( char next )
+	private char check_between( char next )
 	{
-		if ( char_unseen() )
+		if ( starts_id( next ) )
 		{
-			state = L_Flag.new_id;
-			buffer = " " + proper_flag( L_Flag.new_id );
-			return multi;
-		}
-		else if ( char_seen() )
-		{
-			state = L_Flag.old_id;
-			buffer = " " + proper_flag( L_Flag.old_id );
+			state = L_Flag.id_text;
+			buffer = " " + next;
 			return multi;
 		}
 		else if ( is_newline( next ) )
 		{
 			state = L_Flag.new_line;
-			return '\n';
+			return next;
 		}
 		else
+		{
 			return empty;
+		}
 	}
 
-	private char proper_flag( L_Flag which )
+	private char proper_flag( T_Flag which )
 	{
 		if ( keymode )
 			return '*';
-		else if ( which == L_Flag.new_id )
+		else if ( which == T_Flag.f_unseen )
 			return '?';
 		else
 			return '@';

File Project2.java

 		Loader of_keys = new Loader();
 		of_keys.open( keyw_file );
 		while ( of_keys.has_more() )
-			java_lexer.lex_the_char( of_keys.read_next() );
+			java_lexer.lex_char( of_keys.read_next() );
 		of_keys.close();
 		java_lexer.toggle_key_mode();
 	}
 		while ( generic.has_more() )
 		{
 			peek = generic.read_next();
-			became = java_lexer.lex_the_char( peek );
+			became = java_lexer.lex_char( peek );
 			if ( became == nothing )
 				continue;
 			else if ( became == read_several )

File Storage.java

 	public abstract boolean in_alphabet( char bn );
 
 	public abstract void reveal_thyself();
+	
+	public abstract T_Flag check_flag( char a_flag );
 }
 
 public enum T_Flag
 {
-	f_seen, f_unseen, f_diff_flag, saving, initial, rest 
+	f_seen, f_unseen, f_diff_flag, saving, initial, checking 
 }

File TestSuite.java

 		Lexer grammer_nazi = new Lexer( true );
 		// above creates with fake trie, not flat trie
 		grammer_nazi.ends_id( 'n' );
-		grammer_nazi.lex_the_char( 'd' );
+		grammer_nazi.lex_char( 'd' );
 	}
 
 	public void test_trie() // haha, pun