Files
vgstation13/code/modules/scripting/AST/AST Nodes.dm
vageyenaman@gmail.com b5f8eaf8a9 More work done on Telecomms:
▫ Signals can now be rejected by Subspace broadcasters through a specific data[] parameter.
▫ Improved the log browser.
▫ Log browsers and telecommunication monitors no longer require access to use. You do need access to delete logs, however.
▫ Intercoms need power to work. They don't drain power, they just need a constant flow of equipment power. As such, that offline intercom sprite's now finally being put to use.


Scripting language:

▫ Sorry about all the files; they're all necessary! It's important to notice that the basic structure of the scripting language code is not mine; I cannibalized the base structure from some obscure BYOND project. It's pretty well documented, and I'd say easier to browse through than atmos. Here's the basic deal:

A compiler datum manages the relationships between the three main subsystems of a scripting language: the Scanner, the Parser, and the Interpreter. The Scanner splits raw text into token datums that the Parser can read. The Parser transforms the otherwise random bits and strings into ordered AST Trees and nodes for the Interpreter to read. The interpreter actually executes the code and handles scope/functions/code blocks.

git-svn-id: http://tgstation13.googlecode.com/svn/trunk@3193 316c924e-a436-60f5-8080-3fe189b3f50e
2012-02-25 22:51:31 +00:00

139 lines
3.0 KiB
Plaintext

/*
File: AST Nodes
An abstract syntax tree (AST) is a representation of source code in a computer-friendly format. It is composed of nodes,
each of which represents a certain part of the source code. For example, an <IfStatement> node represents an if statement in the
script's source code. Because it is a representation of the source code in memory, it is independent of any specific scripting language.
This allows a script in any language for which a parser exists to be run by the interpreter.
The AST is produced by an <n_Parser> object. It consists of a <GlobalBlock> with an arbitrary amount of statements. These statements are
run in order by an <n_Interpreter> object. A statement may in turn run another block (such as an if statement might if its condition is
met).
Articles:
- <http://en.wikipedia.org/wiki/Abstract_syntax_tree>
*/
var
const
/*
Constants: Operator Precedence
OOP_OR - Logical or
OOP_AND - Logical and
OOP_BIT - Bitwise operations
OOP_EQUAL - Equality checks
OOP_COMPARE - Greater than, less then, etc
OOP_ADD - Addition and subtraction
OOP_MULTIPLY - Multiplication and division
OOP_POW - Exponents
OOP_UNARY - Unary Operators
OOP_GROUP - Parentheses
*/
OOP_OR = 1 //||
OOP_AND = OOP_OR + 1 //&&
OOP_BIT = OOP_AND + 1 //&, |
OOP_EQUAL = OOP_BIT + 1 //==, !=
OOP_COMPARE = OOP_EQUAL + 1 //>, <, >=, <=
OOP_ADD = OOP_COMPARE + 1 //+, -
OOP_MULTIPLY= OOP_ADD + 1 //*, /, %
OOP_POW = OOP_MULTIPLY+ 1 //^
OOP_UNARY = OOP_POW + 1 //!
OOP_GROUP = OOP_UNARY + 1 //()
/*
Class: node
*/
/node
proc
ToString()
return "[src.type]"
/*
Class: identifier
*/
/node/identifier
var
id_name
New(id)
.=..()
src.id_name=id
ToString()
return id_name
/*
Class: expression
*/
/node/expression
/*
Class: operator
See <Binary Operators> and <Unary Operators> for subtypes.
*/
/node/expression/operator
var
node/expression/exp
tmp
name
precedence
New()
.=..()
if(!src.name) src.name="[src.type]"
ToString()
return "operator: [name]"
/*
Class: FunctionCall
*/
/node/expression/FunctionCall
//Function calls can also be expressions or statements.
var
func_name
node/identifier/object
list/parameters=new
/*
Class: literal
*/
/node/expression/value/literal
var
value
New(value)
.=..()
src.value=value
ToString()
return src.value
/*
Class: variable
*/
/node/expression/value/variable
var
node
object //Either a node/identifier or another node/expression/value/variable which points to the object
node/identifier
id
New(ident)
.=..()
id=ident
if(istext(id))id=new(id)
ToString()
return src.id.ToString()
/*
Class: reference
*/
/node/expression/value/reference
var
datum/value
New(value)
.=..()
src.value=value
ToString()
return "ref: [src.value] ([src.value.type])"