예제 #1
0
        /// <summary>
        /// Generates the code for a Statement node.
        /// </summary>
        /// <param name="s">The Statement node.</param>
        /// <returns>String containing C# code for Statement s.</returns>
        private string GenerateStatement(Statement s)
        {
            string retstr = String.Empty;
            bool printSemicolon = true;

            retstr += Indent();

            if (0 < s.kids.Count)
            {
                // Jump label prints its own colon, we don't need a semicolon.
                printSemicolon = !(s.kids.Top is JumpLabel);

                foreach (SYMBOL kid in s.kids)
                    retstr += GenerateNode(kid);
            }

            if (printSemicolon)
                retstr += GenerateLine(";");

            return retstr;
        }
예제 #2
0
        /// <summary>
        /// Generates the code for a Statement node.
        /// </summary>
        /// <param name="s">The Statement node.</param>
        /// <returns>String containing C# code for Statement s.</returns>
        private string GenerateStatement(SYMBOL previousSymbol, Statement s)
        {
            string retstr = String.Empty;
            bool printSemicolon = true;
            bool transformToBlock = false;

            if (m_insertCoopTerminationChecks)
            {
                // A non-braced single line do while structure cannot contain multiple statements.
                // So to insert the termination check we change this to a braced control structure instead.
                if (previousSymbol is WhileStatement 
                    || previousSymbol is DoWhileStatement 
                    || previousSymbol is ForLoop)
                {
                    transformToBlock = true;

                    // FIXME: This will be wrongly indented because the previous for/while/dowhile will have already indented.
                    retstr += GenerateIndentedLine("{");

                    retstr += GenerateIndentedLine(m_coopTerminationCheck);
                }
            }

            retstr += Indent();

            if (0 < s.kids.Count)
            {
                // Jump label prints its own colon, we don't need a semicolon.
                printSemicolon = !(s.kids.Top is JumpLabel);

                // If we encounter a lone Ident, we skip it, since that's a C#
                // (MONO) error.
                if (!(s.kids.Top is IdentExpression && 1 == s.kids.Count))
                    foreach (SYMBOL kid in s.kids)
                        retstr += GenerateNode(s, kid);
            }

            if (printSemicolon)
                retstr += GenerateLine(";");

            if (transformToBlock)
            {
                // FIXME: This will be wrongly indented because the for/while/dowhile is currently handling the unindent
                retstr += GenerateIndentedLine("}");
            }

            return retstr;
        }
예제 #3
0
 public  ForLoop (Parser yyp, ForLoopStatement  flsa , Expression  e , ForLoopStatement  flsb , Statement  s ):base(((LSLSyntax
)yyp)){ kids . Add ( flsa );
 kids . Add ( e );
 kids . Add ( flsb );
 if (0< s . kids . Count && s . kids . Top  is  CompoundStatement ) kids . Add ( s . kids . Pop ());
 else  kids . Add ( s );
}
예제 #4
0
        /// <summary>
        /// Generates the code for a Statement node.
        /// </summary>
        /// <param name="s">The Statement node.</param>
        /// <returns>String containing C# code for Statement s.</returns>
        private string GenerateStatement(Statement s)
        {
            string retstr = String.Empty;
            bool printSemicolon = true;

            retstr += Indent();

            if (0 < s.kids.Count)
            {
                // Jump label prints its own colon, we don't need a semicolon.
                printSemicolon = !(s.kids.Top is JumpLabel);

                // If we encounter a lone Ident, we skip it, since that's a C#
                // (MONO) error.
                if (!(s.kids.Top is IdentExpression && 1 == s.kids.Count))
                    foreach (SYMBOL kid in s.kids)
                        retstr += GenerateNode(kid);
            }

            if (printSemicolon)
                retstr += GenerateLine(";");

            return retstr;
        }
예제 #5
0
 public  IfStatement (Parser yyp, SYMBOL  s , Statement  ifs , Statement  es ):base(((LSLSyntax
)yyp)){ kids . Add ( s );
 AddStatement ( ifs );
 if (0< es . kids . Count && es . kids . Top  is  IfStatement ) kids . Add ( es . kids . Pop ());
 else  AddStatement ( es );
}
예제 #6
0
 public  DoWhileStatement (Parser yyp, SYMBOL  s , Statement  st ):base(((LSLSyntax
)yyp)){ if (0< st . kids . Count && st . kids . Top  is  CompoundStatement ) kids . Add ( st . kids . Pop ());
 else  kids . Add ( st );
 kids . Add ( s );
}
예제 #7
0
 public  IfStatement (Parser yyp, SYMBOL  s , Statement  ifs ):base(((LSLSyntax
)yyp)){ kids . Add ( s );
 AddStatement ( ifs );
}
예제 #8
0
 private  void  AddStatement ( Statement  s ){ if (0< s . kids . Count && s . kids . Top  is  CompoundStatement ) kids . Add ( s . kids . Pop ());
 else  kids . Add ( s );
}
예제 #9
0
 public  StatementList (Parser yyp, StatementList  sl , Statement  s ):base(((LSLSyntax
)yyp)){ while (0< sl . kids . Count ) kids . Add ( sl . kids . Pop ());
 AddStatement ( s );
}
예제 #10
0
 public  StatementList (Parser yyp, Statement  s ):base(((LSLSyntax
)yyp)){ AddStatement ( s );
}
예제 #11
0
 private  void  AddStatement ( Statement  s ){ if ( s . kids . Top  is  IfStatement || s . kids . Top  is  WhileStatement || s . kids . Top  is  DoWhileStatement || s . kids . Top  is  ForLoop ) kids . Add ( s . kids . Pop ());
 else  kids . Add ( s );
}