TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: CHRIS CRANFORD
from: Jasen Betts
date: 2004-05-08 08:19:40
subject: RE: Scripting/Basic Compiler/Interpretor

Hi CHRIS.

15-Apr-04 01:23:42, CHRIS CRANFORD wrote to PASCAL SCHMIDT


 CC> On 4/15/2004 1:21 AM, PASCAL SCHMIDT wrote to CHRIS CRANFORD:

 CC> -> Hi CHRIS! :-) -> ->  CC> Can anyone offer some suggestions on
 CC> how you would go about defining ->  CC> your functions,
 CC> keywords/syntax parser and then how to execute it in ->  CC> the
 CC> internal interpretor engine? -> On Unix/Linux: for the parser,
 CC> come up with a decent grammar, then use lex -> (or flex) and yacc
 CC> (or bison) to automatically generate most of the C code -> for the
 CC> parser. You'd also need to define some data structures to hold the
 CC> -> contents of a script, filled out by the parser. -> -> For the
 CC> interpreter, you need to come up with a runtime system, basically
 CC> -> abstractions for all the actions a script can take. So if your
 CC> scripts are -> allowed to declare arrays, you'd need a full memory
 CC> management system for -> that.

 CC> OK, so far I have defined my grammer and have a fully functioning
 CC> parser with BISON/FLEX.  It detects when parse errors occur and
 CC> terminates as it should.

 CC> Now, from what I have read thus far, I need to, as my parser is
 CC> reading the source file(s), need to create a number of stacks that
 CC> hold information like:

 CC> Labels, Symbols, and Constants Commands Values (Integers, Strings
 CC> - ie: Parameters)

 CC> I know this can be done from the BISON grammer file to call C
 CC> functions which populate these things, but I'm unsure of really
 CC> how I should best structure this monster.

make it so that there's a way to convert each piece of grammer can be
converted into your byte code

   a = b + 1

you get somethinh like this from flex

  sybmol["a"]
  equal
  symbol["b"]
  plus
  number[ 1 ]
  end-of-statement

and then bison understands it like this:

  assignment - target: symbol["a"]
             \ value : addition - X: symbol["b"]
                                \ Y: number[ 1 ]

what you do then is have code to emit bytecode for an assigment

eg for an assignment compute the value then store it in the target

so assigmnet will call the addition code

the addition code (thie is still C code) will emit code to something to
load a register with one value then add the second to it...

in this case it'll see symbol["b"] so it'll call the symbol table functions
to get the address for b and and emit bytecode to load the value of
variable b into a register, then it'll look at the second part of the
addition  and see number[ 1 ] - a constant  so it'll emit bytecode to add 1
to that register etc...
 now addition is done so it'll return to its caller (assignment)

the assignment code will look to the target this time, extract the address
for "a" from the symbol table and emit byte code to store the value from
the register there.

 -=> Bye <=-

---
* Origin: Bad karma, yea Way bad karma.. (3:640/1042)
SEEN-BY: 633/267 270
@PATH: 640/1042 531 954 774/605 123/500 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™.