Browse files

[cardinal] add 'and' and 'or' operators.

+ set cmdline banner+prompt (initial, just to get a ruby feel)

git-svn-id: https://svn.parrot.org/parrot/trunk/languages/cardinal@25498 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent 19073fd commit 65e22725539e17d2ac348a7ce016ed7bb7d92c6b @kjs kjs committed Feb 4, 2008
Showing with 24 additions and 1 deletion.
  1. +3 −0 cardinal.pir
  2. +14 −1 src/parser/actions.pm
  3. +7 −0 src/parser/grammar.pg
View
3 cardinal.pir
@@ -46,6 +46,9 @@ object.
$P1.'parsegrammar'('cardinal::Grammar')
$P1.'parseactions'('cardinal::Grammar::Actions')
+ $P1.'commandline_banner'("Cardinal - Ruby for the Parrot VM\n\n")
+ $P1.'commandline_prompt'('irb(main):001:0>')
+
## create a list of END blocks to be run
$P0 = new 'List'
set_hll_global ['cardinal'], '@?END_BLOCKS', $P0
View
15 src/parser/actions.pm
@@ -63,7 +63,20 @@ method stmt_mod($/) {
}
-method expr($/, $key) {
+method expr($/) {
+ my $past := $( $<basic_expr> );
+ if $<expr> {
+ my $op;
+ if ~$<op>[0] eq 'and' { $op := 'if'; }
+ else { $op := 'unless'; }
+ make PAST::Op.new( $past, $( $<expr>[0] ), :pasttype($op), :node($/) );
+ }
+ else {
+ make $past;
+ }
+}
+
+method basic_expr($/, $key) {
make $( $/{$key} );
}
View
7 src/parser/grammar.pg
@@ -52,7 +52,14 @@ rule stmt_mod {
{*}
}
+
rule expr {
+ <basic_expr> [$<op>=['and'|'or'] <expr>]?
+ {*}
+}
+
+
+rule basic_expr {
| <command> {*} #= command
| <arg> {*} #= arg
| <assignment> {*} #= assignment

0 comments on commit 65e2272

Please sign in to comment.