[173] | 1 | #include <jenga/include/smoothie/LexicalAnalysis.h>
|
---|
| 2 |
|
---|
| 3 | #include <windows.h>
|
---|
| 4 |
|
---|
| 5 | bool IsVariableTopChar(char c){
|
---|
| 6 | if((c>='A'&&c<='Z')||(c>='a'&&c<='z')||c=='_')
|
---|
| 7 | {
|
---|
| 8 | return true;
|
---|
| 9 | }
|
---|
| 10 | return false;
|
---|
| 11 | }
|
---|
| 12 | bool IsVariableChar(char c){
|
---|
| 13 | if((c>='A'&&c<='Z')||(c>='a'&&c<='z')||(c>='0'&&c<='9')||
|
---|
| 14 | c=='%'||c=='!'||c=='#'||c=='$'||
|
---|
| 15 | c=='_'||c=='.')
|
---|
| 16 | {
|
---|
| 17 | return true;
|
---|
| 18 | }
|
---|
| 19 | return false;
|
---|
| 20 | }
|
---|
| 21 | bool IsBlank(char c){
|
---|
| 22 | if(c==' '||c=='\t') return 1;
|
---|
| 23 | return 0;
|
---|
| 24 | }
|
---|
| 25 | int GetOneParameter(const char *Parameter,int pos,char *retAns){
|
---|
| 26 | int i,i2,i3,IsStr;
|
---|
| 27 | for(i=pos,i2=0,IsStr=0;;i++,i2++){
|
---|
| 28 | if(Parameter[i]=='\"') IsStr^=1;
|
---|
| 29 | else if(Parameter[i]=='('&&IsStr==0){
|
---|
| 30 | i3=GetStringInPare(retAns+i2,Parameter+i);
|
---|
| 31 | i+=i3-1;
|
---|
| 32 | i2+=i3-1;
|
---|
| 33 | continue;
|
---|
| 34 | }
|
---|
| 35 | else if(Parameter[i]=='['&&IsStr==0){
|
---|
| 36 | i3=GetStringInBracket(retAns+i2,Parameter+i);
|
---|
| 37 | i+=i3-1;
|
---|
| 38 | i2+=i3-1;
|
---|
| 39 | continue;
|
---|
| 40 | }
|
---|
| 41 | else if(Parameter[i]==','&&IsStr==0){
|
---|
| 42 | retAns[i2]=0;
|
---|
| 43 | i++;
|
---|
| 44 | break;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | if(IsCommandDelimitation(Parameter[i])&&IsStr==0
|
---|
| 48 | || Parameter[i] == ')' && IsStr == 0 ){
|
---|
| 49 | retAns[i2]=0;
|
---|
| 50 | break;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | retAns[i2]=Parameter[i];
|
---|
| 54 | }
|
---|
| 55 | return i;
|
---|
| 56 | }
|
---|
| 57 | int JumpOneParameter(char *Parameter,int i){
|
---|
| 58 | int i2,IsStr;
|
---|
| 59 | for(i2=0,IsStr=0;;i++,i2++){
|
---|
| 60 | if(Parameter[i]=='\"') IsStr^=1;
|
---|
| 61 | else if(Parameter[i]=='('&&IsStr==0){
|
---|
| 62 | i=JumpStringInPare(Parameter,i+1);
|
---|
| 63 | continue;
|
---|
| 64 | }
|
---|
| 65 | else if(Parameter[i]=='['&&IsStr==0){
|
---|
| 66 | i=JumpStringInBracket(Parameter,i+1);
|
---|
| 67 | continue;
|
---|
| 68 | }
|
---|
| 69 | else if(Parameter[i]==','&&IsStr==0){
|
---|
| 70 | i++;
|
---|
| 71 | break;
|
---|
| 72 | }
|
---|
| 73 | if(IsCommandDelimitation(Parameter[i])) break;
|
---|
| 74 | }
|
---|
| 75 | return i;
|
---|
| 76 | }
|
---|
| 77 | int GetStringInQuotation(char *buffer,char *ReadBuffer){
|
---|
| 78 | int i;
|
---|
| 79 |
|
---|
| 80 | if(ReadBuffer[0]=='\"'){
|
---|
| 81 | buffer[0]=ReadBuffer[0];
|
---|
| 82 | i=1;
|
---|
| 83 | }
|
---|
| 84 | else i=0;
|
---|
| 85 |
|
---|
| 86 | for(;;i++){
|
---|
| 87 | buffer[i]=ReadBuffer[i];
|
---|
| 88 | if(IsDBCSLeadByte(ReadBuffer[i])){
|
---|
| 89 | i++;
|
---|
| 90 | buffer[i]=ReadBuffer[i];
|
---|
| 91 | continue;
|
---|
| 92 | }
|
---|
| 93 | if(ReadBuffer[i]=='\"'){
|
---|
| 94 | i++;
|
---|
| 95 | buffer[i]=0;
|
---|
| 96 | break;
|
---|
| 97 | }
|
---|
| 98 | if(ReadBuffer[i]=='\0') return 0;
|
---|
| 99 | }
|
---|
| 100 | return i;
|
---|
| 101 | }
|
---|
| 102 | int GetStringInPare(char *buffer,const char *ReadBuffer){
|
---|
| 103 | int i,IsStr,PareNum;
|
---|
| 104 | for(i=0,IsStr=0,PareNum=0;;i++){
|
---|
| 105 | buffer[i]=ReadBuffer[i];
|
---|
| 106 | if(IsDBCSLeadByte(ReadBuffer[i])){
|
---|
| 107 | i++;
|
---|
| 108 | buffer[i]=ReadBuffer[i];
|
---|
| 109 | continue;
|
---|
| 110 | }
|
---|
| 111 | if(ReadBuffer[i]=='\"') IsStr^=1;
|
---|
| 112 | else if(ReadBuffer[i]=='('&&IsStr==0) PareNum++;
|
---|
| 113 | else if(ReadBuffer[i]==')'&&IsStr==0){
|
---|
| 114 | PareNum--;
|
---|
| 115 | if(PareNum==0){
|
---|
| 116 | i++;
|
---|
| 117 | buffer[i]=0;
|
---|
| 118 | break;
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 | else if(ReadBuffer[i]=='\0') return 0;
|
---|
| 122 | }
|
---|
| 123 | return i;
|
---|
| 124 | }
|
---|
| 125 | int GetStringInBracket(char *buffer,const char *ReadBuffer){
|
---|
| 126 | int i,IsStr,PareNum;
|
---|
| 127 | for(i=0,IsStr=0,PareNum=0;;i++){
|
---|
| 128 | buffer[i]=ReadBuffer[i];
|
---|
| 129 | if(IsDBCSLeadByte(ReadBuffer[i])){
|
---|
| 130 | i++;
|
---|
| 131 | buffer[i]=ReadBuffer[i];
|
---|
| 132 | continue;
|
---|
| 133 | }
|
---|
| 134 | if(ReadBuffer[i]=='\"') IsStr^=1;
|
---|
| 135 | else if(ReadBuffer[i]=='['&&IsStr==0) PareNum++;
|
---|
| 136 | else if(ReadBuffer[i]==']'&&IsStr==0){
|
---|
| 137 | PareNum--;
|
---|
| 138 | if(PareNum==0){
|
---|
| 139 | i++;
|
---|
| 140 | buffer[i]=0;
|
---|
| 141 | break;
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 | else if(ReadBuffer[i]=='\0') return 0;
|
---|
| 145 | }
|
---|
| 146 | return i;
|
---|
| 147 | }
|
---|
| 148 | int JumpStringInPare(const char *buffer,int pos){
|
---|
| 149 | int PareNum;
|
---|
| 150 | for(PareNum=1;;pos++){
|
---|
| 151 | if(buffer[pos]=='\"'){
|
---|
| 152 | for(pos++;;pos++){
|
---|
| 153 | if(buffer[pos]=='\"') break;
|
---|
| 154 | }
|
---|
| 155 | continue;
|
---|
| 156 | }
|
---|
| 157 | else if(buffer[pos]=='(') PareNum++;
|
---|
| 158 | else if(buffer[pos]==')'){
|
---|
| 159 | PareNum--;
|
---|
| 160 | if(PareNum==0) return pos;
|
---|
| 161 | }
|
---|
| 162 | else if(buffer[pos]=='\0') break;
|
---|
| 163 | }
|
---|
| 164 | return 0;
|
---|
| 165 | }
|
---|
| 166 | int JumpStringInBracket(const char *buffer,int pos){
|
---|
| 167 | int PareNum;
|
---|
| 168 | for(PareNum=1;;pos++){
|
---|
| 169 | if(buffer[pos]=='\"'){
|
---|
| 170 | for(pos++;;pos++){
|
---|
| 171 | if(buffer[pos]=='\"') break;
|
---|
| 172 | }
|
---|
| 173 | continue;
|
---|
| 174 | }
|
---|
| 175 | else if(buffer[pos]=='[') PareNum++;
|
---|
| 176 | else if(buffer[pos]==']'){
|
---|
| 177 | PareNum--;
|
---|
| 178 | if(PareNum==0) return pos;
|
---|
| 179 | }
|
---|
| 180 | else if(buffer[pos]=='\0') break;
|
---|
| 181 | }
|
---|
| 182 | return 0;
|
---|
| 183 | }
|
---|
| 184 | bool IsCommandDelimitation( char c ){
|
---|
| 185 | if( c == '\n' || c == ':' || c == '\0' ){
|
---|
| 186 | return true;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | return false;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | int GetStringInPare_RemovePare(char *buffer,const char *ReadBuffer){
|
---|
| 193 | int i,IsStr,PareNum;
|
---|
| 194 | for(i=0,IsStr=0,PareNum=1;;i++){
|
---|
| 195 | buffer[i]=ReadBuffer[i];
|
---|
| 196 | if(IsDBCSLeadByte(ReadBuffer[i])){
|
---|
| 197 | i++;
|
---|
| 198 | buffer[i]=ReadBuffer[i];
|
---|
| 199 | continue;
|
---|
| 200 | }
|
---|
| 201 | if(ReadBuffer[i]=='\"') IsStr^=1;
|
---|
| 202 | else if(ReadBuffer[i]=='('&&IsStr==0) PareNum++;
|
---|
| 203 | else if(ReadBuffer[i]==')'&&IsStr==0){
|
---|
| 204 | PareNum--;
|
---|
| 205 | if(PareNum==0){
|
---|
| 206 | buffer[i]=0;
|
---|
| 207 | break;
|
---|
| 208 | }
|
---|
| 209 | }
|
---|
| 210 | else if(ReadBuffer[i]=='\0') return 0;
|
---|
| 211 | }
|
---|
| 212 | return i;
|
---|
| 213 | }
|
---|