偶有闲暇,添加了对结构的支持。也增加了对typedef structname synonym的支持。
技巧:

  1. 结构成员在解析时转换成相对结构于的起始地址之偏移。
  2. 在运行时计算成员的实际地址(运行时变量才会分配地址 )。
  3. 成员按ValueOfPointerIndiction方式访问。

示例代码:

struct StructA {        int a;        int b;    };    StructA theA;    theA.a = 1;    theA.b = 2;    print("theA.a=%i\ntheA.b=%i", theA.a, theA.b);    StructA *ptheA = &theA;    ptheA->a = 3;    ptheA->b = 4;    print("theA.a=%i\ntheA.b=%i", theA.a, theA.b);    print("ptheA->a=%i\nptheA->b=%i", ptheA->a, ptheA->b);

结果输出:
解析:

SharpC.Grammar.Variable:    Line: 192 Pos: 1 "theA;"SharpC.Grammar.Statement:    Line: 194 Pos: 1 "theA.a = 1;"SharpC.Grammar.Statement:    Line: 195 Pos: 1 "theA.b = 2;"SharpC.Grammar.Statement:    Line: 197 Pos: 1 "print("theA.a=%i\ntheA.b=%i", theA.a, theA.b);"SharpC.Grammar.Variable:    Line: 199 Pos: 1 "ptheA = &theA;"SharpC.Grammar.Statement:    Line: 199 Pos: 1 "ptheA = &theA;"SharpC.Grammar.Statement:    Line: 201 Pos: 1 "ptheA->a = 3;"SharpC.Grammar.Statement:    Line: 202 Pos: 1 "ptheA->b = 4;"SharpC.Grammar.Statement:    Line: 204 Pos: 1 "print("theA.a=%i\ntheA.b=%i", theA.a, theA.b);"SharpC.Grammar.Statement:    Line: 205 Pos: 1 "print("ptheA->a=%i\nptheA->b=%i", ptheA->a, ptheA->b);"

运行:

Declare [struct StructA "theA"] Address: 0x000001D0 Size: 8    Exp: [theA . (* int )[0x00000000]] Result: [(* int )[0x000001D0]]    Exp: [(* int )[0x000001D0] = 1] Result: [(* int )[0x000001D0]]    Exp: [theA . (* int )[0x00000004]] Result: [(* int )[0x000001D4]]    Exp: [(* int )[0x000001D4] = 2] Result: [(* int )[0x000001D4]]    Exp: [theA . (* int )[0x00000000]] Result: [(* int )[0x000001D0]]    Exp: [theA . (* int )[0x00000004]] Result: [(* int )[0x000001D4]]Call function [void  "print"] with [3] parametersDeclare [char *  "$var_char_ptr_161$"] Address: 0x00000194 Size: 4Declare [int  "$var_int_162$"] Address: 0x000001B8 Size: 4Declare [int  "$var_int_163$"] Address: 0x000001B0 Size: 4    Set parameter [char *  "$var_char_ptr_161$"] = 64    Set parameter [int  "$var_int_162$"] = 1    Set parameter [int  "$var_int_163$"] = 2print("theA.a=%i\ntheA.b=%i",1,2)Output of print:"theA.a=1\ntheA.b=2"Free function "print"'s arguments, count: 3    Free argument [char *  "$var_char_ptr_161$"] Address: 0x00000194 Size: 4    Free argument [int  "$var_int_162$"] Address: 0x000001B8 Size: 4    Free argument [int  "$var_int_163$"] Address: 0x000001B0 Size: 4All arguments are freed.Declare [struct * StructA "ptheA"] Address: 0x000001A0 Size: 4    Exp: [theA & ] Result: [464]    Exp: [ptheA = 464] Result: [ptheA]    Exp: [ptheA -> (* int )[0x00000000]] Result: [(* int )[0x000001D0]]    Exp: [(* int )[0x000001D0] = 3] Result: [(* int )[0x000001D0]]    Exp: [ptheA -> (* int )[0x00000004]] Result: [(* int )[0x000001D4]]    Exp: [(* int )[0x000001D4] = 4] Result: [(* int )[0x000001D4]]    Exp: [theA . (* int )[0x00000000]] Result: [(* int )[0x000001D0]]    Exp: [theA . (* int )[0x00000004]] Result: [(* int )[0x000001D4]]Call function [void  "print"] with [3] parametersDeclare [char *  "$var_char_ptr_164$"] Address: 0x000001A4 Size: 4Declare [int  "$var_int_165$"] Address: 0x000001C4 Size: 4Declare [int  "$var_int_166$"] Address: 0x0000019C Size: 4    Set parameter [char *  "$var_char_ptr_164$"] = 36    Set parameter [int  "$var_int_165$"] = 3    Set parameter [int  "$var_int_166$"] = 4print("theA.a=%i\ntheA.b=%i",3,4)Output of print:"theA.a=3\ntheA.b=4"Free function "print"'s arguments, count: 3    Free argument [char *  "$var_char_ptr_164$"] Address: 0x000001A4 Size: 4    Free argument [int  "$var_int_165$"] Address: 0x000001C4 Size: 4    Free argument [int  "$var_int_166$"] Address: 0x0000019C Size: 4All arguments are freed.    Exp: [ptheA -> (* int )[0x00000000]] Result: [(* int )[0x000001D0]]    Exp: [ptheA -> (* int )[0x00000004]] Result: [(* int )[0x000001D4]]Call function [void  "print"] with [3] parametersDeclare [char *  "$var_char_ptr_167$"] Address: 0x00000184 Size: 4Declare [int  "$var_int_168$"] Address: 0x00000198 Size: 4Declare [int  "$var_int_169$"] Address: 0x000001D8 Size: 4    Set parameter [char *  "$var_char_ptr_167$"] = 4    Set parameter [int  "$var_int_168$"] = 3    Set parameter [int  "$var_int_169$"] = 4print("ptheA->a=%i\nptheA->b=%i",3,4)Output of print:"ptheA->a=3\nptheA->b=4"Free function "print"'s arguments, count: 3    Free argument [char *  "$var_char_ptr_167$"] Address: 0x00000184 Size: 4    Free argument [int  "$var_int_168$"] Address: 0x00000198 Size: 4    Free argument [int  "$var_int_169$"] Address: 0x000001D8 Size: 4All arguments are freed.

更深入的测试未进行。