[706] in Coldmud discussion meeting

root meeting help first previous next last

spec for parse tree info

daemon@ATHENA.MIT.EDU (Sat Mar 11 20:49:23 1995 )

From: crag@serial.MIT.EDU (Robert de Forest )
To: coldstuff@MIT.EDU
Date: Sat, 11 Mar 1995 19:42:44 -0600 (CST)

I spent a few hours in grammar.y, codegen.c and code_prv.h and came up with
 the following:

Program:
#[['flags, [list of flag ids]], // Only known flag right now is
                                // 'dissallow_overrides. Default [].
  ['args, [list of arg names]], // Default [] Optional args speced as...
  ['vars, [list of var names]], // Arg and var names are strings, default []
  ['body, [list of statements]]
]

Statement:
[type, line number, info] where info depends on type as follows:
'comment	"comment text"
'noop
'expr		expression
'compound	statements
'if | 'if_else	condition expression, true statement, false statement
'for_range	"var name", lower expression, upper expression, body statement
'for_list	"var name", list expression, body statement
'while		test expression, body statement
'break		
'continue
'return?_expr	optional value expression
'switch		expresion, [case list]
'catch		[error list], body statement, handler statement
'fork		time expression, body statement

Expression:
[type, line number, info] where info depends on type as follows:
'integer | 'string | 'dbref | 'symbol | 'error
'obj_name	"name"
'var		"name"
'list		expressions
'dict		args - see below
'buffer		expressions
'assign		"name", value expression
'function	"name", arg list
'pass		arg list
'expr		expression
'arg_list	[arg expressions]
'function	"name", [args]
'self_expr_message	message expression, [args]
'message	to expression, "message name", [args]
'expr_message	to expression, message expression, [args]
'frob		class expression, rep expression
'index		list expression, offset expression
'unary		opcode id, expression
'binary		opcode id, left expression, right expression
'and | 'or	left expression, right expression (should be combined with above?)
'cond		cond expression, true expression, false expression
'range		lower expression, upper expression
'critical	expression
'propagate	expression
'splice		list expression

Case entry:
[line number, [value expresions], [statements]]

Example:

@Program .example
 arg foo, bar, [baz];
 var x, y, z;

 x = foo;
 y = z = [@baz, 1];
 while (x)
   if (y)
     return z;
   else
     x = obj_var_1.method(y) || .(z)(y);
 return builtin_func();
.

Output of decompile_coldc (line breaks added for clarity)
#[['flags, []],
  ['args, ["foo", "bar", ["baz"]]],
  ['vars, ["x", "y", "z"]],
  ['body, [
    ['expr, 4, ['assign, 4, ["x", 4, ['var, 4, "foo"]]]]
    ['expr, 5, ['expr, 5, ['assign, 5, ['list, 5, ['splice, 5, ['var, 5, "baz"]], ['integer, 5, 1]]]]]
    ['while, 6, ['var, 6, "x"],
      ['if_else, 7, ['var, 7, "y"],
        ['return_expr, 8, ['var, 8, "z"]]
        ['expr, 10, ['assign, 10, "x", ['or, 10, ['message, 10, ['var, 10, "obj_var_1"], "method", ['var, 10, "y"]]], ['self_expr_message, 10, ['var, 10, "z"], ['var, 10, "y"]]]]]]
    ['return, 11, ['function, "builtin_func"]]
  ]
]

WHEW!

From making the example by hand I came to the conclusion that including line
 numbers may be a bit much. It's in the structures that store the parse tree,
 but in a decompiled program it only changes per statement. It's also only used
 to report errors as far as I can tell.

There are three ways to deal with line number info (that I can think of). We
 can make it optional and include the rest of the info inside a list
 (type, optional line, [info list]), we can require them and not enclose the
 rest of the info in a list, or we can discard them entirely.

Since I don't know EXACTLY how the line number info is used I won't make any
 decisions yet. My tendancy is to make them optional and include info in a
 list. Unsupplied line numbers would be calculated by adding one for each new
 statement.

Well, send any comments to the list. I won't start implementing until Brandon
 releases another ColdX version.

Crag / Robert de Forest