alternative
meaning_indentation = false;
newline_is_whitespace = true;
# __specials__ contains a lot of useful viex'
terminals
name __id_viex__
integer __int_viex__
real __real_viex__
str __cstring_viex__
chr __cshar_viex__
arrow __arrow_viex__ # you can write like this: v"-\>"
@unpack __specials__
end
# preprocess code
preprocess
source = system("path\\to\\H4sHz_s\\preproc" + __infile__).pipe.stdout.read()
end
# parsing some structures
parse format "format" name begin
put "format " + %1 + "\n"
return $?
end
parse func "fn" name "(" (def (comma def)*)? ")" (arrow type)? body begin
put __cdecl__(name = %1, args_num = args_count(%3))
return $?
end
parse body "{" line* "}" begin
put "\n\t" <> %1 + "\n"
return $?
end
parse def name ":" type begin
put get_size(type) + name + ":\n"
return $?
end
parse var def equal expr begin
put %0 + "\t" + %2 + "\n"
return $?
end
parse type name ("[" type? "]")? begin
return __node__
end
parse line ret | liv | def_var | forever | each |
while | clike | expr | comment begin
put %0
return $?
end
parse forever "for" body begin
idx = random_integer()
put "__L" + idx + ":\n\t" + %1 + "jmp __L" + idx + "\n"
return $?
end
parse each "for" def "in" range body begin
idx = random_integer()
put "push word " + %3 + "\n__L" + idx +
":\n\tcall __range__.$iter\n\ttest eax, eax\n\tjz __E" + idx +
"\n\t" + %4 + "__E" + idx + ":\n"
return $?
end
parse while "for" expr body begin
idx = random_integer()
put "__L" + idx + ":\n\t" + %1 + "\tjz __E" +
idx + "\n\t" + %2 + "__E" + idx + ":\n"
return $?
end
parse clike "for" var semi ";" expr ";" line body begin
idx = random_integer()
put %1 + "\n__L" + idx + ":\n\t" + %4 + "\tjz __E" + idx +
"\n\t" + %7 + "\n\n\t" + %6 + "__E" + idx + "\n"
return $?
end
parse leave "leave" begin
put __cdecl_end__(rvalue = null)
return __node__
end
parse call name "(" (expr (comma expr)* )? ")" begin
put __cdecl_call__(args = args_list(%2), name = %0)
return $?
end
parse useas expr "as" type begin
return %0
end
parse cast expr "to" type begin
return %0
end
parse ret "return" expr
put __cdecl__end__(rvalue = %1)
return __node__
end
format = ""
funcs = []
constants = []
locals = []
globals = []
generate begin
return format + "\n" + funcs + "\n" +
constants + "\n" + locals + "\n" + globals
compile = "fasm " + __outfile__ + " " + __exefile__
переделал, теперь это полноценный генератор компиляторов и интерпретаторов
Что за ересь?
domain-specific language, вроде это так называется
а теперь попробуй llvm
фии, не буду
Обсуждают сегодня