ltcmelo / psychec

A compiler frontend for the C programming language
BSD 3-Clause "New" or "Revised" License
535 stars 39 forks source link

Something wrong when I dumped AST with codes like"sum = 3 * M + 4 * M + 5 * M;" #126

Open Z769018860 opened 1 year ago

Z769018860 commented 1 year ago

source code:

int main() { int sum=5; sum = 3 M + 4 M + 5 * M; int test=assgin(sum); printf(sum); return 0; }

AST:

TranslationUnit |--FunctionDefinition <54:2162..54:2173> int main() { |--BuiltinTypeSpecifier <54:2162..54:2164> int |--FunctionDeclarator <54:2166..54:2170> main( | |--IdentifierDeclarator <54:2166..54:2169> main | |--ParameterSuffix <54:2170..54:2171> () |--CompoundStatement <54:2173..60:2260> { int sum=5; sum = 3 * M + 4 *... |--DeclarationStatement <55:2175..55:2177> int | |--VariableAndOrFunctionDeclaration <55:2175..55:2184> int sum=5; | |--BuiltinTypeSpecifier <55:2175..55:2177> int | |--IdentifierDeclarator <55:2179..55:2183> sum=5 | |--ExpressionInitializer <55:2183..55:2183> 5 | |--IntegerConstantExpression <55:2183..55:2183> 5 |--ExpressionStatement <56:2186..56:2213> sum = 3 * M + 4 * M + 5 * M; | |--BasicAssignmentExpression <56:2186..56:2192> sum = 3 | |--IdentifierName <56:2186..56:2188> sum | |--AddExpression <56:2192..56:2208> 3 * M + 4 * M + 5 | |--AddExpression <56:2192..56:2200> 3 * M + 4 | | |--MultipliyExpression <56:2192..56:2196> 3 * M | | | |--IntegerConstantExpression <56:2192..56:2192> 3 | | | |--IdentifierName <56:2196..56:2196> M | | |--MultipliyExpression <56:2200..56:2204> 4 * M | | |--IntegerConstantExpression <56:2200..56:2200> 4 | | |--IdentifierName <56:2204..56:2204> M | |--MultipliyExpression <56:2208..56:2212> 5 * M | |--IntegerConstantExpression <56:2208..56:2208> 5 | |--IdentifierName <56:2212..56:2212> M |--DeclarationStatement <57:2215..57:2217> int | |--VariableAndOrFunctionDeclaration <57:2215..57:2235> int test=assgin(sum); | |--BuiltinTypeSpecifier <57:2215..57:2217> int | |--IdentifierDeclarator <57:2219..57:2229> test=assgin | |--ExpressionInitializer <57:2224..57:2229> assgin | |--CallExpression <57:2224..57:2234> assgin(sum) | |--IdentifierName <57:2224..57:2229> assgin | |--IdentifierName <57:2231..57:2233> sum |--AmbiguousCallOrVariableDeclaration <58:2237..58:2242> printf | |--DeclarationStatement <58:2237..58:2242> printf | | |--VariableAndOrFunctionDeclaration <58:2237..58:2248> printf(sum); | | |--TypedefName <58:2237..58:2242> printf | | |--ParenthesizedDeclarator <58:2243..58:2247> (sum) | | |--IdentifierDeclarator <58:2244..58:2246> sum | |--ExpressionStatement <58:2237..58:2248> printf(sum); | |--CallExpression <58:2237..58:2247> printf(sum) | |--IdentifierName <58:2237..58:2242> printf | |--IdentifierName <58:2244..58:2246> sum |--ReturnStatement <59:2250..59:2258> return 0; |--IntegerConstantExpression <59:2257..59:2257> 0

ERROR:

  |     |--IdentifierDeclarator  <57:2219..57:2229>  `test=assgin`
  |        |--ExpressionInitializer  <57:2224..57:2229>  `assgin`

  |--ExpressionStatement  <56:2186..56:2213>  `sum = 3 * M + 4 * M + 5 * M;`
  |  |--BasicAssignmentExpression  <56:2186..56:2192>  `sum = 3`
  |     |--IdentifierName  <56:2186..56:2188>  `sum`

I think there is something wrong with ‘=’. The content next to '=' will be always extracted with the variable before '='.