Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SuperStrict
- Framework brl.blitz
- ?Win32
- 'Framework brl.d3d9max2d
- ?Linux
- 'Framework brl.glmax2d
- ?
- Import brl.standardio
- Import brl.retro
- rem
- ?Win32
- SetGraphicsDriver D3D9Max2DDriver()
- ?Linux
- SetGraphicsDriver GLMax2DDriver()
- ?
- end rem
- Scanner.LoadFile("MyScript.txt")
- Type Scanner
- Global _file:TStream
- Global _tokens:Token[]
- Global _numTokens:Int
- Function LoadFile(File:String)
- _file = ReadStream(File)
- If Not _file RuntimeError("File did not load.")
- _ScanFile()
- End Function
- Function _ScanFile:Int()
- DebugLog("First pass")
- Repeat
- _GetToken()
- _numTokens:+1
- Until Eof(_file)
- _tokens:Token = New Token[_numTokens]
- _file.Seek(0)
- DebugLog "Second pass"
- Local i:Int
- Repeat
- _tokens[i] = New token
- _tokens[i].init(_getToken())
- i:+1
- Until Eof(_file)
- Local Temp_Token:Token
- For Temp_Token = EachIn _tokens
- Print Temp_Token._value + "~t" + Temp_Token._class
- Next
- Return True
- End Function
- Function _GetToken:String()
- Local token:String
- Repeat
- Local character:String = ReadString(_file, 1)
- Local nextCharacter:String
- If Not Eof(_file)
- nextCharacter = ReadString(_file, 1)
- _file.Seek(_file.Pos() - 1)
- EndIf
- token:+character
- Local firstCharacter:String = Left(token, 1)
- If (nextCharacter = " " Or nextCharacter = "." Or character = " " Or character = ".") And firstCharacter <> "~q"
- Exit
- Else If character = "~q" And firstCharacter = "~q" And token.Length > 1
- Exit
- End If
- Until Eof(_file)
- Return token
- End Function
- Function _CheckToken:String(token:String)
- Select token
- Case " "
- End Select
- End Function
- End Type
- Type Token
- Field _value:String
- Field _class:String
- Method Init(Value:String)
- _value = Value
- Local firstCharacter:String = Left(_value, 1)
- Select firstCharacter
- Case "~q"
- _class = "string"
- _value = Left(_value, Len(_value) - 1)
- _value = Right(_value, Len(_value) - 1)
- Case "."
- _class = "teminating character"
- Case " "
- _class = "literal character"
- Default
- _class = "identifier"
- End Select
- End Method
- End Type
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement