By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,245 Members | 2,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,245 IT Pros & Developers. It's quick & easy.

Writing a bytecode interpreter (for TeX dvi files)

P: n/a
I'm writing some routines for handling dvi files.
In case you didn't know, these are TeX's typeset output.

These are binary files containing opcodes.
I wish to write one or more dvi opcode interpreters.

Are there any tools or good examples to follow for
writing a bytecode interpreter?

I am already aware of opcode.py and other modules in
Python Language Services, in the Library Reference.

Thanks.

--
Jonathan
http://texd.sourceforge.net

Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Aloha,

Jonathan Fine wrote:
I'm writing some routines for handling dvi files.
In case you didn't know, these are TeX's typeset output.
These are binary files containing opcodes.
I wish to write one or more dvi opcode interpreters.
Are there any tools or good examples to follow for
writing a bytecode interpreter?


As far as i know, dvi is a very straight forward format, commands
followed by parameters, no conditionals, no loops.
For similar designs i used something like the following approach:

s = file('a.dvi','r').read() # read complete file to string

while s:
command = ord(s[0])

if command < 128:
#typeset command
s = s[1:]
elif command = 139:
#bop command
param = s[:40]
#interpret param
c = struct.unpack('D',param[:3])
#consume s
s = s[41:]
else:
#undefined command
s = s[1:]

You can work directly on strings, or convert to a list. If you don't
want long if/elif lists, you can use a dict as a dispatcher (python
cookbook has an example?). For most of the commands you can use
a lookup table for the parameter list length.
TeX §591 claims, that dvi is stricly interpretable from front to end.
The description in Tex§585++ can be transcripted to struct definitions
easily.

Wishing a happy day
LOBI

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.