python - Semantic Analysis For Simple Compile-To-C Language -


so i'm working on creating simple, compile-to-c language has syntax similar python. here sample source code:

# comments start pound signs  # integer declaration speed = 4 motor = 69.5 text = "hey +  guys!" junk =   5    +4  # move function def move():   speed = speed + 1   print speed  # main function (program entry) def main():   localvar = 43.2   move()   if true:     print localvar 

like python, language emphasizes readability indentation policies. has loose type declaration system. types determined context.

object = 5            // creates integer object_two = "stuff"  // creates string object_three = 5.23   // creates float 

the sample source code have above internally represented such:

[   [     "global",     [       "speed = 4",       "motor = 69.5",       "text = \"hey +  guys!\"",       "junk =   5    +4"     ],     [       "scope",       [         "speed",         "motor",         "text",         "junk"       ],       [         "int",         "float",         "string",         "int"       ],       [         0,         1,         2,         3       ]     ]   ],   [     "def move():",     [       "  speed = speed + 1",       "  print speed"     ],     [       "scope",       [         "speed",         "motor",         "text",         "junk"       ],       [         "global",         "global",         "global",         "global"       ],       [         0,         1,         2,         3       ]     ]   ],   [     "def main():",     [       "  localvar = 43.2",       "  move()",       "  if true:",       "    print localvar"     ],     [       "scope",       [         "speed",         "motor",         "text",         "junk",         "localvar"       ],       [         "global",         "global",         "global",         "global",         "float"       ],       [         0,         1,         2,         3,         0       ]     ]   ] ] 

every function packed representation along respective local variables , types (also index of line declared on respective function).

i'm trying convert intermediate representation actual c code (actually nxc code, differs c).

my question how can make sense of variable types (particularly variables declared in function argument). way can possibly guessing based on context in function called.

not mention, i'm creating intermediate representation in linear fashion. happens if function defined not called until later on? have several runs modifying intermediate representation until obtain necessary type information?


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -