Implied multiplication?
If (check code here) [set (listCheck) to 1] [set (iterationCheck) to 1] [set (currentItem) to [(item (currentTotal.Iteration#) of [allTerms]] ] Repeat until <(done?) = 1> If <<(currentItem) > 0> and <(currentItem) < 11>> [change (iterationCheck) by 1] If <item ((listCheck) + 1 ) of [allTerms]> = [(] [insert [*] at ((listCheck) + 1) of [allTerms]] [set (done?) to 1] if <item ((listCheck) - 1) of [allTerms]> = [)] [insert [*] at ((listCheck) - 1) of [allTerms]] [set (done?) to 1] endIf if <(iterationCheck> = 10> [set (done?) to 1] endIf [change (listCheck) by 1] endIf If <(currentItem) = [)]> [if <item ((listCheck) + 1) of [allTerms] = [(] [insert [*] at ((listCheck) + 1) of [allTerms] [set (done?) to 1] else endif
Hold on, my code is messed up...
EDIT: Feel free to edit, i stil lthink its messed up, but go ahead and figure it out...
Last edited by bbbeb (2011-06-03 18:27:31)
Offline
I'm submitting Xenon here.
Offline
@bbbeb: Hardmath123 is gone for a bit of time because his school just started up (mine just ended). Concerning your code: you don't want it always to insert a * after a (. Consider 5 * (2 + 3).
You only want a * between a left parenthesis ) and a right parenthesis (
(5+2)(2+3)
or between a number and a right parenthesis (
5(2+3)
or between a left parenthesis ) and a number
(2+3)5
Offline
*Sigh of relief* School's out! I'll be able to do some more now. I've been checking this topic often (but wasn't posting), and I like what I see, but who's doing the implied multiplication? scratcher7_13, amcerbu, or bbbeb?
Current status: Awaiting my part, as soon as implied multiplication is out of the way.
Oh, one thing:
amcerbu wrote:
... make sure that negative signs (-x) are converted to "-1*x". So, -4 will become "-1*4". That will clear up some problems later in the execution.
Wouldn't changing it to "-1*4" be inserting yet another negative (-1)? Wouldn't it be easier to change it to "0-4"?
Offline
@hpotter134- Sorry, I don't think that will work anyway. The program must distinguish between something like 5 - 4 and 5 * - 4.
5 - 4 would become 5 0 - 4 or 5 (- 1 * 4), instead of 5 + 0 - 4.
I'm not exactly sure how to deal with this.
Supposedly (according to a post by Hardmath123), the implied multiplication job is in my hands. However, if bbbeb wants to do it, I'm fine with that. scratcher7_13 quit/went inactive. We ought to discuss some code in-forum so that someone can later go straight to Scratch.
@everyone: If you have any ideas at all about dealing with implied multiplication, post them in a [code] box.
Last edited by amcerbu (2011-06-03 22:08:31)
Offline
amcerbu wrote:
@hpotter134- Sorry, I don't think that will work anyway. The program must distinguish between something like 5 - 4 and 5 * - 4.
5 - 4 would become 5 0 - 4 or 5 (- 1 * 4), instead of 5 + 0 - 4.
I'm not exactly sure how to deal with this.
Supposedly (according to a post by Hardmath123), the implied multiplication job is in my hands. However, if bbbeb wants to do it, I'm fine with that. scratcher7_13 quit/went inactive. We ought to discuss some code in-forum so that someone can later go straight to Scratch.
@everyone: If you have any ideas at all about dealing with implied multiplication, post them in a [code] box.
Hmm...maybe the 5*-4 shouldn't be allowed, i.e. it should cause an error, so the user would be forced to place the -4 in parenthesis, making it 5*(-4), which becomes 5*(0-4), and voila.
So unless the previous item is either a number or a close parenthesis ')', a zero should be inserted before the '-'. Make sense?
Offline
Yeah, that sounds like it would work. So, negative terms must be presented within parentheses, and a zero is inserted only if the negative term is isolated.
5-3 good (5)-3 good 5*-3 bad, user should replace with 5*(-3) programmed to be replaced with 5*(0-3)
Last edited by amcerbu (2011-06-04 15:21:06)
Offline
amcerbu wrote:
Good! But why do you limit the length of the sequence to 10?
Its the current character- it detects 0-9 (and 10, idk why)
as in the current digit, not the sequence.
Offline
bbbeb wrote:
amcerbu wrote:
Good! But why do you limit the length of the sequence to 10?
Its the current character- it detects 0-9 (and 10, idk why)
as in the current digit, not the sequence.
Oh! It took me about ten read-throughs to get it, so you are checking that the item is a number, yes?
I think the whole thing might be much faster if we "tokenise" it. In the original parsing (scimonster's code), we could also record the item type of each item in a separate list, where each item in scimonster's generated Input list has a corresponding "token" in the other list. This way, we can figure out the type once, and any subsequent scripts will look at the tokens list rather than figure out the type again. So
currentItem = index of this item in the inputList if <(item: currentItem of: tokenList) = 'num'> //perform action
Instead of doing weird stuff like checking if the number is a digit, because the way scimonster made it, bbbeb, it doesn't have to be a digit, it could be much larger.
Offline
hpotter134 wrote:
bbbeb wrote:
amcerbu wrote:
Good! But why do you limit the length of the sequence to 10?
Its the current character- it detects 0-9 (and 10, idk why)
as in the current digit, not the sequence.Oh! It took me about ten read-throughs to get it, so you are checking that the item is a number, yes?
I think the whole thing might be much faster if we "tokenise" it. In the original parsing (scimonster's code), we could also record the item type of each item in a separate list, where each item in scimonster's generated Input list has a corresponding "token" in the other list. This way, we can figure out the type once, and any subsequent scripts will look at the tokens list rather than figure out the type again. SoCode:
currentItem = index of this item in the inputList if <(item: currentItem of: tokenList) = 'num'> //perform actionInstead of doing weird stuff like checking if the number is a digit, because the way scimonster made it, bbbeb, it doesn't have to be a digit, it could be much larger.
Can you please explain in detail? I'm trying to figure out what tokens are, but the concept to me is confusing.
Offline
bbbeb wrote:
hpotter134 wrote:
...
Can you please explain in detail? I'm trying to figure out what tokens are, but the concept to me is confusing.
Sorry if I wasn't clear.
So, when we process the user's input, we currently make one list. So 2(5+13) would be parsed into
2
(
5
+
13
)
right? But each item is a certain type, in this case its either a number, an open parenthesis, a close parenthesis, or an operator. Later in the program, we will want to do something to each item in the list above depending on its type, as in, we want to know what type of item each item is. Make sense so far?
Figuring out the type of item could be tedious, and could include scanning multiple lists and other yuck. So, if we have to figure out the type of an item more than once, the program will be significantly bulkier and slower.
So my suggestion is that we figure out the type of each item at the very beginning, and parse it into two list, not one. So it becomes:
inputList tokenList 2 number ( open parenthesis 5 number + operator 13 number ) close parenthesis
So later scripts would just look at tokenList to see the type, rather than checking what type the item is in the first list. This will allow us to get really specific with types (such func3 for a function with three arguments, or something like that), without slowing the program down too much.
Offline
hpotter134 wrote:
bbbeb wrote:
hpotter134 wrote:
...
Can you please explain in detail? I'm trying to figure out what tokens are, but the concept to me is confusing.
Sorry if I wasn't clear.
So, when we process the user's input, we currently make one list. So 2(5+13) would be parsed into
2
(
5
+
13
)
right? But each item is a certain type, in this case its either a number, an open parenthesis, a close parenthesis, or an operator. Later in the program, we will want to do something to each item in the list above depending on its type, as in, we want to know what type of item each item is. Make sense so far?
Figuring out the type of item could be tedious, and could include scanning multiple lists and other yuck. So, if we have to figure out the type of an item more than once, the program will be significantly bulkier and slower.
So my suggestion is that we figure out the type of each item at the very beginning, and parse it into two list, not one. So it becomes:Code:
inputList tokenList 2 number ( open parenthesis 5 number + operator 13 number ) close parenthesisSo later scripts would just look at tokenList to see the type, rather than checking what type the item is in the first list. This will allow us to get really specific with types (such func3 for a function with three arguments, or something like that), without slowing the program down too much.
Oohhhhh!
Thanks!
I should do a runthrough of my code to optimize it, but instead i'm just going to copy it into this and optimize it there so I have a backup....
If (check code here) [set (listCheck) to 1] [set (iterationCheck) to 1] [set (currentItem) to [(item (currentTotal.Iteration#) of [allTerms]] ] Repeat until <(done?) = 1> If <item (currentItem) of [tokenList] = [number]> If <item ((listCheck) + 1 ) of [inputList]> = [(] [insert [*] at ((listCheck) + 1) of [inputList]] [set (done?) to 1] if <item ((listCheck) - 1) of [inputList]> = [)] [insert [*] at ((listCheck) - 1) of [allTerms]] [set (done?) to 1] endIf [change (listCheck) by 1] endIf If <(currentItem) = [)]> [if <item ((listCheck) + 1) of [tokenList] = [(] [insert [*] at ((listCheck) + 1) of [tokenList] [set (done?) to 1] else endif endif
Last edited by bbbeb (2011-06-05 19:51:25)
Offline
amcerbu wrote:
Good! In the actual program's token list, numbers can be represented by n, operators by o, and parentheses by p.
Actually, I would recommend N(umber), O(perator) C(lose parentheses), O(pen parentheses).
Offline
In case of 5*-3, make the list item (3) into (-3)! So simple!
List:
5
*
-
3
to:
List:
5
*
-3
Offline
I meant to say that!
You're completely right.
Offline
What's the fastest and most failproof method of figuring out what "type" an item is? We could use this for starters, but what then?
Offline
Umm... But now you have two "O"s! I would suggest "S" for starting parenthesis and "E" for end parenthesis, just plain old "(" and ")", or a capital "O" for open parenthesis and a lower case "o" for operators. [offTopic]I'm so happy! I have a website making camp today!!!
[/offTopic]
scimonster wrote:
amcerbu wrote:
Good! In the actual program's token list, numbers can be represented by n, operators by o, and parentheses by p.
Actually, I would recommend N(umber), O(perator) C(lose parentheses), O(pen parentheses).
Offline
applejack wrote:
Umm... But now you have two "O"s! I would suggest "S" for starting parenthesis and "E" for end parenthesis, just plain old "(" and ")", or a capital "O" for open parenthesis and a lower case "o" for operators. [offTopic]I'm so happy! I have a website making camp today!!!
[/offTopic]
scimonster wrote:
amcerbu wrote:
Good! In the actual program's token list, numbers can be represented by n, operators by o, and parentheses by p.
Actually, I would recommend N(umber), O(perator) C(lose parentheses), O(pen parentheses).
It's really hard to do case sensing, so yeah, ( & ).
EDIT: 200th post on this topic!
Last edited by scimonster (2011-06-06 12:54:45)
Offline