TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JASEN BETTS
from: CHRIS CRANFORD
date: 2004-04-17 14:59:48
subject: RE: BISON/Flex

On 4/17/2004 2:29 PM, JASEN BETTS wrote to CHRIS CRANFORD:

-> Hi CHRIS.
-> 
-> 15-Apr-04 01:16:50, CHRIS CRANFORD wrote to ALL
-> 
->  CC> I am trying to implement a BASIC-like language compiler with the
->  CC> caveat that the compiler doesn't actually take source to machine
->  CC> language but to a bytecode type language which an embedded virtual
->  CC> machine would process.
-> 
-> Most (if not all) basic interpreters work that way.
-> (well, they convert keywords to tokens, and labels/structure items to
-> addresses atleast)
->
-> I take it from the above that you are using bison (or somethink like it) to
-> parse the language and it's giving you back a stack full of language and
-> context symbols
->
-> I think one way to do it is to arrage for each closure of an
-> expression/line/block/function etc to cause the compiler to emit the
-> apropriate bytecode, and then at the end (or when you encounter the
-> targets) go back and fill in the addresses of the forwards references.

Ok, lets take a very simple example using a basic-like syntax notation since
that is what I am having to interpret to bytecode.  

// File: Example1.bsc
//
Dim x as Integer = 2
Dim s as String  = "Text"
Print s; " #"; x

The above results in "Test #2" being pushed to the VM's stdout device.

-> am I close?
-> what's the road-block?

The roadblock is understanding how I am suppose to handle variables by 
defining them on the stack and representing their sizes so that when the code 
runs through a VM, the VM knows to:

  Allocate a 4-byte memory space for variable X and assign it value 2.
  Allocate a 5-byte memory space for variable S and assign it "Test\0".

If we were talking about a calculation application like:

  2+3*5

I know for sure that (assuming the stack is just integer based), I would:

  PUSH 3
  PUSH 5
  MULTI
  PUSH 2
  ADD
  
This leaves the top of the stack with a value of 17 assuming normal math 
operations and precedence occurs right.

But it's going from something simple like the math example to the use of 
variables that is killing me.  Something even like:

  Dim x as Integer                   Dim x as Integer = 2
  Dim y as Integer                   Dim y as Integer = 5
  x = 2                    or        x = x + 3 * y
  y = 5
  x = x + 3 * y
  
In both of the examples above, the stack should contain the value 17 for X, 
but it's slightly different because X isn't located at the very top of the
stack any longer, right?  Its moreover SP+offset on the stack?

-> is the design of the byte-code under your control?
-> do you have the byte-code interpreter working?

Yes, the entire system is at my control which means I can create as many or 
any special OPCODEs I need or want, but within reason of course because I 
need my VM to be as blazing fast as possible :-).

I don't think at this point I'm at a place where I can work on getting the 
BYTECODE interpreter to work or coded until I get over the hurdle I'm 
at right now, no?

-> it seems to me you could use flex and bison (generated software) to do most
-> of the work generating the byte-code

Exactly my point and goal.  Its just doing that which keeps hanging me up.

Thanks,
Chris

--- Mail-ennium/32 v2.0-alpha-r12
* Origin: Mail-ennium/32 v2 Beta Coming Soon! (1:379/1200.0)
SEEN-BY: 633/267 270
@PATH: 379/1200 1 396/45 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.