Daniel Vlad

Greenhorn
+ Follow
since Aug 07, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Daniel Vlad

Thanks for clearing that up. I wish I would have had a course like that in college , would have been helpful . I understand the basics of compilers and parser , but I imagine a deeper understanding would have helped a lot right about now.
12 years ago
Thank you for the replies. At this point i pretty much have set some rules by which to define the grammar. As you said Jeff, the question i posted above is

a very high-level, oversimplified picture

but at the moment that is what i am struggling with .

@Pat: sorry, but what exactly do you mean by undergraduate CS program? Also , i will start looking into domain specific language so thanks.
12 years ago
Basically what i am trying to do is: 1. take some input from the user. this input will come under the form of a lot of if/else/switch/case combined with some simple math operations (the string i posted above is a very simple example).
2. if the input contains certain strings(i call them references), for example something like "AGE_Y" or "PROPERTY_LENGTH" (there are a lot of these also) , i grab the first occurrence of each of these and turn it into a variable to which i will add some extra code(in order for it to be read by another application) and insert it right above where it first appeared in the text. i'll post a clearer example lower.
3. once i created those variables i will replace all the occurrences of the references with the name of the variable

Now up to this point i''ve managed to do this properly, except that the insertion goes wonky, and that's why i need to do what i described in the above post. For example if i find x=PROPERTY_LENGTH; as the first occurrence of the reference , i already know the index of PROPERTY_LENGTH and of the = sign closest to it(made a method to help out with that), but i need to grab the value in front of the "=" sign in order to properly insert the newly created variable. for example , if it was in a list and the index of "=" would be , a variable called "index", i would do something like: which would grab me string "x"(who's length can obviously vary) , and after that i would simply do a

oh and for a clearer example of a string: this is a very simple example, but an accurate one.
12 years ago

Paul Clapham wrote:So in other words, first you decided to use a StringBuilder as a data structure to store some data, and now you're having trouble getting data back out of that data structure? That's because String and StringBuilder are really poor choices for storing structured data. As you are now finding out. So stop and choose some more suitable data structure.

That is one way to learn :).

Any suggestions on what data structures i should use to achieve what i need Paul?
12 years ago
I mean something like this: say i have a string like "if(c==1){a=x-3/23;\r\n z=23+newVariable;}" now i have mapped the indexes of every "=" sign and "if" that appear in that string because i need them for later. I split that string and added it to a List which now looks something like "[if, (, c, =, =, 1, ), ....]" then looped through the list and added every item to a stringBuilder and grabbed the index of the above mentioned "=" and "if" like this: Now at some point in my application i need to check what is in front of every "=" sign and do something according to that. Normally i would just do list.get(indexOfStrings) but since i got the index the way i did I am not able to do that because get() method will return the position when i need the index of the element (it will end up with the list having less elements than the actual value of indexOfString). That's why i'm looking for a way to do this using stringBuilder maybe. Open to any other suggestions of course. Hope i cleared my question up a bit and i didn't make it more confusing (i tend to do that )
12 years ago
Is there a way to retrieve a string from a StringBuilder if we know the index of the string we want to retrieve? i mean something similar to list.get().
12 years ago
I'm sorry i though i might not have been clear in my explanation : the 'j' and 'm' you are referring to are there simply as an example of user input. I didn't think i should really be concerned with them at all. Also i added AGE_X and AGE_Y to a List<String> called referenceList and i'm looping through that list(which will contain many more references in the future) to check every part of the user input (String text1) against them. Just to try and clear things up: 'j, m, AGE_X, AGE_Y' are all part of the user input (which i treat as a List<String> ). Also for sorting out the rules, i believe i have all i need for now and the exceptions i will deal with along the way because i'm really set on at least getting this to show the result i want:). The rules: 1. split the input from the user and add it to a List<String>
2. search the string for the first occurrence of each reference
3. when the first occurrence of each reference is found , create a new variable and assign to it the value of the reference + some more text around it (this is the reason i am creating a new variable and not just leaving it as AGE_X or AGE_Y)
4. place the newly created variable on the line above where the first occurrence of the reference was found
5.replace all the references with the created variables

Thank you for your answer and i will look into java.util.regex.Pattern and java.util.regex.Matcher.
12 years ago
Hello, i've recently been working on a way to take a user's input and depending on that it contains i will make some replacements in that certain string. For example , a user enters this input :

"if (AGE_X==10){\r\n"
+ " j=1;"
+ "AGE_X=5;"
+ " if(true){"
+ "m=4/AGE_Y;"
+ "}"
+ "}";


