Author: kjs
Date: Fri Feb 22 04:18:20 2008
New Revision: 25984
Modified:
trunk/languages/c99/MAINTAINER
trunk/languages/c99/src/parser/actions.pm
trunk/languages/c99/src/parser/grammar.pg
Log:
[c99] Hello world in C runs on Parrot!
update grammar and actions.pm
add myself to MAINTAINER
Modified: trunk/languages/c99/MAINTAINER
==============================================================================
--- trunk/languages/c99/MAINTAINER (original)
+++ trunk/languages/c99/MAINTAINER Fri Feb 22 04:18:20 2008
@@ -2,3 +2,6 @@
N: Kevin Tew
E: [EMAIL PROTECTED]
+
+N: Klaas-Jan Stol (kjs)
+E: [EMAIL PROTECTED]
Modified: trunk/languages/c99/src/parser/actions.pm
==============================================================================
--- trunk/languages/c99/src/parser/actions.pm (original)
+++ trunk/languages/c99/src/parser/actions.pm Fri Feb 22 04:18:20 2008
@@ -18,10 +18,17 @@
class C99::Grammar::Actions;
method TOP($/) {
- my $past := PAST::Block.new( :blocktype('declaration'), :node( $/ ) );
+ my $past;
for $<external_declaration> {
- $past.push( $( $_ ) );
+ my $fun := $( $_ );
+
+ ## Look for the "main" function, and set that as the result
+ ## object.
+ if $fun.name() eq 'main' {
+ $past := $fun;
+ }
}
+
make $past;
}
@@ -33,6 +40,9 @@
my $past := PAST::Block.new( :blocktype('declaration'), :node($/) );
my $decl := $( $<declarator> );
$past.name( $decl.name() );
+
+ my $body := $( $<compound_statement> );
+ $past.push($body);
make $past;
}
@@ -70,7 +80,8 @@
}
method compound_statement($/) {
- my $past := PAST::Block.new( :blocktype('immediate'), :node($/) );
+ #my $past := PAST::Block.new( :blocktype('immediate'), :node($/) );
+ my $past := PAST::Stmts.new( :node($/) );
for $<block_item> {
$past.push( $($_) );
}
@@ -81,6 +92,10 @@
make $( $/{$key} );
}
+method constant($/, $key) {
+ make $( $/{$key} );
+}
+
method constant_expression($/) {
make $( $<conditional_expression> );
}
@@ -112,7 +127,9 @@
method argument_expression_list($/) {
my $past := PAST::Op.new( :pasttype('call'), :node($/) );
-
+ for $<assignment_expression> {
+ $past.push( $( $_ ) );
+ }
make $past;
}
@@ -121,7 +138,8 @@
for $<postfix_expression_suffix> {
## XXX
my $args := $( $_ );
- $past := PAST::Op.new( $past, $args, :pasttype('call'), :node($/) );
+ $args.unshift($past);
+ $past := $args;
}
make $past;
}
@@ -134,12 +152,18 @@
make $( $/{$key} );
}
-method integer($/) {
+method integer_constant($/) {
make PAST::Val.new( :value( ~$/ ), :returns('Integer'), :node($/) );
}
+method floating_constant($/) {
+ make PAST::Val.new( :value( ~$/ ), :returns('Float'), :node($/) );
+}
+
+
method c_string_literal($/) {
- make PAST::Val.new( :value( ~$/ ), :node($/) );
+ make PAST::Val.new( :value( ~$<string_literal> ), :node($/) );
+ #make PAST::Val.new( :value( ~$/ ), :node($/) );
}
method identifier($/) {
Modified: trunk/languages/c99/src/parser/grammar.pg
==============================================================================
--- trunk/languages/c99/src/parser/grammar.pg (original)
+++ trunk/languages/c99/src/parser/grammar.pg Fri Feb 22 04:18:20 2008
@@ -385,10 +385,10 @@
## A.1.5 Constants
##
token constant {
- | <floating_constant>
- | <integer_constant>
- | <enumeration_constant>
- | <character_constant>
+ | <floating_constant> {*} #= floating_constant
+ | <integer_constant> {*} #= integer_constant
+ | <enumeration_constant> {*} #= enumeration_constant
+ | <character_constant> {*} #= character_constant
}
token integer_constant {
@@ -418,8 +418,11 @@
}
token floating_constant {
+ [
| <decimal_floating_constant>
| <hexadecimal_floating_constant>
+ ]
+ {*}
}
token decimal_floating_constant {
@@ -484,10 +487,12 @@
## A.1.6 String literals
token c_string_literal {
- [L]? \" <s_char>* \"
+ [L]? '"' <string_literal: "> '"'
{*}
}
+##\" <s_char>* \"
+
token s_char { <-["\\\n]> | <escape_sequence> }