Hunter McMillen

Ranch Hand
+ Follow
since Mar 13, 2009
Hunter likes ...
Firefox Browser VI Editor Linux
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
27
Received in last 30 days
0
Total given
13
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Hunter McMillen

fred rosenberger wrote:
Finding examples of bad perl is like looking for grains of sand on a beach...




I really wish that I was able to refute this statement, but alas I cannot I should say that Perl Best Practices shows you how you aught to be writing Perl.
9 years ago
Learning Perl was already mentioned, but one of the better starting resources I have found is Modern Perl by Chromatic. It gives a good, concise overview to how you should be writing Perl. Another good resource is Perl Best Practices by Damian Conway. It might be more of a reference, but has really good examples of bad Perl and good Perl.

10 years ago

Vijay Kumar wrote:

I doubt, why do I need to visit on each element on string? What about below code. I know there is no O(N/2), as Ulf said its linear complexity, but in this case it is.



Just because you don't iterate from 0 to N doesn't mean that you don't operate on every element from 0 to N. In the code above you perform two operations per iteration of your for loop, which still comes out to be O(n). So regardless of how many operations you perform in your loop, you still touch N elements.

Also, this thread is 3 years old; you probably shouldn't post on it.

Hunter
11 years ago
What specifically are you having trouble with? Are you getting incorrect output? Do you get compile or runtime errors? You need to give more information about your problem.

Hunter
11 years ago
There are two ways to make custom thread classes in Java:

1) Have your class implement the Runnable interface
2) Have your class extend the Thread class

Option 1 is the best option in my opinion because not only can your custom class run in its own thread, it can also choose to inherit from some other class if needed. This is nice since in Java multiple inheritance is not supported.

When you make your class extend Runnable, you aren't actually making a thread class, you are making a class that can be passed to a constructor of the java.lang.Thread class, namely the one that takes a Runnable as a parameter. After creating your Thread object using this Runnable you just call the thread's start() method, just like you would any other thread.

example:



Hope this helps.

11 years ago
What is your desired output?

Hunter
11 years ago
Note: I have also posted this question here - http://stackoverflow.com/questions/9761267/encode-first-and-follow-sets-into-a-recursive-descent-parser

Hi everyone,

I am implementing the Syntax Analysis phase of my compiler by writing a recursive descent parser. I need to be able to take advantage of the FIRST and FOLLOW sets so I can handle errors in the syntax of the source program more efficiently. I have already calculated the FIRST and FOLLOW for all of my non-terminals, but am have trouble deciding where to logically place them in my program and what the best data-structure would be to do so.

Note: all code will be pseudo code

Option 1) Use a map, and map all non-terminals by their name to two Sets that contains their FIRST and FOLLOW sets:



This seems like a viable option, but inside of my parser I would then need sorta ugly code like this to retrieve the FIRST and FOLLOW and pass to error function:


Option 2) Create a class for each non-terminal and have a FIRST and FOLLOW property:


this leads to code that looks a little nicer:



These are the two options I thought up, I would love to hear any other suggestions for ways to encode these two sets, and also any critiques and additions to the two ways I posted would be helpful.
Thanks
12 years ago
You're right the left hand side of the statement will need to say Map<K,V> but this will work for any map implementation:




Hunter
12 years ago
Map is just an interface, what will actually be returned is a concrete implementation of that interface; which in this case is a HashMap since that is what you are passing in to the method.

The nice thing about the unmodifiableMap(...) returning a Map instead of a HashMap is that if later down the road you decide you don't want to use a HashMap , but instead a HashTable or a TreeMap all of the code should still function the same.

Hunter
12 years ago


takes a map as an argument and returns it in a context where it can't be modified. If you pass it a HashMap<K,V> it will still return a HashMap<K,V>:



Hope this helps.
Hunter
12 years ago
keep in mind that even if the language is large like Python, Ruby, or Perl; you don't need to know everything about the language to write small scripts. You only need to focus on the subset of the language your task requires.

Hunter
12 years ago

Gary Furash wrote:What do most Java programmers in these cases use as a scripting language? Something "full-blown" like Python, or just bash shell. Just curious. It would seem odd to learn a large complex language just to do quick scripting tasks. Cross platform would be nice, but even Perl can turn out to be pretty complicated.



When I was trying to figure out what scripting language to use I tried a bunch of online tutorials to get a feel for the languages, I ended up really enjoying Ruby and use that almost everyday now; but there are plenty of other alternatives, ksh, bash, python, perl, lua. A ton of languages you can choose from.


Hunter
12 years ago
Have a look at this page from the Java tutorials about visibility and access specifiers: http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

The answer you are looking for it near the bottom

Hunter
12 years ago
If you are just picking 3 random letters from the user's first name then there are some things to consider:

1) You need to know the length of the user's first name, store it in some variable
2) You can generate a random number from 0 to the length of the user's first name, this will represent a single character in the user's first name (do this 3 times, once for every letter you need)
3) Take a look at the charAt() or the substring() method in the String class API and see if you can find a way to use the numbers you randomly generated to get the character from the user's first name at the positions you generated in step 2

Try that and post back.

Hope this helps,
Hunter
12 years ago

Jessica Egart wrote:
the three letters of the license plate are generated from the user's input of their first name



How are the letters supposed to be generated from the user's first name? Just pick any 3 from their name? or is it the first 3 letters?


Hunter

12 years ago