update
This commit is contained in:
parent
4a5083f5cf
commit
e9fd953273
|
@ -23,6 +23,10 @@ So i tried to write a new interpreter to help them checking syntax error and eve
|
|||
I wrote the lexer, parser and runtime(nasal virtual machine/ast-runtime virtual machine) to help checking errors.
|
||||
|
||||
They found it easier for them to check errors before copying nasal-codes in nasal-console in Flightgear to test.
|
||||
|
||||
# How to Compile
|
||||
|
||||
> g++ -std=c++11 main.cpp -o main.exe
|
||||
|
||||
# Lexical Analysis
|
||||
|
||||
|
|
20
main.cpp
20
main.cpp
|
@ -2,7 +2,7 @@
|
|||
|
||||
nasal_lexer lexer;
|
||||
nasal_parse parse;
|
||||
nasal_import preprocessor;
|
||||
nasal_import import;
|
||||
nasal_codegen code_generator;
|
||||
std::string inputfile="null";
|
||||
nasal_runtime runtime;
|
||||
|
@ -96,13 +96,13 @@ void runtime_start()
|
|||
die("parse",inputfile);
|
||||
return;
|
||||
}
|
||||
preprocessor.preprocessing(parse.get_root());
|
||||
if(preprocessor.get_error())
|
||||
import.link(parse.get_root());
|
||||
if(import.get_error())
|
||||
{
|
||||
die("import",inputfile);
|
||||
return;
|
||||
}
|
||||
runtime.set_root(preprocessor.get_root());
|
||||
runtime.set_root(import.get_root());
|
||||
runtime.run();
|
||||
return;
|
||||
}
|
||||
|
@ -123,14 +123,14 @@ void codegen_start()
|
|||
die("parse",inputfile);
|
||||
return;
|
||||
}
|
||||
preprocessor.preprocessing(parse.get_root());
|
||||
if(preprocessor.get_error())
|
||||
import.link(parse.get_root());
|
||||
if(import.get_error())
|
||||
{
|
||||
die("import",inputfile);
|
||||
return;
|
||||
}
|
||||
runtime.set_root(preprocessor.get_root());
|
||||
code_generator.output_exec(inputfile+".naexec",preprocessor.get_root());
|
||||
runtime.set_root(import.get_root());
|
||||
code_generator.output_exec(inputfile+".naexec",import.get_root());
|
||||
if(code_generator.get_error())
|
||||
{
|
||||
die("code",inputfile);
|
||||
|
@ -141,13 +141,13 @@ void codegen_start()
|
|||
|
||||
void execution_start()
|
||||
{
|
||||
code_generator.load_exec(inputfile,preprocessor.get_root());
|
||||
code_generator.load_exec(inputfile,import.get_root());
|
||||
if(code_generator.get_error())
|
||||
{
|
||||
die("code",inputfile);
|
||||
return;
|
||||
}
|
||||
runtime.set_root(preprocessor.get_root());
|
||||
runtime.set_root(import.get_root());
|
||||
runtime.run();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -10,11 +10,14 @@ enum op_code
|
|||
op_pushstr,
|
||||
op_newvec,op_newhash,op_newfunc,
|
||||
op_vecappend,op_hashappend,
|
||||
op_para,op_defaultpara,op_dynamicpara,
|
||||
op_unot,op_usub,
|
||||
op_add,op_sub,op_mul,op_div,op_lnk,
|
||||
op_eq,op_neq,op_less,op_leq,op_grt,op_geq,
|
||||
op_pop,
|
||||
op_jmp,op_jmptrue,op_jmpfalse,
|
||||
op_gccall,op_gccallvec,op_gccallhash,op_gccallfunc,op_builtincall,op_slice,
|
||||
op_gccall,op_gccallvec,op_gccallhash,op_gccallfunc,op_builtincall,
|
||||
op_slice,op_slice2,
|
||||
op_memcall,op_memcallvec,op_memcallhash,
|
||||
op_return,
|
||||
op_end
|
||||
|
|
20
nasal_misc.h
20
nasal_misc.h
|
@ -178,26 +178,6 @@ void prt_hex(const int ptr)
|
|||
}
|
||||
else
|
||||
std::cout<<"0x";
|
||||
/*
|
||||
int: 00000000 00000000 00000000 00000000
|
||||
int: 0x00 00 00 00
|
||||
example:
|
||||
a=0x13 57 9b df
|
||||
a=00010011 01010111 10011011 11011111
|
||||
a & 0x00 00 00 0f:
|
||||
00010011 01010111 10011011 11011111
|
||||
and 00000000 00000000 00000000 00001111
|
||||
---------------------------------------
|
||||
00000000 00000000 00000000 00001111
|
||||
a>>=4:
|
||||
00000001 00110101 01111001 10111101
|
||||
a & 0x00 00 00 0f
|
||||
00000001 00110101 01111001 10111101
|
||||
and 00000000 00000000 00000000 00001111
|
||||
---------------------------------------
|
||||
00000000 00000000 00000000 00001101
|
||||
then convert 0~15 to 0~9 a~f
|
||||
*/
|
||||
for(int j=7;j>=0;--j)
|
||||
{
|
||||
int tmp=(tmp_plc & 0x0000000f);
|
||||
|
|
Loading…
Reference in New Issue