diff --git a/NASAL语言教程-完整版.pdf b/NASAL语言教程-完整版.pdf new file mode 100644 index 0000000..e80601e Binary files /dev/null and b/NASAL语言教程-完整版.pdf differ diff --git a/nasal_hash.h b/nasal_hash.h new file mode 100644 index 0000000..0413c23 --- /dev/null +++ b/nasal_hash.h @@ -0,0 +1,94 @@ +#ifndef __NASAL_HASH_H__ +#define __NASAL_HASH_H__ + +#include +#include +namespace nasal +{ + + +struct HashUnit +{ + std::string VarName; + std::string Type; + void *data; + HashUnit* next; +}; + +class NasalHash +{ + private: + HashUnit *head; + public: + NasalHash() + { + head=new HashUnit; + head->next=NULL; + } + ~NasalHash() + { + HashUnit *temp=head; + while(temp->next) + { + head=temp->next; + delete temp; + temp=head; + } + delete temp; + } + void PrintHash() + { + HashUnit *temp=head; + std::cout<<"{ "; + while(temp->next) + { + temp=temp->next; + std::cout<VarName<<":"; + if(temp->next) + { + if(temp->Type=="int") + std::cout<<*((int *)temp->data)<<", "; + if(temp->Type=="float") + std::cout<<*((float *)temp->data)<<", "; + if(temp->Type=="double") + std::cout<<*((double *)temp->data)<<", "; + if(temp->Type=="char") + std::cout<<"\""<<*((char *)temp->data)<<"\", "; + if(temp->Type=="long long int") + std::cout<<*((long long int *)temp->data)<<", "; + } + else + { + if(temp->Type=="int") + std::cout<<*((int *)temp->data); + if(temp->Type=="float") + std::cout<<*((float *)temp->data); + if(temp->Type=="double") + std::cout<<*((double *)temp->data); + if(temp->Type=="char") + std::cout<<"\""<<*((char *)temp->data)<<"\""; + if(temp->Type=="long long int") + std::cout<<*((long long int *)temp->data); + } + } + std::cout<<"}"; + } + void Append(const char *VariaName,void *AppendData,const char *TypeName) + { + HashUnit *temp=head; + while(temp->next) + { + temp=temp->next; + } + HashUnit *NewHashMember=new HashUnit; + temp->next=NewHashMember; + NewHashMember->data=AppendData; + NewHashMember->VarName=VariaName; + NewHashMember->Type=TypeName; + NewHashMember->next=NULL; + } +}; + +} + +#endif diff --git a/nasal_list.h b/nasal_list.h new file mode 100644 index 0000000..d6b6dbd --- /dev/null +++ b/nasal_list.h @@ -0,0 +1,91 @@ +#ifndef __NASAL_LIST_H__ +#define __NASAL_LIST_H__ + +#include +#include +namespace nasal +{ + + +struct ListUnit +{ + std::string Type; + void *data; + ListUnit* next; +}; + +class NasalList +{ + private: + ListUnit *head; + public: + NasalList() + { + head=new ListUnit; + head->next=NULL; + } + ~NasalList() + { + ListUnit *temp=head; + while(temp->next) + { + head=temp->next; + delete temp; + temp=head; + } + delete temp; + } + void PrintList() + { + ListUnit *temp=head; + std::cout<<"[ "; + while(temp->next) + { + temp=temp->next; + if(temp->next) + { + if(temp->Type=="int") + std::cout<<*((int *)temp->data)<<", "; + if(temp->Type=="float") + std::cout<<*((float *)temp->data)<<", "; + if(temp->Type=="double") + std::cout<<*((double *)temp->data)<<", "; + if(temp->Type=="char") + std::cout<<"\""<<*((char *)temp->data)<<"\", "; + if(temp->Type=="long long int") + std::cout<<*((long long int *)temp->data)<<", "; + } + else + { + if(temp->Type=="int") + std::cout<<*((int *)temp->data); + if(temp->Type=="float") + std::cout<<*((float *)temp->data); + if(temp->Type=="double") + std::cout<<*((double *)temp->data); + if(temp->Type=="char") + std::cout<<"\""<<*((char *)temp->data)<<"\""; + if(temp->Type=="long long int") + std::cout<<*((long long int *)temp->data); + } + } + std::cout<<"]"; + } + void Append(void *AppendData,const char *TypeName) + { + ListUnit *temp=head; + while(temp->next) + { + temp=temp->next; + } + ListUnit *NewListMember=new ListUnit; + temp->next=NewListMember; + NewListMember->data=AppendData; + NewListMember->Type=TypeName; + NewListMember->next=NULL; + } +}; + +} + +#endif diff --git a/nasal_print.h b/nasal_print.h new file mode 100644 index 0000000..4b4a8da --- /dev/null +++ b/nasal_print.h @@ -0,0 +1,135 @@ +#ifndef __NASAL_PRINT_H__ +#define __NASAL_PRINT_H__ + +#include +#include +#include "nasal_hash.h" +#include "nasal_list.h" +namespace nasal +{ + +void PrintVar(int Var) +{ + std::cout<=(int)PrintInfo.length()) + { + //error occurred + std::cout<=strlen(PrintInfo)) + { + //error occurred + std::cout<