Charj : added support for the print and println statements
authorMinas Charalambides <charala1@illinois.edu>
Wed, 2 Jun 2010 02:14:58 +0000 (21:14 -0500)
committerMinas Charalambides <charala1@illinois.edu>
Wed, 2 Jun 2010 02:14:58 +0000 (21:14 -0500)
src/langs/charj/src/charj/translator/Charj.g
src/langs/charj/src/charj/translator/Charj.stg
src/langs/charj/src/charj/translator/CharjASTModifier.g
src/langs/charj/src/charj/translator/CharjEmitter.g
src/langs/charj/src/charj/translator/CharjSemantics.g

index e92556597d2403750f8c1074cc9182ab91b02681..2218a1a513c9e24570c13805873c7d922c2bd4a8 100644 (file)
@@ -54,6 +54,9 @@ tokens {
     ENUM                    = 'enum'            ;
     READONLY                = 'readonly'        ;
 
+    PRINT                   = 'print'           ;
+    PRINTLN                 = 'println'         ;
+
     FOR                     = 'for'             ;
     WHILE                   = 'while'           ;
     IF                      = 'if'              ;
@@ -578,6 +581,10 @@ nonBlockStatement
         ->  ^('embed' STRING_LITERAL EMBED_BLOCK)
     |   expression ';'!
     |   ';' // Preserve empty statements.
+    |   PRINT '(' (expression (',' expression)*)* ')' ';'
+        ->  ^(PRINT expression*)
+    |   PRINTLN '(' (expression (',' expression)*)* ')' ';'
+        ->  ^(PRINTLN expression*)
     ;           
         
 
index 3398b4b634c314eee9b1bbeaddeb886faafbe70d..325c2ec59117a7c0032b23cdcc8a3a46f1cd32b6 100644 (file)
@@ -475,4 +475,14 @@ arguments(exprs) ::=
 <exprs; separator=", ">
 >>
 
+print(exprs) ::=
+<<
+<if(first(exprs))>cout <exprs : { n | \<\< <n> }>;<endif>
+>>
+
+println(exprs) ::=
+<<
+cout<if(first(exprs))> <exprs : { n | \<\< <n> }><else> <endif>\<\< endl;
+>>
+
 
index e1715260a3432205b8d1db64c98397328e617e82..72b812f1aba8282c6d5f378eeb00ed3a5bd6a792 100644 (file)
@@ -307,6 +307,8 @@ nonBlockStatement
     |   ^('delete' qualifiedIdentifier)
     |   ^(EMBED STRING_LITERAL EMBED_BLOCK)
     |   ';' // Empty statement.
+    |   ^(PRINT expression*)
+    |   ^(PRINTLN expression*)
     ;
         
 switchCaseLabel
index 303186017daad95af637fb819380bfb2d7c1b0a6..92d485cedd98915f47c690323b0495c03576a1c8 100644 (file)
@@ -587,6 +587,10 @@ nonBlockStatement
         ->  embed_cc(str={$STRING_LITERAL.text}, blk={$EMBED_BLOCK.text})
     |   ';' // Empty statement.
         -> {%{$start.getText()}}
+    |   ^(PRINT (exprs += expression)*)
+        ->  print(exprs = {$exprs})
+    |   ^(PRINTLN (exprs += expression)*)
+        ->  println(exprs = {$exprs})
     ;
         
 switchCaseLabel
index 6ac3ce6e593effffa8956b91b82fe590938ba52a..6ac5cb500bc6bbeb13747f5296263ff916a2116c 100644 (file)
@@ -446,6 +446,8 @@ nonBlockStatement
     |   ^('delete' qualifiedIdentifier)
     |   ^(EMBED STRING_LITERAL EMBED_BLOCK)
     |   ';' // Empty statement.
+    |   ^(PRINT expression*)
+    |   ^(PRINTLN expression*)
     ;
         
 switchCaseLabel