mighty

The mighty programming language, compiler and tools (WIP)
Log | Files | Refs

ast.lua (780B)



local AST = {}

function AST:program(body)
	return {
		kind = "program",
		body = body,
	}
end

function AST:use(lib)
	return {
		kind = "use",
		lib = lib,
	}
end

function AST:postfix(op, operand)
	return {
		op = op,
		operand = operand,
		is_postfix = true,
	}
end

function AST:unary(op, operand)
	return {
		op = op,
		operand = operand,
		is_postfix = false,
	}
end

function AST:binary(op, lhs, rhs)
	return {
		op = op,
		lhs = lhs,
		rhs = rhs,
	}
end

-- note the name/callee etc. usually carries the token so we have file/line/col
-- access via lexeme
function AST:call(callee, args)
	return { callee = callee, args = args }
end

function AST:func(name, params, ret, body)
	return {
		kind = "func",
		name = name,
		params = params,
		body = body,
	}
end

return AST