Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SuperStrict
  2.  
  3. Framework brl.blitz
  4.  
  5. ?Win32
  6.     'Framework brl.d3d9max2d
  7. ?Linux
  8.     'Framework brl.glmax2d
  9. ?
  10. Import brl.standardio
  11. Import brl.retro
  12.  
  13. rem
  14. ?Win32
  15.     SetGraphicsDriver D3D9Max2DDriver()
  16. ?Linux
  17.     SetGraphicsDriver GLMax2DDriver()
  18. ?
  19. end rem
  20.  
  21. Scanner.LoadFile("MyScript.txt")
  22.  
  23. Type Scanner
  24.     Global _file:TStream
  25.     Global _tokens:Token[]
  26.     Global _numTokens:Int
  27.    
  28.     Function LoadFile(File:String)
  29.         _file = ReadStream(File)
  30.         If Not _file RuntimeError("File did not load.")
  31.         _ScanFile()
  32.     End Function
  33.    
  34.     Function _ScanFile:Int()
  35.         DebugLog("First pass")
  36.         Repeat
  37.             _GetToken()
  38.             _numTokens:+1
  39.         Until Eof(_file)
  40.        
  41.         _tokens:Token = New Token[_numTokens]
  42.         _file.Seek(0)
  43.        
  44.         DebugLog "Second pass"
  45.         Local i:Int
  46.         Repeat
  47.             _tokens[i] = New token
  48.             _tokens[i].init(_getToken())
  49.             i:+1
  50.         Until Eof(_file)
  51.        
  52.         Local Temp_Token:Token
  53.         For Temp_Token = EachIn _tokens
  54.             Print Temp_Token._value + "~t" + Temp_Token._class
  55.         Next
  56.        
  57.         Return True
  58.     End Function
  59.    
  60.     Function _GetToken:String()
  61.         Local token:String
  62.         Repeat
  63.             Local character:String = ReadString(_file, 1)
  64.             Local nextCharacter:String
  65.             If Not Eof(_file)
  66.                 nextCharacter = ReadString(_file, 1)
  67.                 _file.Seek(_file.Pos() - 1)
  68.             EndIf
  69.             token:+character
  70.            
  71.             Local firstCharacter:String = Left(token, 1)
  72.             If (nextCharacter = " " Or nextCharacter = "." Or character = " " Or character = ".") And firstCharacter <> "~q"
  73.                 Exit
  74.             Else If character = "~q" And firstCharacter = "~q" And token.Length > 1
  75.                 Exit
  76.             End If
  77.         Until Eof(_file)
  78.        
  79.         Return token
  80.     End Function
  81.    
  82.     Function _CheckToken:String(token:String)
  83.         Select token
  84.             Case " "
  85.         End Select
  86.     End Function
  87. End Type
  88.  
  89. Type Token
  90.     Field _value:String
  91.     Field _class:String
  92.    
  93.     Method Init(Value:String)
  94.         _value = Value
  95.        
  96.         Local firstCharacter:String = Left(_value, 1)
  97.         Select firstCharacter
  98.             Case "~q"
  99.             _class = "string"
  100.             _value = Left(_value, Len(_value) - 1)
  101.             _value = Right(_value, Len(_value) - 1)
  102.            
  103.             Case "."
  104.             _class = "teminating character"
  105.            
  106.             Case " "
  107.             _class = "literal character"
  108.            
  109.             Default
  110.             _class = "identifier"
  111.         End Select
  112.     End Method
  113. End Type
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement