# Macro Tests
#------------------------------------------------------------------------------
# Macro Definitions
-#% if ( cond, branch1:Block ) {
-# exec_if( cond, branch1 )
-#}
+% if ( cond, branch1:Block ) {
+ exec_if( cond, branch1 )
+}
-#% ifelse ( cond, branch1:Block, branch2:Block ) {
-# exec_if( cond, branch1, branch2 )
-#}
+% ifelse ( cond, branch1:Block, branch2:Block ) {
+ exec_if( cond, branch1, branch2 )
+}
-#% foreach ( lst, fn:Block ) {
-# for_each(fn, lst)
-#}
+% foreach ( lst, fn:Block ) {
+ for_each(fn, lst)
+}
# Macro Uses
-#if (1 == 1)
-#{
-# print("1 Hello, World!")
-#}
-#
-#if (1 == 0)
-#{
-# print("Hello, World!")
-#}
-#
-#ifelse (1 == 1)
-#{
-# print("2 Hello, World!")
-#}{
-# error("Incorrect branch was taken.")
-#}
-#
-#ifelse (1 == 0)
-#{
-# error("Incorrect branch was taken.")
-#}{
-# print("3 Hello, World!")
-#}
+if (1 == 1)
+{
+ print("1 Hello, World!")
+}
+
+if (1 == 0)
+{
+ print("Hello, World!")
+}
+
+ifelse (1 == 1)
+{
+ print("2 Hello, World!")
+}{
+ error("Incorrect branch was taken.")
+}
+
+ifelse (1 == 0)
+{
+ error("Incorrect branch was taken.")
+}{
+ print("3 Hello, World!")
+}
#------------------------------------------------------------------------------
# Collection Access and Iteration Tests
#------------------------------------------------------------------------------
-## Accessing elements of lists, vectors, and strings
-#lst1 = `(4,5,6)
-#print(lst1[0], " Hello, World!")
-#
-#vec1 = [4,5,6]
-#print(vec1[1], " Hello, World!")
-#
-#str1 = "456"
-#print(str1[2], " Hello, World!")
-#
-## Iterating over lists, vectors, and strings
-#lst_foo = `(7,8,9,10)
-#foreach lst_foo { |a|
-# print(a," Hello, World!")
-#}
-#
-#vec_foo = [11,12,13,14,15]
-#foreach vec_foo { |a,b|
-# print(b," Hello, World!")
-#}
-#
-#str_foo = "6789"
-#foreach str_foo { |a|
-# print(1,a," Hello, World!")
-#}
+# Accessing elements of lists, vectors, and strings
+lst1 = `(4,5,6)
+print(lst1[0], " Hello, World!")
+
+vec1 = [4,5,6]
+print(vec1[1], " Hello, World!")
+
+str1 = "456"
+print(str1[2], " Hello, World!")
+
+# Iterating over lists, vectors, and strings
+lst_foo = `(7,8,9,10)
+foreach lst_foo { |a|
+ print(a," Hello, World!")
+}
+
+vec_foo = [11,12,13,14,15]
+foreach vec_foo { |a,b|
+ print(b," Hello, World!")
+}
+
+str_foo = "6789"
+foreach str_foo { |a|
+ print(1,a," Hello, World!")
+}
#------------------------------------------------------------------------------
# Delayed Evaluation
#% force ( prom ) {
# force( prom )
#}
-
+#
#foo = delay nonexistent_var + 1
#nonexistent_var = 19
#assert( typeof(foo) == Block )
if( (argc == 2) && fileExists( argv[1] ) )
{
- //string input_fname(argv[1]);
- //string temp_fname = createTempFileName( input_fname );
- //ifstream input(input_fname.c_str());
- //DLLexer lexer;
- //Token tok;
- //lexer.setInput(&input);
- //while( tok.type() != EOF )
- //{
- // tok = lexer.next();
- //}
- //(void)temp_fname;
-
string input_fname(argv[1]);
string temp_fname = createTempFileName( input_fname );
- (void)temp_fname;
DLParser parser;
- //Scheme* visitor = NULL;
- AST* parse_tree = NULL;
+ Scheme* visitor = NULL;
// Open the input and output files
ifstream input(input_fname.c_str());
- //ofstream output(temp_fname.c_str());
+ ofstream output(temp_fname.c_str());
// Parse the file
parser.setInput(&input);
- parse_tree = parser.parse();
// Translate the AST
- //visitor = _new Scheme( parse_tree );
- //visitor->visit();
+ visitor = _new Scheme( parser.parse() );
+ visitor->visit();
// Write to a temp file
- //output << visitor->str();
- //cout << visitor->str();
- //output.close();
+ output << visitor->str();
+ cout << visitor->str();
+ output.close();
// Compile temp file
- //system(("csc " + temp_fname).c_str());
+ system(("csc " + temp_fname).c_str());
- //// delete temp file
- //remove(temp_fname.c_str());
- //delete visitor;
- delete parse_tree;
+ // delete temp file
+ remove(temp_fname.c_str());
+ delete visitor;
}
else
{