Esempio n. 1
0
 def main():
     import sys
     env = {}
     if len(sys.argv) < 2:
         filename = "/usr/include/stdio.h"
     else:
         filename = sys.argv[1]
     with open(filename, 'r') as fd:
         contents = fd.read()
     stream = CharacterStream(trigraphs.translate(contents), 1, filename)
     state = PreprocessorState(stream, env,
             include_chain=(filename,),
             include=include_stub)
     try:
         position = (1, filename)
         for token in chomp(state):
             if position_of(token) != position:
                 position = advance_position(position, position_of(token))
             # Token generation. This is still wrong
             if name_of(token) == 'string': 
                 sys.stdout.write('"' + value_of(token) + '" ')
             elif name_of(token) == 'char':
                 sys.stdout.write("'" + value_of(token) + "' ")
             else:
                 sys.stdout.write(value_of(token) + ' ')
         sys.stdout.write('\n')
     except AssertionError as ass:
         traceback.print_exc()
         for x in range(5):
             print tokenize.chop(stream)
Esempio n. 2
0
 def main():
     import sys
     env = {}
     if len(sys.argv) < 2:
         filename = "/usr/include/stdio.h"
     else:
         filename = sys.argv[1]
     with open(filename, 'r') as fd:
         contents = fd.read()
     stream = CharacterStream(trigraphs.translate(contents), 1, filename)
     state = PreprocessorState(stream,
                               env,
                               include_chain=(filename, ),
                               include=include_stub)
     try:
         position = (1, filename)
         for token in chomp(state):
             if position_of(token) != position:
                 position = advance_position(position, position_of(token))
             # Token generation. This is still wrong
             if name_of(token) == 'string':
                 sys.stdout.write('"' + value_of(token) + '" ')
             elif name_of(token) == 'char':
                 sys.stdout.write("'" + value_of(token) + "' ")
             else:
                 sys.stdout.write(value_of(token) + ' ')
         sys.stdout.write('\n')
     except AssertionError as ass:
         traceback.print_exc()
         for x in range(5):
             print tokenize.chop(stream)
Esempio n. 3
0
 def main():
     env = {}
     filename = "/usr/include/stdio.h"
     with open(filename, 'r') as fd:
         contents = fd.read()
     stream = CharacterStream(trigraphs.translate(contents), 1, filename)
     state = PreprocessorState(stream, env,
             include_chain=(filename,),
             include=include_stub)
     try:
         position = (1, filename)
         for token in chomp(state):
             if position_of(token) != position:
                 position = advance_position(position, position_of(token))
             sys.stdout.write(value_of(token) + ' ')
         sys.stdout.write('\n')
     except AssertionError as ass:
         traceback.print_exc()
         for x in range(5):
             print tokenize.chop(stream)
Esempio n. 4
0
 def next_token(self):
     token = tokenize.chop(self.stream)
     if token is None:
         self.exhausted = True
     return token
Esempio n. 5
0
 def next_token(self):
     token = tokenize.chop(self.stream)
     if token is None:
         self.exhausted = True
     return token