Intellectual Property?

Pages: 12
closed account (Dy7SLyTq)
So i could care less if i get my name on a piece of software. i love coding so thats my best reward. however not everyone feels the same as me. so what my question. how should i give credit to someone? a specific example is im building a parser, but i need to check for balanced [ { and (. I dont know how to build one for myself. i remember one on this site. now in this case i can just ask the guy what he wants, but what about people who dont respond to emails or dont provide a way to contact him or her.
What I would do in a case like that is, put his/her name in the credits of your parser, and a link to the place you got their code form.
closed account (Dy7SLyTq)
ok. thanks for the reply.
And now let this thread become five pages long with an incredibly long discussion about a problem that has been solved. Oh, and don't forget the usual argument.

EDIT: The green tick means nothing.
Last edited on
I disagree, I think the green tick is important. Unlike that checkmark icon, which is meaningless.
closed account (Dy7SLyTq)
i know its meaningless i just wanted to mark it as solved
i know its meaningless i just wanted to mark it as solved

fair enough, but people will still post to a solved thread long after it should be in the archives.
Script Coder wrote:
What I would do in a case like that is, put his/her name in the credits of your parser, and a link to the place you got their code form.
Unless the author explicitly says it can be used or has a license I wouldn't use it.
Just write it on your own. Here is one way you could do it:

If at any point, you have more closing brackets than opening brackets, you know it's not balanced. [ ] ]

The same isn't true the other way around. [ [ ]

In the end, if the number of closing brackets is not equal to the number of opening brackets, then it's not balanced.

1
2
3
4
5
6
7
8
9
10
11
12
13
b = 0
balanced = true

for each character
    if [
        ++b
    if ]
        --b
    if a < 0
         balanced = false

if b != 0
    balanced = false

Last edited on
fair enough, but people will still post to a solved thread long after it should be in the archives.

People other than then OP might come across this thread. That the OP is satisfied with an answer is less important than wether or not the question has been adequately addressed.
Last edited on
iseeplusplus:
In the end, if the number of closing brackets is not equal to the number of opening brackets, then it's not balanced.

That doesn't deal with situations like this { [ } ]; right number of opens and closes but still wrong.
Your right. That does complicate the problem. I understand why you might want to use an established algorithm in that case.

Can you just modify it to add the condition that:

If the current one is closing, and the last one is not of the same type as the current one and is opening, then not balanced.

Something like this. (sorry for bad pseudo code style)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
token[3];
token[0].opening = '{'
token[1].opening = '['
token[2].opening = '('
token[0].closing = '}'
token[1].closing = ']'
token[2].closing = ')'

balance[3] = {0, 0, 0}
open[3]    = {null, null, null}

for each character c {
   
    if (c is a closing token)
        if prev != opening version of c,  and prev is opening
            return false

    for i = 0 to 2 {
        if(c == token[i].opening) {
            ++balance[i]
            open[i] = true
            prev = token[i].opening
            prevOpen = true
            break
        }
        if(c == token[i].closing) {
            --balance[i]
            open[i] = false
            prev = token[i].closing
            prevOpen = false
            if balance[i] < 0
                return false
            break
        }
    }
}      
for i = 0 to 2
    if balance[i] != 0
        return false

It seams valid, but I might be missing something.
Last edited on
Your algorithm fails to remember more than one level of nesting, beyond the count of types of brackets. A string where the right brackets are in a different order than the left brackets but the innermost brackets match, such as "{(()})", breaks it.
You need a stack of tokens. When a left bracket comes it, it gets pushed. When a right bracket comes in, if the stack is empty or the token doesn't match the top of the stack, the string is invalid. After the loop, the string is valid iff the stack is empty.
Just because you write someone's name at the bottom of some text file you distribute with your program, doesn't mean you can just use their code. You have to get permission first, unless it's explicitly stated somewhere you can use it if you give credit, or if the license says you can redistribute the code or make derivative works.
closed account (Dy7SLyTq)
what if its just a random snippet like:
http://www.cplusplus.com/forum/lounge/100453/#msg540410

and he doesnt respond to my message asking if i can use it. he doesnt say i can use it explicitly or provide a liscense
closed account (1yR4jE8b)
Hey, someone seems to have accidentally left the bank vault open...I would like some money but there is no sign or any workers around to ask if I can, does that mean it's legal for me to take it?
closed account (Dy7SLyTq)
a) if you left a bank vault open with no one around to guard it, you deserve to have it stolen

b) while i see what you mean by the example, its not a good one because if (s)he never found out (s)he is the same off
Speaking of parsers, this is the forum post from which I learned how to parse expressions. This is the only article/forum post on parsing I've ever read, and it has covered all my parsing needs so far.

http://www.cplusplus.com/forum/lounge/11845/
What is this topic even about now? I'm having a hard time following it without getting involved.
closed account (Dy7SLyTq)
the steps you take to get code snippets and fragments off the web
ie legal rights and ettiquite
Pages: 12