i want to create a variable for every type of reference(i'm calling AGE_X and AGE_Y references) found in the string. By this i mean , when i find the first occurence of AGE_X i want to add a new line in front of the that line and create a variable like so: AgeX=some string(AGE_X)... and then replace the every occurence of AGE_X with AgeX. Same will go for AGE_Y and and any other references found in the string(there will be a lot more such references , using these just for testing purposes).

So far my logic has been like this: split the large string so i can get the index of every reference and = sign inside it. Then , because i will have multiple indexes for every reference and sign i will map every reference to a list of it's indexes and do the same for all the signs. Once i've done this i will search for the smallest index in each list and insert the newly created variable there(as described above). So far i've run into some trouble with the code, and I am not sure where the problem is though my guess would be that i either got stuck somehow in the for loops or something went wrong with the mapping. This is how the code looks so far(i've extracted some unnecessary methods so i must have missed and } somewhere):



The commented line // text = TestSplitting.addDelimiters(text); is just a method that splits the string into pieces. Created it because the user will not be allowed spaces as i've placed them now in the text1 string so the method will parse that string and split it as necessary. So far i'm getting a result like this :

Reference AGE_X at position 3 has closest index at 0
Reference AGE_X at position 46 has closest index at 43
Reference AGE_Y at position 67 has closest index at 64

which is accurate, but i'm not sure how i have to proceed in order to map the each reference to it's value list properly and do what i described above(as you can see in some of the commented System.out.println the mapping doesn't work properly). For example the System.out.println("references-> " + references); will result in something like this:

references-> {AGE_X=[3]}
references-> {AGE_X=[46]}
references-> {AGE_Y=[67], AGE_X=[46]}

and i have no idea why it adds another AGE_X=[46] at the end.

If i didn't explain my issue clear enough please let me know and i will do my best to explain properly.

Any help would be greatly appreciated, i've been stuck at this for a while now and i think i'm missing some obvious things which i might not have missed if i was looking at it with fresh eyes. Also any suggestions on how to improve my code or logic are also more than welcome


12 years ago
that's what i get for not paying attention thanks for clearing that up.
12 years ago
hmm that's weird. i just copied your agetesting class and ran it, it works just fine for me even if you enter an age beyond 100. So i'm guessing it's something else?
12 years ago
Related to understanding the basic concepts of OOP, you could also try this little tutorial: http://sepwww.stanford.edu/sep/jon/family/jos/oop/oop1.htm . It helped me out quite a bit with understanding what objects are, what methods are and so on and how to relate them to the real world (which in my opinion is very important to do when you are at the beginner level).

Also , glad to see you are not giving up i struggled with the same things you do now but i managed to get the general idea after a while and the HeadFirst series has helped and is still helping me a lot.
12 years ago
Ok well, array indexing starts from 0 (unless i'm missing something). So if i'm understanding correctly "int i" should get the value of "1" so when i try to get the previous element i don't hit my head on the ArrayIndexOutOfBounds ? . But if i do that i won't be able to grab the first element of my list, so i guess i'm still missing something?
12 years ago
Ok i have a List that looks sort of like this:


now what i'm trying to do is this to detect if the string that precedes a given string is "=" but i can't figure out how to get that previous string:



i tried it in different ways, one of them being as you can see in the above code. I understand why i'm getting an error at that line but i can't really figure out if it is possible to do what i want using this kind of list.

Any help would be appreciated,
Daniel
12 years ago
Thanks for the advice. I ended up fixing my problem by adding a simple Javascript function which got the value i wanted from the selectbox and put it in the inputTextArea. (i can give a code example of how i fixed it if anyone is interested). Now I have another question : is it possible to make 2 buttons with (JSF or javascript and jquery) which basically imitate the effects that the Enter and Backspace keys would have on a textArea. For example if the user clicks the "Enter" button, the cursor will move to a new line and if he clicks the "Backspace" button he can delete the last entry he made in the textbox. I am asking this because i'm thinking of making the textArea readOnly for now and once my application evolves I will allow users who are more experienced to manually modify the formulas if they so desire.

Once again any input is welcome

Thanks,
Daniel
12 years ago
JSF
Well I'm currently doing something like this:



And it's doing what it should(printing the selected content to the textarea) , but the issue is that it will always appear in the textArea in the exact same order I put it in and that's not what I need it to do. I want the user to be able to select let's say "property1 from the first selectbox" and then click the "+" button and then select "property 3 from the second selectBox" and so on with other operators and properties, and end up with something like : property1 + property3 - whatever else he chooses + .... So I would like him to be able to see the operations he is doing in the textArea, but to see them in the exact order in which he is doing them. (If it's not clear what i wanted to say, please let me know).

The beans I''m using look something like this:



Same for the other beans i use to populate the selectBoxes. The output bean i use for saving the created formula to a .txt file.


I'm also thinking of doing something like this:



And then maybe iterrate through he list somehow and order them in the way we need(just an idea and not a pretty good one, but it's all i have for now). And use this method as an ajax listener in the JSF maybe?
Would appreciate any sort of input .

PS. maybe someone can point me to a Calculator like application on the web(preferably made with JSF, but not only) which i can study and maybe adapt something from there to what I need. Because honestly i see this as a sort of calculator which can also use words(strings) besides numbers and mathematical operations.
12 years ago
JSF