• Congratulations to the Class of 2024 on your results!
    Let us know how you went here
    Got a question about your uni preferences? Ask us here

A number of problems ..... (1 Viewer)

chris42

Member
Joined
Oct 4, 2003
Messages
649
Location
Sydney
Gender
Male
HSC
2004
Tokens.. What are tokens and whats the difference between parsed tokens and tokens
Whats a relational operator, arithmetic operator and assignment statement
And a question says a processor has a word size of 128bits how many bytes of data can it process at one time ? How do you work that out.. Answers inc 7,8,16,32
how do you sort arrays that are letter arrays ?


AB BA ZA ZB AR BD WR DS FG and Im meant to do a selection sort on it in descending order and its not working


I ended up getting AB BA FG LK AR BD DS WR 2A 2B
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Ok


i know a few

relational ops : <, >, =

arithmetic ops: +, -, *, /, MOD


128 bits?, there are 8 bits per byte so 128/8 = 16 bytes
 

Fosweb

I could be your Doctor...
Joined
Jun 20, 2003
Messages
594
Location
UNSW. Still.
Gender
Male
HSC
2003
Meh... Database error last time i tried to post this, sorry if its already been answered...

Tokens: (Part of the Lexical Analysis part of Translating code)
When translating code, the processor needs to know what words are used in the code, but if words are encountered multiple
times, then you are wasting a lot of time reading each word over again.
So a translator goes through the code and replaces every word with a 'token' (like - another way of referring to that particular word).
The code is translated into a list of tokens, and then this is given to the parser.

How does the translator figure out when to add in tokens?
Well, each character is looked at individually, and the translator has a list of reserved words for that language. It goes through each character, and when it comes across a string of characters that matches one of the reserved words (which are called 'lexemes'), it replaces that word with a 'token'. If the characters arent recognised it chucks up an error.
The whole code is done like this (I think it does the whole code anyway).

Parsed: (My understanding of 'parsing' is searching something, like a string, looking for characters/patterns of characters...)
So I would say that what you might mean is that parsing happens in the Syntactical Analysis bit of translation, where the

'Parser' searches the code to see if everything is 'in order'... Like, whether tokens are syntactically in order... So say that token 1A could only be before token 2F, and the code didnt have 1A before 2F, then a syntax error would be given.
So 'parsed tokens' would be tokens that are in their correct syntactical arrangement (according to the EBNF rules of the specific language)

Hope that helps for that... You should also look at things like type-checking and then how code is actually produced, which both happen after the code has been analysed as above.

OK - the easier questions...
Relational relates to something else, so like your equalities situations, so >,<, <= and >= are relational operators
Arithmetic is math stuff, so things like +, -, *, /
Assignment is = (but if it asks for this in BNF then it's ::=)... Think of assigning something a value, which you do with something = something else... (like, meAge = x )
Others: Logical/Boolean operators: things like AND/OR/NOT
And things like string operators but i dont know whether you need them...

Sorting Letter Arrays: (Depending on routine used)
This is how a computer does it:
All of the sorts we deal with compare each item individually against another item, and they pass over the list a number of times in order to compare each item with each other item. (I'm not going to worry about actual routines here... there are other threads with that stuff in it.)
But with letters, when it comes across a letter, the computer converts the letter to its ascii equivalent (or whatever encoding you are using, but dont worry about that either) and then compares based on this ascii character.

Some ascii character rules for sorting letters:
(What text book do you have? There is an ascii chart on page 336 in Davis' book)
What you will see is that Capital letters are lower than lower case, so capital 'A' is sorted before 'a'.
If the first character in each string is the same, then the next character is looked at, and so on until they can be discriminated...

AB BA ZA ZB AR BD WR DS FG and Im meant to do a selection sort on it in descending order and its not working


I ended up getting AB BA FG LK AR BD DS WR 2A 2B
You have a couple not included in your answer... Like LK.
Do it ascending first, thats easier to recognise:

AB first, as A is lowest ascii value.
AR next, as A is looked at first, then R.
Then BD as B next after A, and so on...
So ascending:
AB,AR,BA,BD,DS,FG,WR,ZA,ZB (and the reverse for descending...)

Winston answered your word size question I think, so I wont do that one.

Damn computer keeps adding extra lines in this message...
 
Last edited:

saves.the.day

Member
Joined
Oct 29, 2003
Messages
233
Location
Castle Hill
Gender
Undisclosed
HSC
2003
What are tokens
Part of lexical analysis where each character or group of characters are given an element. e.g. say you have code
total = 1 + 1
The word 'total' will be given the token of VARIABLE, the characters '+' and '=' will be given token OPERATOR while the '1' will be given the token INTEGER.

whats the difference between parsed tokens and tokens
You already know what a token is now. A parsed token is simply a token put into a more logical order for the computer. It is 'parsed' when the computer orders the tokens in say a parse tree, giving it a more logical arrangement.
 

ezzy85

hmm...yeah.....
Joined
Nov 4, 2002
Messages
556
Gender
Undisclosed
HSC
N/A
what about operators and operands? ive seen that in a few trial papers and always get it wrong.
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Originally posted by ezzy85
what about operators and operands? ive seen that in a few trial papers and always get it wrong.

i know that a operand is comprised of the Opcode and the Memory address, the operand if i'm not wrong is the data that's fetched in the fetch-execute cycle.
 

-X-

Member
Joined
Aug 10, 2003
Messages
481
Gender
Undisclosed
HSC
N/A
An operator is the name of an action taken on something i.e. "+" or "*".

An operand is an item who has an action being performed on it. ie a constant or variable.

something like that....
 

chris42

Member
Joined
Oct 4, 2003
Messages
649
Location
Sydney
Gender
Male
HSC
2004
Thanks for that, do you expect them to be putting a question about tokens in the HSC, the only reason i asked it was I got it out this year's catholic paper, but have never heard about it before.
 

ezzy85

hmm...yeah.....
Joined
Nov 4, 2002
Messages
556
Gender
Undisclosed
HSC
N/A
check th syllabus. if its there, expect the worst. anythings possible
 

chris42

Member
Joined
Oct 4, 2003
Messages
649
Location
Sydney
Gender
Male
HSC
2004
I can't seem to see it, my teacher said it was part of the 3 unit course, so I'm assuming its not in there. But now I know it just incase :)
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Originally posted by chris42
I can't seem to see it, my teacher said it was part of the 3 unit course, so I'm assuming its not in there. But now I know it just incase :)

well u see the token and token parsin level is done in the lexical anaylsis, and this is a prorcess in the compilation of code, so if u check the sylllabus it may very well be in it under compilation.

what my guess will be no thorough explanation will be required more so a brief explanation of it and wat stage is the tokens assigned and parsed.
 

chris42

Member
Joined
Oct 4, 2003
Messages
649
Location
Sydney
Gender
Male
HSC
2004
Originally posted by Winston
what my guess will be no thorough explanation will be required more so a brief explanation of it and wat stage is the tokens assigned and parsed.
Yup that sounds good, I'm just glad I found out what tokens were before the exam. :p
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top