Last active
October 10, 2017 01:17
-
-
Save PedroHLC/0b5d3baefeb667304d5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!ruby | |
#THIS SHIT MIGHT USE A LOT OF RAM, BUT THIS IS RUBY, RIGHT? | |
$LANGUAGE_SEPATOR_VER = "0.0.1" | |
class Program_Project | |
@files = nil | |
@rules = nil | |
@symbols = nil #Universal | |
@output = nil | |
attr_reader :rules, :symbols, :output | |
def initialize(output, src_files, rules) | |
@output = output | |
@files = [] | |
@symbols = [] | |
@rules = rules | |
src_files.each{|src_fln| | |
@files << Program_File.new(src_fln, self) | |
} | |
@files.each{|f| | |
f.begin | |
} | |
end | |
end | |
class Program_File | |
@file = nil | |
@project = nil | |
@symbols = nil #Global | |
@code = nil | |
attr_reader :file, :project, :symbols | |
def initialize(filename, parent) | |
@file = File.new(filename).read | |
@project = parent | |
@symbols = [] | |
end | |
def begin | |
@project.rules.begin_file(self) | |
@code = Code_Level.new(self, 0) | |
@code.interpret | |
end | |
end | |
class Code_Level | |
@pfile = nil | |
@codebegin = nil | |
@codeend = nil | |
@symbols = nil #Local | |
@subcodes = nil | |
@rules = nil | |
@project = nil | |
@output = nil | |
def initialize (pfile, codebegin) | |
@symbols = [] | |
@subcodes = [] | |
@pfile = pfile | |
@codebegin = codebegin | |
@codeend = -1 | |
@project = @pfile.project | |
@rules = @project.rules | |
@output = @project.output | |
end | |
def interpret | |
@output.write(@rules::TREE) | |
point = 0 | |
loop do | |
first_token = read_ftoken (point) | |
point += first_token.size | |
puts first_token | |
break if first_token == '' | |
end | |
end | |
def read_ftoken(point) | |
ftoken = '' | |
@pfile.file[point..@pfile.file.size]. | |
each_char do |c| | |
if @rules.out_of_ftoken?(c) | |
break | |
else | |
ftoken += c | |
end | |
end | |
return ftoken | |
end | |
end | |
class Code_Instruction | |
@type = nil | |
@args = nil | |
@rules = nil | |
def initialize(rules, type, *args) | |
@rules = rules | |
@type = @rules::Instruct_type[type] | |
@args = args | |
end | |
def dump | |
return Marshal.dump(@type) + Marshal.dump(@args) | |
end | |
end | |
class Program_Output | |
def initialize (filename) | |
@file = File.new(filename, 'wb') | |
@file.write("LSP"+Marshal.dump($LANGUAGE_SEPATOR_VER)) | |
end | |
def write(instruction) | |
@file.write Marshal.dump(instruction.dump) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!ruby | |
load 'language_separator_kit.rb' | |
def enumize (array) #my fake enum | |
hash = {} | |
i = 0 | |
array.each{|key| | |
hash[key] = i | |
i += 1 | |
} | |
return hash | |
end | |
def is_in?(key, *comparable) | |
comparable.each do |item| | |
return true if item == key | |
end | |
return false | |
end | |
module NeoL_Rules | |
Instruct_type = enumize [ | |
:tree, | |
:precall, | |
:call, | |
:create, | |
:set, | |
:type, | |
:const_value, | |
:symbol, | |
:symbol_attr, | |
:code | |
] | |
Symbol_type = enumize [ | |
:neighboor, | |
:system, | |
:linked | |
] | |
Const_type = enumize [ | |
:string, | |
:character, | |
:number, | |
:code | |
] | |
Calls_type = enumize [ | |
:create_symbol | |
"source", | |
"debug" | |
] | |
TREE = Code_Instruction.new(self, :tree) | |
CODE = Code_Instruction.new(self, :code) | |
ALPHABET = ['A'..'Z','a'..'z'] | |
class << self | |
def begin_file(pfile) | |
end | |
def begin_subcode(pcode) | |
end | |
def begin_instruct(pins) | |
end | |
def out_of_ftoken?(c) | |
return !( | |
is_in?(c, *ALPHABET) || | |
c == '_' || | |
c == '/' | |
) | |
end | |
end | |
end | |
##main | |
$output = Program_Output.new("test.neos") | |
Program_Project.new($output, ["test.neoc"], NeoL_Rules) | |
##end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "neol.helloworld" | |
func puts | |
/*Just a comment is okay*/ | |
end | |
func main | |
str message = "Hello World!" | |
debug message | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment