Created
April 2, 2013 09:12
-
-
Save drslump/5290968 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace consoleApplication1 | |
import System | |
import System.IO | |
class ParserClass: | |
public CurrentCommand as string: | |
get: | |
return self._currentCommand | |
set: | |
self._currentCommand =value | |
private _currentCommand as string | |
public File1 as string: | |
get: | |
return self._file1 | |
set: | |
self._file1 =value | |
private _file1 as string | |
public NumOfLines as int: | |
get: | |
return self._numOfLines | |
set: | |
self._numOfLines =value | |
private _numOfLines as int | |
public CurrentLine as int: | |
get: | |
return self._currentLine | |
set: | |
self._currentLine =value | |
private _currentLine as int | |
public def constructor(path as string): | |
self.File1 = path | |
self.NumOfLines = 0 | |
self.CurrentLine = 0 | |
content= StreamReader(_file1) | |
for line in content.ReadToEnd(): | |
self.NumOfLines= self.NumOfLines+ 1 | |
content.Close() | |
e = StreamReader(self.File1) | |
public def HasMoreCommands() as bool: | |
if self.NumOfLines > self.CurrentLine: | |
return true | |
public def advance(): | |
# Note that there is no need to assign the result of an incrementation | |
self.CurrentLine++ | |
read = File.ReadAllText(self.File1) | |
mylines = @/n/.Split(read) | |
i=0 | |
for word in mylines: | |
if i == self.CurrentLine: | |
str=System.Convert.ToString(word) | |
words_splited= @/" "/.Split(str) | |
self.CurrentCommand = words_splited[1] | |
break | |
public def commandType(): | |
# Matching a value against a set can be done in Boo with: | |
if self.CurrentCommand in ("PUSH", "POP", "ADD", "SUB", "NEG", "EQ", "GT", "LT", "OR", "AND", "NOT"): | |
return "C_ARITHMETIC" | |
elif self.CurrentCommand in ("PUSH",): | |
return "C_PUSH" | |
elif self.CurrentCommand in ("POP",): | |
return "C_POP" | |
public def arg1(): | |
# Matching a value against a set can be done in Boo with: | |
if self.CurrentCommand in ("PUSH", "POP", "ADD", "SUB", "NEG", "EQ", "GT", "LT", "OR", "AND", "NOT"): | |
return self.CurrentCommand | |
elif self.CurrentCommand in ("PUSH", "POP"): | |
read=File.ReadAllText(_file1) | |
mylines = @/n/.Split(read) | |
i=0 | |
for word in mylines: | |
if i == self.CurrentLine: | |
str=System.Convert.ToString(word) | |
words_splited= @/" "/.Split(str) | |
# In Boo methods/functions are also values, we shouldn't shadow their names | |
# or the compiler can start complaining :) | |
arg1_value = words_splited[2] | |
return arg1_value | |
public def arg2(): | |
# Matching a value against a set can be done in Boo with: | |
if self.CurrentCommand in ("PUSH", "POP", "C_FUNCTION", "C_CALL"): | |
read=File.ReadAllText(self.File1) | |
mylines = @/n/.Split(read) | |
i=0 | |
for word in mylines: | |
if i == self.CurrentLine: | |
str=System.Convert.ToString(word) | |
words_splited= @/" "/.Split(str) | |
# In Boo methods/functions are also values, we shouldn't shadow their names | |
# or the compiler can start complaining :) | |
arg2_value = words_splited[3] | |
return arg2_value | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment