opening file "IRuleandAction.cs" using declar : using System ; using declar : using System . Collections ; using declar : using System . Collections . Generic ; namespace def : namespace CodeAnalysis { interface def : public interface IAction { function declar: void doAction ( CSsemi . CSemiExp semi ) ; class def : public abstract class AAction : IAction { data declar : static bool displaySemi_ = false ; data declar : static bool displayStack_ = false ; data declar : protected Repository repo_ ; data declar : static public Action < string > actionDelegate ; function declar: public abstract void doAction ( CSsemi . CSemiExp semi ) ; executable : return displaySemi_ ; executable : displaySemi_ = value ; executable : return displayStack_ ; executable : displayStack_ = value ; function def : public virtual void display ( CSsemi . CSemiExp semi ) { executable : if ( displaySemi ) for ( int i = 0 ; executable : i < semi . count ; executable : i ) Console . Write ( "{0} " , semi [ i ] ) ; interface def : public interface IRule { function declar: bool test ( CSsemi . CSemiExp semi ) ; function declar: void add ( IAction action ) ; class def : public abstract class ARule : IRule { data declar : private List < IAction > actions ; data declar : static public Action < string > actionDelegate ; function def : public ARule ( ) { executable : actions = new List < IAction > ( ) ; function def : public void add ( IAction action ) { executable : actions . Add ( action ) ; function declar: abstract public bool test ( CSsemi . CSemiExp semi ) ; function def : public void doActions ( CSsemi . CSemiExp semi ) { executable : foreach ( IAction action in actions ) action . doAction ( semi ) ; function def : public int indexOfType ( CSsemi . CSemiExp semi ) { data declar : int indexCL = semi . Contains ( "class" ) ; data declar : int indexIF = semi . Contains ( "interface" ) ; data declar : int indexST = semi . Contains ( "struct" ) ; data declar : int indexEN = semi . Contains ( "enum" ) ; data declar : int indexDE = semi . Contains ( "delegate" ) ; data declar : int index = Math . Max ( indexCL , indexIF ) ; executable : index = Math . Max ( index , indexST ) ; executable : index = Math . Max ( index , indexEN ) ; executable : index = Math . Max ( index , indexDE ) ; executable : return index ; opening file "Parser.cs" using declar : using System ; using declar : using System . Collections ; using declar : using System . Collections . Generic ; using declar : using System . Linq ; using declar : using System . Text ; using declar : using System . IO ; namespace def : namespace CodeAnalysis { class def : public class Parser { data declar : private List < IRule > Rules ; function def : public Parser ( ) { executable : Rules = new List < IRule > ( ) ; function def : public void add ( IRule rule ) { executable : Rules . Add ( rule ) ; function def : public void parse ( CSsemi . CSemiExp semi ) { executable : Display . displaySemiString ( semi . displayStr ( ) ) ; control def : foreach ( IRule rule in Rules ) { executable : if ( rule . test ( semi ) ) break ; class def : class TestParser { function def : static List < string > ProcessCommandline ( string [ ] args ) { data declar : List < string > files = new List < string > ( ) ; control def : if ( args . Length == 0 ) { executable : Console . Write ( "\n Please enter file(s) to analyze\n\n" ) ; executable : return files ; data declar : string path = args [ 0 ] ; executable : path = Path . GetFullPath ( path ) ; control def : for ( int i = 1 ; i < args . Length ; ++ i ) { data declar : string filename = Path . GetFileName ( args [ i ] ) ; executable : files . AddRange ( Directory . GetFiles ( path , filename ) ) ; executable : return files ; function def : static void ShowCommandLine ( string [ ] args ) { executable : Console . Write ( "\n Commandline args are:\n " ) ; control def : foreach ( string arg in args ) { executable : Console . Write ( " {0}" , arg ) ; executable : Console . Write ( "\n current directory: {0}" , System . IO . Directory . GetCurrentDirectory ( ) ) ; executable : Console . Write ( "\n" ) ; function def : static void Main ( string [ ] args ) { executable : Console . Write ( "\n Demonstrating Parser" ) ; executable : Console . Write ( "\n ======================\n" ) ; executable : ShowCommandLine ( args ) ; data declar : List < string > files = TestParser . ProcessCommandline ( args ) ; control def : foreach ( string file in files ) { executable : Console . Write ( "\n Processing file {0}\n" , System . IO . Path . GetFileName ( file ) ) ; function declar: CSsemi . CSemiExp semi = new CSsemi . CSemiExp ( ) ; executable : semi . displayNewLines = false ; control def : if ( ! semi . open ( file as string ) ) { executable : Console . Write ( "\n Can't open {0}\n\n" , args [ 0 ] ) ; executable : Console . Write ( "\n Type and Function Analysis" ) ; executable : Console . Write ( "\n ----------------------------" ) ; data declar : BuildCodeAnalyzer builder = new BuildCodeAnalyzer ( semi ) ; function declar: Parser parser = builder . build ( ) ; control def : try { executable : while ( semi . getSemi ( ) ) parser . parse ( semi ) ; executable : Console . Write ( "\n locations table contains:" ) ; control def : catch ( Exception ex ) { executable : Console . Write ( "\n\n {0}\n" , ex . Message ) ; function declar: Repository rep = Repository . getInstance ( ) ; data declar : List < Elem > table = rep . locations ; executable : Console . Write ( "\n {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}" , "category" , "name" , "bLine" , "eLine" , "bScop" , "eScop" , "size" , "cmplx" ) ; executable : Console . Write ( "\n {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}" , "--------" , "----" , "-----" , "-----" , "-----" , "-----" , "----" , "-----" ) ; control def : foreach ( Elem e in table ) { executable : if ( e . type == "class" || e . type == "struct" ) Console . Write ( "\n" ) ; executable : Console . Write ( "\n {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}" , e . type , e . name , e . beginLine , e . endLine , e . beginScopeCount , e . endScopeCount + 1 , e . endLine - e . beginLine + 1 , e . endScopeCount - e . beginScopeCount + 1 ) ; executable : Console . Write ( "\n" ) ; function declar: semi . close ( ) ; executable : Console . Write ( "\n\n" ) ; opening file "RulesAndActions.cs" using declar : using System ; using declar : using System . Collections ; using declar : using System . Collections . Generic ; using declar : using System . Text ; namespace def : namespace CodeAnalysis { class def : public class Elem { function def : public override string ToString ( ) { data declar : StringBuilder temp = new StringBuilder ( ) ; executable : temp . Append ( "{" ) ; executable : temp . Append ( String . Format ( "{0,-10}" , type ) ) . Append ( " : " ) ; executable : temp . Append ( String . Format ( "{0,-10}" , name ) ) . Append ( " : " ) ; executable : temp . Append ( String . Format ( "{0,-5}" , beginLine . ToString ( ) ) ) ; executable : temp . Append ( String . Format ( "{0,-5}" , endLine . ToString ( ) ) ) ; executable : temp . Append ( "}" ) ; executable : return temp . ToString ( ) ; class def : public class Repository { function declar: ScopeStack < Elem > stack_ = new ScopeStack < Elem > ( ) ; function declar: List < Elem > locations_ = new List < Elem > ( ) ; function declar: Dictionary < string , List < Elem >> locationsTable_ = new Dictionary < string , List < Elem >> ( ) ; data declar : static Repository instance ; function def : public Repository ( ) { executable : instance = this ; function def : public static Repository getInstance ( ) { executable : return instance ; executable : return semi . lineCount ; executable : return stack_ ; executable : return locations_ ; executable : locations_ = value ; executable : return locationsTable_ ; executable : locationsTable_ = value ; class def : public class PushStack : AAction { function def : public PushStack ( Repository repo ) { executable : repo_ = repo ; function def : public override void doAction ( CSsemi . CSemiExp semi ) { executable : Display . displayActions ( actionDelegate , "action PushStack" ) ; executable : repo_ . scopeCount ; data declar : Elem elem = new Elem ( ) ; executable : elem . type = semi [ 0 ] ; executable : elem . name = semi [ 1 ] ; executable : elem . beginLine = repo_ . semi . lineCount - 1 ; executable : elem . endLine = 0 ; executable : elem . beginScopeCount = repo_ . scopeCount ; executable : elem . endScopeCount = 0 ; executable : repo_ . stack . push ( elem ) ; executable : if ( AAction . displayStack ) repo_ . stack . display ( ) ; control def : if ( AAction . displaySemi ) { executable : Console . Write ( "\n line# {0,-5}" , repo_ . semi . lineCount - 1 ) ; executable : Console . Write ( "entering " ) ; data declar : string indent = new string ( ' ' , 2 * repo_ . stack . count ) ; executable : Console . Write ( "{0}" , indent ) ; executable : this . display ( semi ) ; executable : if ( elem . type == "control" || elem . name == "anonymous" ) return ; executable : repo_ . locations . Add ( elem ) ; class def : public class PopStack : AAction { function def : public PopStack ( Repository repo ) { executable : repo_ = repo ; function def : public override void doAction ( CSsemi . CSemiExp semi ) { executable : Display . displayActions ( actionDelegate , "action SaveDeclar" ) ; data declar : Elem elem ; control def : try { function declar: elem = repo_ . stack . pop ( ) ; control def : for ( int i = 0 ; i < repo_ . locations . Count ; ++ i ) { data declar : Elem temp = repo_ . locations [ i ] ; control def : if ( elem . type == temp . type ) { control def : if ( elem . name == temp . name ) { control def : if ( ( repo_ . locations [ i ] ) . endLine == 0 ) { executable : repo_ . locations [ i ] ) . endLine = repo_ . semi . lineCount ; executable : repo_ . locations [ i ] ) . endScopeCount = repo_ . scopeCount ; control def : catch { executable : Console . Write ( "popped empty stack on semiExp: " ) ; function declar: semi . display ( ) ; executable : CSsemi . CSemiExp local = new CSsemi . CSemiExp ( ) ; executable : local . Add ( elem . type ) . Add ( elem . name ) ; executable : if ( local [ 0 ] == "control" ) return ; control def : if ( AAction . displaySemi ) { executable : Console . Write ( "\n line# {0,-5}" , repo_ . semi . lineCount ) ; executable : Console . Write ( "leaving " ) ; data declar : string indent = new string ( ' ' , 2 * ( repo_ . stack . count + 1 ) ) ; executable : Console . Write ( "{0}" , indent ) ; executable : this . display ( local ) ; class def : public class PrintFunction : AAction { function def : public PrintFunction ( Repository repo ) { executable : repo_ = repo ; function def : public override void display ( CSsemi . CSemiExp semi ) { executable : Console . Write ( "\n line# {0}" , repo_ . semi . lineCount - 1 ) ; executable : Console . Write ( "\n " ) ; executable : for ( int i = 0 ; i < semi . count ; ++ i ) if ( semi [ i ] ! = "\n" && ! semi . isComment ( semi [ i ] ) ) Console . Write ( "{0} " , semi [ i ] ) ; function def : public override void doAction ( CSsemi . CSemiExp semi ) { executable : this . display ( semi ) ; class def : public class Print : AAction { function def : public Print ( Repository repo ) { executable : repo_ = repo ; function def : public override void doAction ( CSsemi . CSemiExp semi ) { executable : Console . Write ( "\n line# {0}" , repo_ . semi . lineCount - 1 ) ; executable : this . display ( semi ) ; class def : public class SaveDeclar : AAction { function def : public SaveDeclar ( Repository repo ) { executable : repo_ = repo ; function def : public override void doAction ( CSsemi . CSemiExp semi ) { executable : Display . displayActions ( actionDelegate , "action SaveDeclar" ) ; data declar : Elem elem = new Elem ( ) ; executable : elem . type = semi [ 0 ] ; executable : elem . name = semi [ 1 ] ; executable : elem . beginLine = repo_ . semi . lineCount ; executable : elem . endLine = elem . beginLine ; executable : elem . beginScopeCount = repo_ . scopeCount ; executable : elem . endScopeCount = elem . beginScopeCount ; control def : if ( AAction . displaySemi ) { executable : Console . Write ( "\n line# {0,-5}" , repo_ . semi . lineCount - 1 ) ; executable : Console . Write ( "entering " ) ; data declar : string indent = new string ( ' ' , 2 * repo_ . stack . count ) ; executable : Console . Write ( "{0}" , indent ) ; executable : this . display ( semi ) ; executable : repo_ . locations . Add ( elem ) ; class def : public class DetectNamespace : ARule { function def : public override bool test ( CSsemi . CSemiExp semi ) { executable : Display . displayRules ( actionDelegate , "rule DetectNamespace" ) ; data declar : int index = semi . Contains ( "namespace" ) ; control def : if ( index ! = - 1 ) { function declar: CSsemi . CSemiExp local = new CSsemi . CSemiExp ( ) ; executable : local . displayNewLines = false ; function declar: local . Add ( semi [ index ] ) . Add ( semi [ index + 1 ] ) ; executable : doActions ( local ) ; executable : return true ; executable : return false ; class def : public class DetectClass : ARule { function def : public override bool test ( CSsemi . CSemiExp semi ) { executable : Display . displayRules ( actionDelegate , "rule DetectClass" ) ; data declar : int indexCL = semi . Contains ( "class" ) ; data declar : int indexIF = semi . Contains ( "interface" ) ; data declar : int indexST = semi . Contains ( "struct" ) ; data declar : int index = Math . Max ( indexCL , indexIF ) ; executable : index = Math . Max ( index , indexST ) ; control def : if ( index ! = - 1 ) { function declar: CSsemi . CSemiExp local = new CSsemi . CSemiExp ( ) ; executable : local . displayNewLines = false ; function declar: local . Add ( semi [ index ] ) . Add ( semi [ index + 1 ] ) ; executable : doActions ( local ) ; executable : return true ; executable : return false ; class def : public class DetectFunction : ARule { function def : public static bool isSpecialToken ( string token ) { executable : foreach ( string stoken in SpecialToken ) if ( stoken == token ) return true ; executable : return false ; function def : public override bool test ( CSsemi . CSemiExp semi ) { executable : Display . displayRules ( actionDelegate , "rule DetectFunction" ) ; executable : if ( semi [ semi . count - 1 ] ! = "{" ) return false ; data declar : int index = semi . FindFirst ( "(" ) ; control def : if ( index > 0 && ! isSpecialToken ( semi [ index - 1 ] ) ) { function declar: CSsemi . CSemiExp local = new CSsemi . CSemiExp ( ) ; executable : local . Add ( "function" ) . Add ( semi [ index - 1 ] ) ; executable : doActions ( local ) ; executable : return true ; executable : return false ; class def : public class DetectAnonymousScope : ARule { function def : public override bool test ( CSsemi . CSemiExp semi ) { executable : Display . displayRules ( actionDelegate , "rule DetectAnonymousScope" ) ; data declar : int index = semi . Contains ( "{" ) ; control def : if ( index ! = - 1 ) { function declar: CSsemi . CSemiExp local = new CSsemi . CSemiExp ( ) ; executable : local . displayNewLines = false ; executable : local . Add ( "control" ) . Add ( "anonymous" ) ; executable : doActions ( local ) ; executable : return true ; executable : return false ; class def : public class DetectPublicDeclar : ARule { function def : public override bool test ( CSsemi . CSemiExp semi ) { executable : Display . displayRules ( actionDelegate , "rule DetectPublicDeclar" ) ; data declar : int index = semi . Contains ( ";" ) ; control def : if ( index ! = - 1 ) { executable : index = semi . Contains ( "public" ) ; executable : if ( index == - 1 ) return true ; function declar: CSsemi . CSemiExp local = new CSsemi . CSemiExp ( ) ; executable : local . displayNewLines = false ; executable : local . Add ( "public " + semi [ index + 1 ] ) . Add ( semi [ index + 2 ] ) ; executable : index = semi . Contains ( "=" ) ; control def : if ( index ! = - 1 ) { executable : doActions ( local ) ; executable : return true ; executable : index = semi . Contains ( "(" ) ; control def : if ( index == - 1 ) { executable : doActions ( local ) ; executable : return true ; executable : return false ; class def : public class DetectLeavingScope : ARule { function def : public override bool test ( CSsemi . CSemiExp semi ) { executable : Display . displayRules ( actionDelegate , "rule DetectLeavingScope" ) ; data declar : int index = semi . Contains ( "}" ) ; control def : if ( index ! = - 1 ) { executable : doActions ( semi ) ; executable : return true ; executable : return false ; class def : public class BuildCodeAnalyzer { function declar: Repository repo = new Repository ( ) ; function def : public BuildCodeAnalyzer ( CSsemi . CSemiExp semi ) { executable : repo . semi = semi ; function def : public virtual Parser build ( ) { data declar : Parser parser = new Parser ( ) ; executable : AAction . displaySemi = false ; executable : AAction . displayStack = false ; data declar : PushStack push = new PushStack ( repo ) ; data declar : DetectNamespace detectNS = new DetectNamespace ( ) ; executable : detectNS . add ( push ) ; executable : parser . add ( detectNS ) ; data declar : DetectClass detectCl = new DetectClass ( ) ; executable : detectCl . add ( push ) ; executable : parser . add ( detectCl ) ; data declar : DetectFunction detectFN = new DetectFunction ( ) ; executable : detectFN . add ( push ) ; executable : parser . add ( detectFN ) ; data declar : DetectAnonymousScope anon = new DetectAnonymousScope ( ) ; executable : anon . add ( push ) ; executable : parser . add ( anon ) ; data declar : DetectPublicDeclar pubDec = new DetectPublicDeclar ( ) ; data declar : SaveDeclar print = new SaveDeclar ( repo ) ; executable : pubDec . add ( print ) ; executable : parser . add ( pubDec ) ; data declar : DetectLeavingScope leave = new DetectLeavingScope ( ) ; data declar : PopStack pop = new PopStack ( repo ) ; executable : leave . add ( pop ) ; executable : parser . add ( leave ) ; executable : return parser ; opening file "ScopeStack.cs" using declar : using System ; using declar : using System . Collections . Generic ; using declar : using System . Linq ; using declar : using System . Text ; namespace def : namespace CodeAnalysis { class def : public class ScopeStack < E > { function declar: List < E > stack_ = new List < E > ( ) ; data declar : E lastPopped_ ; function def : public void push ( E elem ) { executable : stack_ . Add ( elem ) ; function def : public E pop ( ) { data declar : int len = stack_ . Count ; executable : if ( len == 0 ) throw new Exception ( "empty scope stack" ) ; data declar : E elem = stack_ [ len - 1 ] ; executable : stack_ . RemoveAt ( len - 1 ) ; executable : lastPopped_ = elem ; executable : return elem ; function def : public void clear ( ) { executable : stack_ . Clear ( ) ; executable : if ( i < 0 || stack_ . Count < = i ) throw new Exception ( "scope stack index out of range" ) ; executable : return stack_ [ i ] ; executable : if ( i < 0 || stack_ . Count < = i ) throw new Exception ( "scope stack index out of range" ) ; executable : stack_ [ i ] = value ; executable : return stack_ . Count ; function def : public E lastPopped ( ) { executable : return lastPopped_ ; function def : public void display ( ) { control def : for ( int i = 0 ; i < count ; ++ i ) { executable : Console . Write ( "\n {0}" , stack_ [ i ] . ToString ( ) ) ; class def : class Test { struct def : public struct Elem { data declar : public string type ; data declar : public string name ; data declar : public int place ; function def : public void make ( string tp , string nm , int pl ) { executable : type = tp ; executable : name = nm ; executable : place = pl ; function def : public override string ToString ( ) { data declar : StringBuilder temp = new StringBuilder ( ) ; executable : temp . Append ( "{" ) ; executable : temp . Append ( String . Format ( "{0,-10}" , type ) ) . Append ( " : " ) ; executable : temp . Append ( String . Format ( "{0,-10}" , name ) ) . Append ( " : " ) ; executable : temp . Append ( String . Format ( "{0,-5}" , place . ToString ( ) ) ) ; executable : temp . Append ( "}" ) ; executable : return temp . ToString ( ) ; function def : static void Main ( ) { executable : Console . Write ( "\n Test ScopeStack" ) ; executable : Console . Write ( "\n =================\n" ) ; data declar : ScopeStack < Elem > mystack = new ScopeStack < Elem > ( ) ; executable : Test . Elem e ; executable : e . type = "namespace" ; executable : e . name = "foobar" ; executable : e . place = 14 ; executable : mystack . push ( e ) ; executable : e . make ( "class" , "feebar" , 21 ) ; executable : mystack . push ( e ) ; executable : e . make ( "function" , "doTest" , 44 ) ; executable : mystack . push ( e ) ; executable : e . make ( "control" , "for" , 56 ) ; executable : mystack . push ( e ) ; executable : mystack . display ( ) ; executable : Console . WriteLine ( ) ; data declar : Elem test = mystack . lastPopped ( ) ; executable : Console . Write ( "\n last popped:\n {0}\n" , test ) ; executable : e = mystack . pop ( ) ; executable : Console . Write ( "\n popped:\n {0}" , e ) ; executable : e = mystack . pop ( ) ; executable : Console . Write ( "\n popped:\n {0}\n" , e ) ; executable : Console . Write ( "\n last popped:\n {0}\n" , mystack . lastPopped ( ) ) ; executable : mystack . display ( ) ; executable : Console . Write ( "\n\n" ) ; opening file "Semi.cs" using declar : using System ; using declar : using System . Collections ; using declar : using System . Collections . Generic ; using declar : using System . Text ; using declar : using CStoker ; namespace def : namespace CSsemi { class def : public class CSemiExp { data declar : CToker toker = null ; data declar : List < string > semiExp = null ; data declar : string currTok = "" ; data declar : string prevTok = "" ; executable : return toker . lineCount ; function def : public CSemiExp ( ) { executable : toker = new CToker ( ) ; executable : semiExp = new List < string > ( ) ; executable : discardComments = true ; executable : returnNewLines = true ; executable : displayNewLines = false ; function def : override public bool Equals ( Object semi ) { data declar : CSemiExp temp = ( CSemiExp ) semi ; executable : if ( temp . count ! = this . count ) return false ; executable : for ( int i = 0 ; i < temp . count && i < this . count ; ++ i ) if ( this [ i ] ! = temp [ i ] ) return false ; executable : return true ; function def : public int FindFirst ( string str ) { executable : for ( int i = 0 ; i < count - 1 ; ++ i ) if ( this [ i ] == str ) return i ; function def : public int FindLast ( string str ) { executable : for ( int i = this . count - 1 ; i > = 0 ; -- i ) if ( this [ i ] == str ) return i ; function def : public int Contains ( string str ) { executable : return FindLast ( str ) ; function def : override public System . Int32 GetHashCode ( ) { executable : return base . GetHashCode ( ) ; function def : public bool open ( string fileName ) { executable : return toker . openFile ( fileName ) ; function def : public void close ( ) { executable : toker . close ( ) ; function def : bool isTerminator ( string tok ) { control def : switch ( tok ) { executable : case ";" : return true ; executable : case "{" : return true ; executable : case "}" : return true ; executable : case "\n" : if ( this . FindFirst ( "#" ) ! = - 1 ) return true ; executable : return false ; function def : string get ( ) { executable : prevTok = currTok ; executable : currTok = toker . getTok ( ) ; executable : if ( verbose ) Console . Write ( "{0} " , currTok ) ; executable : return currTok ; function def : bool IsPunc ( char ch ) { executable : return ( Char . IsPunctuation ( ch ) || Char . IsSymbol ( ch ) ) ; function def : bool IsOperatorPair ( char first , char second ) { data declar : StringBuilder test = new StringBuilder ( ) ; executable : test . Append ( first ) . Append ( second ) ; executable : foreach ( string oper in opers ) if ( oper . Equals ( test . ToString ( ) ) ) return true ; executable : return false ; function def : public bool getSemi ( ) { executable : semiExp . RemoveRange ( 0 , semiExp . Count ) ; control def : do { function declar: get ( ) ; executable : if ( currTok == "" ) return false ; executable : if ( returnNewLines || currTok ! = "\n" ) semiExp . Add ( currTok ) ; executable : while ( ! isTerminator ( currTok ) || count == 0 ) ; control def : if ( semiExp . Contains ( "for" ) ) { function declar: CSemiExp se = clone ( ) ; function declar: getSemi ( ) ; function declar: se . Add ( semiExp . ToArray ( ) ) ; function declar: getSemi ( ) ; function declar: se . Add ( semiExp . ToArray ( ) ) ; function declar: semiExp . Clear ( ) ; executable : for ( int i = 0 ; i < se . count ; ++ i ) semiExp . Add ( se [ i ] ) ; executable : return ( semiExp . Count > 0 ) ; executable : return semiExp . Count ; executable : return semiExp [ i ] ; executable : semiExp [ i ] = value ; function def : public bool insert ( int loc , string tok ) { control def : if ( 0 < = loc && loc < semiExp . Count ) { executable : semiExp . Insert ( loc , tok ) ; executable : return true ; executable : return false ; function def : public CSemiExp Add ( string token ) { executable : semiExp . Add ( token ) ; executable : return this ; function def : public void Add ( string [ ] source ) { executable : foreach ( string tok in source ) semiExp . Add ( tok ) ; function def : public bool initialize ( ) { executable : if ( semiExp . Count > 0 ) return false ; executable : semiExp . Add ( ";" ) ; executable : return true ; function def : public void flush ( ) { executable : semiExp . RemoveRange ( 0 , semiExp . Count ) ; function def : public bool isComment ( string tok ) { executable : if ( tok . Length > 1 ) if ( tok [ 0 ] == '/' ) if ( tok [ 1 ] == '/' || tok [ 1 ] == '*' ) return true ; executable : return false ; function def : public void display ( ) { executable : Console . Write ( "\n" ) ; executable : Console . Write ( displayStr ( ) ) ; function def : public string displayStr ( ) { data declar : StringBuilder disp = new StringBuilder ( "" ) ; control def : foreach ( string tok in semiExp ) { executable : disp . Append ( tok ) ; executable : if ( tok . IndexOf ( '\n' ) ! = tok . Length - 1 ) disp . Append ( " " ) ; executable : return disp . ToString ( ) ; function def : public CSemiExp clone ( ) { data declar : CSemiExp copy = new CSemiExp ( ) ; control def : for ( int i = 0 ; i < count ; ++ i ) { function declar: copy . Add ( this [ i ] ) ; executable : return copy ; function def : public bool remove ( int i ) { control def : if ( 0 < = i && i < semiExp . Count ) { executable : semiExp . RemoveAt ( i ) ; executable : return true ; executable : return false ; function def : public bool remove ( string token ) { control def : if ( semiExp . Contains ( token ) ) { executable : semiExp . Remove ( token ) ; executable : return true ; executable : return false ; function def : STAThread ] static void Main ( string [ ] args ) { executable : Console . Write ( "\n Testing semiExp Operations" ) ; executable : Console . Write ( "\n ============================\n" ) ; data declar : CSemiExp test = new CSemiExp ( ) ; executable : test . returnNewLines = true ; executable : test . displayNewLines = true ; data declar : string testFile = "../../testSemi.txt" ; executable : if ( ! test . open ( testFile ) ) Console . Write ( "\n Can't open file {0}" , testFile ) ; executable : while ( test . getSemi ( ) ) test . display ( ) ; executable : test . initialize ( ) ; executable : test . insert ( 0 , "this" ) ; executable : test . insert ( 1 , "is" ) ; executable : test . insert ( 2 , "a" ) ; executable : test . insert ( 3 , "test" ) ; executable : test . display ( ) ; executable : Console . Write ( "\n 2nd token = \"{0}\"\n" , test [ 1 ] ) ; executable : Console . Write ( "\n removing first token:" ) ; executable : test . remove ( 0 ) ; executable : test . display ( ) ; executable : Console . Write ( "\n" ) ; executable : Console . Write ( "\n removing token \"test\":" ) ; executable : test . remove ( "test" ) ; executable : test . display ( ) ; executable : Console . Write ( "\n" ) ; executable : Console . Write ( "\n making copy of semiExpression:" ) ; data declar : CSemiExp copy = test . clone ( ) ; executable : copy . display ( ) ; executable : Console . Write ( "\n" ) ; control def : if ( args . Length == 0 ) { executable : Console . Write ( "\n Please enter name of file to analyze\n\n" ) ; data declar : CSemiExp semi = new CSemiExp ( ) ; executable : semi . returnNewLines = true ; control def : if ( ! semi . open ( args [ 0 ] ) ) { executable : Console . Write ( "\n can't open file {0}\n\n" , args [ 0 ] ) ; executable : Console . Write ( "\n Analyzing file {0}" , args [ 0 ] ) ; executable : Console . Write ( "\n ----------------------------------\n" ) ; executable : while ( semi . getSemi ( ) ) semi . display ( ) ; executable : semi . close ( ) ; opening file "TestCase-eligibleCheck.cs" using declar : using System ; using declar : using System . Collections . Generic ; using declar : using System . Linq ; using declar : using System . Text ; using declar : using CodeAnalysis ; using declar : using myFileSystem ; using declar : using System . IO ; namespace def : namespace myEligibleCheck { class def : class eligibleCheck { function def : public List < string > preCreate ( List < string > sourceFiles ) { data declar : string htmFile ; data declar : List < string > htmFiles = new List < string > ( ) ; data declar : fileSystem myFile = new fileSystem ( ) ; control def : foreach ( string file in sourceFiles ) { data declar : StreamReader reader = myFile . openToRead ( file ) ; executable : if ( reader == null ) continue ; executable : myFile . closeReadFile ( reader ) ; executable : htmFile = Path . GetDirectoryName ( file ) + @"\" + Path . GetFileNameWithoutExtension ( file ) + ".htm" ; control def : if ( ! myFile . ifExist ( htmFile ) ) { data declar : StreamWriter writer = myFile . openToWrite ( htmFile ) ; control def : if ( writer == null ) { executable : Console . WriteLine ( "writer is null" ) ; control def : else { executable : myFile . closeWriteFile ( writer ) ; executable : htmFiles . Add ( htmFile ) ; control def : else { executable : htmFile = "" ; executable : htmFiles . Add ( htmFile ) ; executable : return htmFiles ; function def : public List < string > travers ( string [ ] args ) { data declar : List < string > files1 = TestParser . ProcessCommandline ( args ) ; data declar : List < string > files2 = new List < string > ( ) ; control def : foreach ( string file in files1 ) { executable : if ( Path . GetExtension ( file ) == ".cs" ) files2 . Add ( file ) ; executable : return files2 ; function def : public List < string > coverFiles ( List < string > sourceFiles , List < string > htmFiles ) { data declar : List < string > htmFiles2 = new List < string > ( ) ; data declar : fileSystem myFile = new fileSystem ( ) ; data declar : string tempFile ; data declar : int count = 0 ; control def : foreach ( string htmFile in htmFiles ) { executable : if ( htmFile ! = "" ) htmFiles2 . Add ( htmFile ) ; control def : else { executable : tempFile = Path . GetDirectoryName ( sourceFiles [ count ] ) + @"\" + Path . GetFileNameWithoutExtension ( sourceFiles [ count ] ) + ".htm" ; data declar : StreamWriter writer = myFile . openToWrite ( tempFile ) ; executable : if ( writer == null ) continue ; control def : else { executable : myFile . closeWriteFile ( writer ) ; executable : htmFiles2 . Add ( tempFile ) ; executable : count ++ ; executable : return htmFiles2 ; function def : public List < string > renameFiles ( List < string > sourceFiles , List < string > htmFiles ) { data declar : List < string > htmFiles2 = new List < string > ( ) ; data declar : int count = 0 ; data declar : fileSystem myFile = new fileSystem ( ) ; data declar : string tempFile ; data declar : string time ; control def : foreach ( string htmFile in htmFiles ) { executable : if ( htmFile ! = "" ) htmFiles2 . Add ( htmFile ) ; control def : else { executable : time = DateTime . Now . ToString ( "T" ) . Replace ( ":" , "0" ) ; executable : tempFile = Path . GetDirectoryName ( sourceFiles [ count ] ) + @"\" + Path . GetFileNameWithoutExtension ( sourceFiles [ count ] ) + time + ".htm" ; data declar : StreamWriter writer = myFile . openToWrite ( tempFile ) ; executable : if ( writer == null ) continue ; control def : else { executable : myFile . closeWriteFile ( writer ) ; executable : htmFiles2 . Add ( tempFile ) ; executable : count ++ ; executable : return htmFiles2 ; function def : static void Main ( string [ ] args ) { data declar : eligibleCheck checker = new eligibleCheck ( ) ; data declar : List < string > sourceFiles = checker . travers ( args ) ; data declar : List < string > htmFiles ; data declar : int scount = 0 ; data declar : int fcount = 0 ; executable : htmFiles = checker . preCreate ( sourceFiles ) ; control def : foreach ( string file in htmFiles ) { executable : if ( file ! = "" ) scount ++ ; executable : Console . Write ( "\n success:{0}, fail:{1}" , scount , fcount ) ; executable : scount = 0 ; executable : fcount = 0 ; executable : htmFiles = checker . renameFiles ( sourceFiles , htmFiles ) ; control def : foreach ( string file in htmFiles ) { executable : if ( file ! = "" ) scount ++ ; executable : Console . Write ( "\n success:{0}, fail:{1}" , scount , fcount ) ; opening file "Toker.cs" using declar : using System ; using declar : using System . IO ; using declar : using System . Text ; using declar : using System . Collections ; using declar : using System . Collections . Generic ; namespace def : namespace CStoker { class def : class CToker { data declar : private TextReader ts = null ; data declar : private List < string > tokBuffer = null ; data declar : private string lineRemainder ; executable : private set ; function def : public CToker ( ) { executable : tokBuffer = new List < string > ( ) ; executable : lineCount = 0 ; executable : returnComments = false ; function def : public bool openFile ( string fileName ) { executable : lineCount = 0 ; executable : lineRemainder = "" ; control def : try { executable : ts = new StreamReader ( fileName ) ; control def : catch ( Exception ) { executable : return false ; executable : return true ; function def : public bool openString ( string source ) { executable : lineCount = 0 ; executable : lineRemainder = "" ; control def : try { executable : ts = new StringReader ( source ) ; control def : catch ( Exception ) { executable : return false ; executable : return true ; function def : public void close ( ) { executable : ts . Close ( ) ; function def : void removeReturn ( ref StringBuilder tok ) { control def : for ( int i = 0 ; i < tok . Length ; ++ i ) { executable : if ( tok [ i ] == '\r' ) tok . Remove ( i , 1 ) ; function def : string removeReturn ( string tok ) { data declar : StringBuilder temp = new StringBuilder ( ) ; control def : for ( int i = 0 ; i < tok . Length ; ++ i ) { executable : if ( tok [ i ] ! = '\r' ) temp . Append ( tok [ i ] ) ; executable : return temp . ToString ( ) ; function def : public string readLine ( ) { data declar : StringBuilder temp = new StringBuilder ( ) ; control def : while ( true ) { function declar: int i = ts . Read ( ) ; executable : if ( ( char ) i == '\n' ) lineCount ++ ; control def : if ( i == - 1 ) { function declar: return temp . ToString ( ) ; data declar : char ch = ( char ) i ; executable : temp . Append ( ch ) ; executable : if ( ch == '\n' ) break ; executable : removeReturn ( ref temp ) ; data declar : string outstr = temp . ToString ( ) ; executable : return outstr ; function def : bool getLine ( out string line ) { control def : do { control def : if ( lineRemainder == "" ) { control def : try { function declar: lineRemainder = readLine ( ) ; control def : if ( lineRemainder == null || lineRemainder == "" ) { executable : line = "" ; executable : return false ; control def : catch ( Exception except ) { function declar: line = except . Message . ToString ( ) ; executable : return false ; executable : line = extract ( ref lineRemainder ) ; executable : if ( line == "" ) lineRemainder = lineRemainder + readLine ( ) ; executable : while ( line == "" && tokBuffer . Count == 0 ) ; executable : return true ; function def : string extract ( ref string lineRemainder ) { executable : lineRemainder = lineRemainder . TrimStart ( whiteChars ) ; data declar : int posErr = lineRemainder . IndexOf ( "@\"" ) ; executable : if ( posErr ! = - 1 ) lineRemainder = mapToOldDoubleQuoteStyle ( lineRemainder ) ; data declar : int posCppComm = lineRemainder . IndexOf ( ) ; data declar : int posCComm = lineRemainder . IndexOf ( ) ; data declar : int posDQuote = lineRemainder . IndexOf ( '\"' ) ; data declar : int posSQuote = lineRemainder . IndexOf ( '\'' ) ; executable : for ( int i = 0 ; i < positions . Length ; ++ i ) if ( positions [ i ] == - 1 ) positions [ i ] = Int32 . MaxValue ; executable : Array . Sort ( positions ) ; control def : if ( positions [ 0 ] == Int32 . MaxValue ) { data declar : string retStr = lineRemainder ; executable : lineRemainder = "" ; executable : return retStr ; executable : if ( posCppComm == positions [ 0 ] || posCComm == positions [ 0 ] ) return extractComment ( ref lineRemainder ) ; executable : if ( posDQuote == positions [ 0 ] ) return extractDQuote ( ref lineRemainder ) ; executable : if ( posSQuote == positions [ 0 ] ) return extractSQuote ( ref lineRemainder ) ; executable : throw new Exception ( "extract failed" ) ; function def : string mapToOldDoubleQuoteStyle ( string str ) { data declar : bool foundNewStyle = false ; executable : System . Text . StringBuilder temp = new StringBuilder ( ) ; data declar : int i ; control def : for ( i = 0 ; i < str . Length ; ++ i ) { control def : if ( str [ i ] == '@' ) { executable : foundNewStyle = true ; function declar: temp . Append ( str [ i ] ) ; control def : if ( foundNewStyle ) { executable : if ( str [ i ] == '\\' ) temp . Append ( '\\' ) ; executable : if ( str [ i ] == '"' && str [ i - 1 ] ! = '\\' && str [ i - 1 ] ! = '@' ) break ; executable : for ( int j = i + 1 ; j < str . Length ; ++ j ) temp . Append ( str [ j ] ) ; executable : return temp . ToString ( ) ; function def : string extractDQuote ( ref string lineRemainder ) { data declar : string retStr = "" ; data declar : int pos = lineRemainder . IndexOf ( '\"' ) ; control def : if ( pos == 0 ) { function declar: StringBuilder quote = new StringBuilder ( ) ; executable : quote . Append ( '\"' ) ; control def : for ( int i = 1 ; i < lineRemainder . Length ; ++ i ) { function declar: quote . Append ( lineRemainder [ i ] ) ; control def : if ( lineRemainder [ i ] == '\"' ) { control def : if ( lineRemainder [ i - 1 ] ! = '\\' || lineRemainder [ i - 2 ] == '\\' ) { function declar: tokBuffer . Add ( quote . ToString ( ) ) ; executable : lineRemainder = lineRemainder . Remove ( 0 , i + 1 ) ; executable : return "" ; control def : else { executable : retStr = lineRemainder . Remove ( pos , lineRemainder . Length - pos ) ; executable : lineRemainder = lineRemainder . Remove ( 0 , pos ) ; executable : return retStr ; executable : return retStr ; function def : string extractSQuote ( ref string lineRemainder ) { data declar : string retStr ; data declar : int pos = lineRemainder . IndexOf ( '\'' ) ; control def : if ( pos == 0 ) { function declar: StringBuilder quote = new StringBuilder ( ) ; executable : quote . Append ( '\'' ) ; control def : for ( int i = 1 ; i < lineRemainder . Length ; ++ i ) { function declar: quote . Append ( lineRemainder [ i ] ) ; control def : if ( lineRemainder [ i ] == '\'' ) { control def : if ( lineRemainder [ i - 1 ] ! = '\\' || lineRemainder [ i - 2 ] == '\\' ) { function declar: tokBuffer . Add ( quote . ToString ( ) ) ; executable : lineRemainder = lineRemainder . Remove ( 0 , i + 1 ) ; executable : return "" ; control def : else { executable : retStr = lineRemainder . Remove ( pos , lineRemainder . Length - pos ) ; executable : lineRemainder = lineRemainder . Remove ( 0 , pos ) ; executable : return retStr ; executable : throw new Exception ( "extractSQuote failed" ) ; function def : string extractComment ( ref string lineRemainder ) { data declar : string line ; data declar : int pos = lineRemainder . IndexOf ( ) ; control def : if ( pos == 0 ) { control def : if ( lineRemainder [ lineRemainder . Length - 1 ] == '\n' ) { executable : lineRemainder = lineRemainder . Remove ( lineRemainder . Length - 1 , 1 ) ; executable : tokBuffer . Add ( lineRemainder ) ; executable : lineRemainder = "" ; executable : return "\n" ; control def : else { executable : tokBuffer . Add ( lineRemainder ) ; executable : lineRemainder = "" ; executable : return lineRemainder ; control def : if ( pos > - 1 ) { executable : line = lineRemainder . Remove ( pos , lineRemainder . Length - pos ) . TrimEnd ( WhiteChars ) ; executable : lineRemainder = lineRemainder . Remove ( 0 , pos ) ; executable : return line ; executable : pos = lineRemainder . IndexOf ( ) ; control def : if ( pos > - 1 ) { control def : if ( pos == 0 ) { function declar: eatCComment ( ) ; executable : return "" ; control def : else { data declar : string retStr = lineRemainder . Remove ( pos , lineRemainder . Length - pos ) ; executable : lineRemainder = lineRemainder . Remove ( 0 , pos ) ; executable : return retStr ; executable : line = lineRemainder ; executable : lineRemainder = "" ; executable : return line ; function def : void eatCComment ( ) { data declar : List < char > comment = new List < char > ( ) ; control def : while ( true ) { data declar : int pos = lineRemainder . IndexOf ( "*/" ) ; control def : for ( int i = 0 ; i < lineRemainder . Length ; ++ i ) { executable : if ( pos ! = i ) comment . Add ( lineRemainder [ i ] ) ; control def : else { function declar: comment . Add ( lineRemainder [ i ] ) ; executable : comment . Add ( lineRemainder [ i + 1 ] ) ; data declar : string temp = new string ( comment . ToArray ( ) ) ; executable : tokBuffer . Add ( temp ) ; executable : lineRemainder = lineRemainder . Remove ( 0 , i + 2 ) ; function declar: lineRemainder = ts . ReadLine ( ) ; executable : lineCount ++ ; control def : if ( lineRemainder == null ) { executable : throw new Exception ( "encountered eof while processing comment" ) ; executable : lineRemainder = lineRemainder + "\n" ; executable : lineRemainder = removeReturn ( lineRemainder ) ; function def : bool IsGrammarPunctuation ( char ch ) { executable : if ( ch == '_' ) return false ; executable : if ( Char . IsPunctuation ( ch ) ) return true ; executable : return false ; function def : string eatAscii ( ref string tok ) { data declar : string retStr = tok ; control def : for ( int i = 0 ; i < tok . Length ; ++ i ) { control def : if ( IsGrammarPunctuation ( tok [ i ] ) || Char . IsSymbol ( tok [ i ] ) ) { executable : retStr = tok . Remove ( i , tok . Length - i ) ; executable : tok = tok . Remove ( 0 , i ) ; executable : return retStr ; executable : tok = "" ; executable : return retStr ; function def : string eatPunctuationChar ( ref string tok ) { data declar : string retStr = tok . Remove ( 1 , tok . Length - 1 ) ; executable : tok = tok . Remove ( 0 , 1 ) ; executable : return retStr ; function def : bool fillBuffer ( ) { data declar : string line ; executable : if ( ! this . getLine ( out line ) ) return false ; executable : if ( line == "" ) return ( tokBuffer . Count > 0 ) ; executable : string [ ] toks = line . Split ( delim ) ; control def : foreach ( string tok in toks ) { data declar : string temp = tok ; control def : while ( temp . Length > 0 ) { control def : if ( IsGrammarPunctuation ( temp [ 0 ] ) || Char . IsSymbol ( temp [ 0 ] ) ) { data declar : string punc = this . eatPunctuationChar ( ref temp ) ; executable : tokBuffer . Add ( punc ) ; control def : else { data declar : string ascii = this . eatAscii ( ref temp ) ; executable : tokBuffer . Add ( ascii ) ; executable : return true ; function def : public string getTok ( ) { data declar : string tok = peekNextTok ( ) ; executable : if ( tok ! = "" ) tokBuffer . RemoveAt ( 0 ) ; control def : if ( tok . IndexOf ( '\n' ) == tok . Length - 1 && tok . Length > 1 ) { executable : tok = tok . TrimEnd ( trimChar ) ; executable : tokBuffer . Insert ( 0 , "\n" ) ; executable : if ( returnComments ) return tok ; control def : while ( true ) { executable : if ( tok . Length > 1 && tok [ 0 ] == '/' && ( tok [ 1 ] == '*' || tok [ 1 ] == '/' ) ) tok = getTok ( ) ; executable : return tok ; function def : public string peekNextTok ( ) { executable : if ( tokBuffer . Count == 0 ) if ( ! fillBuffer ( ) ) return "" ; data declar : string tok = ( string ) tokBuffer [ 0 ] ; executable : return tok ; function def : public void pushBack ( string tok ) { executable : tokBuffer . Insert ( 0 , tok ) ; function def : STAThread ] static void Main ( string [ ] args ) { executable : Console . Write ( "\n Testing CToker - Tokenizer " ) ; executable : Console . Write ( "\n ============================\n" ) ; control def : try { function declar: CToker toker = new CToker ( ) ; control def : if ( args . Length == 0 ) { executable : Console . Write ( "\n Please enter name of file to tokenize\n\n" ) ; control def : foreach ( string file in args ) { data declar : string msg1 ; control def : if ( ! toker . openFile ( file ) ) { executable : msg1 = "Can't open file " + file ; executable : Console . Write ( "\n\n {0}" , msg1 ) ; executable : Console . Write ( "\n {0}" , new string ( '-' , msg1 . Length ) ) ; control def : else { executable : msg1 = "Processing file " + file ; executable : Console . Write ( "\n\n {0}" , msg1 ) ; executable : Console . Write ( "\n {0}" , new string ( '-' , msg1 . Length ) ) ; data declar : string tok = "" ; executable : while ( ( tok = toker . getTok ( ) ) ! = "" ) if ( tok ! = "\n" ) Console . Write ( "\n{0}" , tok ) ; function declar: toker . close ( ) ; executable : Console . Write ( "\n" ) ; executable : string [ ] msgs = new string [ 12 ] ; executable : msgs [ 0 ] = "abc" ; executable : msgs [ 11 ] = "-- \"abc def\" --" ; executable : msgs [ 1 ] = "string with double quotes \"first quote\"" + " and \"second quote\" but no more" ; executable : msgs [ 2 ] = "string with single quotes \'1\' and \'2\'" ; executable : msgs [ 3 ] = "string with quotes \"first quote\" and \'2\'" ; executable : msgs [ 4 ] = ; executable : msgs [ 10 ] = @"string with @ \\stuff" ; executable : msgs [ 5 ] = ; executable : msgs [ 6 ] = ; executable : msgs [ 7 ] = ; executable : msgs [ 8 ] = ; executable : msgs [ 9 ] = ; control def : foreach ( string msg in msgs ) { control def : if ( ! toker . openString ( msg ) ) { data declar : string msg2 = "Can't open string for reading" ; executable : Console . Write ( "\n\n {0}" , msg2 ) ; executable : Console . Write ( "\n {0}" , new string ( '-' , msg2 . Length ) ) ; control def : else { data declar : string msg2 = "Processing \"" + msg + "\"" ; executable : Console . Write ( "\n\n {0}" , msg2 ) ; executable : Console . Write ( "\n {0}" , new string ( '-' , msg2 . Length ) ) ; data declar : string tok = "" ; control def : while ( ( tok = toker . getTok ( ) ) ! = "" ) { executable : if ( tok ! = "\n" ) Console . Write ( "\n{0}" , tok ) ; executable : else Console . Write ( "\nnewline" ) ; function declar: toker . close ( ) ; executable : Console . Write ( "\n\n" ) ; control def : catch ( Exception ex ) { executable : Console . Write ( "\n\n token \"{0}\" has embedded newline\n\n" , ex . Message ) ; opening file "TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs" opening file "TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs" opening file "TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs" opening file "AssemblyInfo.cs" using declar : using System . Reflection ; using declar : using System . Runtime . CompilerServices ; using declar : using System . Runtime . InteropServices ;