optimization - Write a compiler for a language that looks ahead and multiple files? -


In my language, I can use a class variable in my method when it appears below the definition method. It can also call methods below my method and etc. There is no 'header' to take this C # example.

  class A {public zero call methods () {print (); BB; B.notYetSeen (); Public Zero Print () {Console.Write ("v = {0}", v); } Int v = 9; } Class B {public zero not YETSeen () {Console.Write ("notYetSeen () \ n"); }}  

How should I compile this? What I was thinking:

  • Pass 1: Change everything in one AST
  • Pass 2: Go through all the squares and define sections / variables / etc Please. >
  • Pass 3: Go through the code and check if there are any errors such as undefined variables, incorrect access, etc. and make their output

but it seems that it does work For I have to pass 1 and 2 for all the files before passing it, besides doing so seems like a lot of work until I get a syntax error (obviously that pars can be done on time It is like a brace The do or do not write 0xLETTERS instead of hex value). My stomach says that there is some other way.

Note: I am using Bison / Flex to generate my compiler.

My understanding of languages, which are further references, is that they usually have valid names Use the first pass to make the list first. On the lines of putting an entry in just one table (without filling the definition) so that you can tell a few points later when you make your actual pass to generate definitions.

If you actually try to create full definitions, then you need to scan again the last time, save any references to save the unchanged things next to each other. . Even if unsuccessful the reference can be unsuccessful.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -