Qbasicnews.com
January 21, 2022, 01:43:55 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 2 3 [4]
  Print  
Author Topic: Computer Science and Other Items  (Read 11920 times)
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #45 on: February 12, 2004, 06:50:32 AM »

It depends on the compiler being used.

As Loose said "You could output asm code inline in the parser, or have the parser generate an intermediate set of opcodes that are later translated into asm"
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #46 on: February 12, 2004, 04:06:47 PM »

Too complex.

Much easier:

1) figure out what kind of structures in your language can be broken down into other structures. (with a greater length of course)
In QB, such structures are: FOR... NEXT and DO...LOOP to label... IF.. GOTO, etc.

2) Break down more complex structures into most basic structures.

3) Break down into non-your-language structures. (in QB (without graphics/input/output/etc.), fortunately, all you need to do is to break everything down into variables, line numbers, and mathematical expressions. (ie: a = b))

Anywayz, it's all a lot more complex than it sounds.

Example: variable names/functions/etc. There is a certain degree of ambiguity that arises from something possibly being a variable or a function or an array.. All of this needs iterative passes through the code to generate enough information. You can't parse anything more complex than machine code with one pass.
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #47 on: February 12, 2004, 04:12:46 PM »

Aga, thats way too simple Wink. If someone has the time look at the GCC compiler =P.
Logged
LooseCaboose
I hold this place together
*****
Posts: 981



« Reply #48 on: February 12, 2004, 10:03:38 PM »

Quote from: "Agamemnus"

You can't parse anything more complex than machine code with one pass.


Heres an implementation of a one-pass C compiler: http://www-users.cs.umn.edu/~joshi/compilers/Compiler_page.htm

Quote from: "Agamemnus"

Example: variable names/functions/etc. There is a certain degree of ambiguity that arises from something possibly being a variable or a function or an array


This is why you use BNF grammars to define a language, because the ambiguity can be removed, at worst you may require some lookahead, which can still be done with a one pass compiler. Functions and subroutines must be declared at the beginning of a module, so they can be looked up in a table when encountered. It is usally possible to tell what a name refers to by the surrounding code.
Logged

esus saves.... Passes to Moses, shoots, he scores!
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #49 on: February 12, 2004, 10:51:06 PM »

Is it just me or is all the sample source written so that functions that require other functions go in later?

 :roll:
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
LooseCaboose
I hold this place together
*****
Posts: 981



« Reply #50 on: February 12, 2004, 11:27:56 PM »

Quote from: "Agamemnus"

Is it just me or is all the sample source written so that functions that require other functions go in later?


Thats because that haven't been explicity defined, this is true for any C compiler.
Code:

int main() {
  func();
}

void func() {
  /* Blah */
}

Is wrong, because func() hasn't been defined prior to being called, one solution is the following:
Code:

void func() {
  /* Blah */
}

int main() {
  func();
}

When func() is called, it has already been defined. A better solution is this:
Code:

void func();

int main() {
  func();
}

void func() {
  /* Blah */
}


Either of the last two can be compiled using a one-pass compiler and look up tables.
Logged

esus saves.... Passes to Moses, shoots, he scores!
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #51 on: February 12, 2004, 11:58:16 PM »

recursive calls...
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Pages: 1 2 3 [4]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!