Author: bernhard
Date: Fri Mar 17 09:49:10 2006
New Revision: 11917
Modified:
trunk/languages/bc/grammar/antlr_2/antlr_past2pir_past.g
trunk/languages/bc/grammar/antlr_3/AntlrPast2PirPast.java
trunk/languages/bc/grammar/antlr_3/BcParser.java
trunk/languages/bc/grammar/antlr_3/BcParserLexer.java
trunk/languages/bc/grammar/antlr_3/antlr_past2pir_past.g
trunk/languages/bc/grammar/antlr_3/bc.g
trunk/languages/bc/t/basic.t
Log:
Switch to ANTLR3 ea8.
Modified: trunk/languages/bc/grammar/antlr_2/antlr_past2pir_past.g
==============================================================================
--- trunk/languages/bc/grammar/antlr_2/antlr_past2pir_past.g (original)
+++ trunk/languages/bc/grammar/antlr_2/antlr_past2pir_past.g Fri Mar 17
09:49:10 2006
@@ -1,4 +1,4 @@
-// Copyright: 2005 The Perl Foundation. All Rights Reserved.
+// Copyright: 2005-2006 The Perl Foundation. All Rights Reserved.
// $Id$
header "AntlrPast2PirPastTreeWalker.__init__"
@@ -43,7 +43,7 @@
{
pir_before = """
.local pmc stmts_children
-stmts_children = new PerlArray
+stmts_children = new .PerlArray
#"""
pir_after = """
.local pmc stmts
@@ -68,7 +68,7 @@
self.reg = self.reg + 10;
pir = """
$P%d = new 'PAST::Stmt'
- $P%d = new PerlArray
+ $P%d = new .PerlArray
push $P%d, $P%d
$P%d.set_node('1', 1 ,$P%d)
@@ -93,7 +93,7 @@
self.reg = self.reg + 10;
pir = """
$P%d = new 'PAST::Exp'
- $P%d = new PerlArray
+ $P%d = new .PerlArray
push $P%d, $P%d
$P%d.set_node('1', 1, $P%d)
@@ -114,7 +114,7 @@
self.reg = self.reg + 10;
pir = """
$P%d = new 'PAST::Exp'
- $P%d = new PerlArray
+ $P%d = new .PerlArray
push $P%d, $P%d
$P%d.set_node('1', 1, $P%d)
@@ -135,7 +135,7 @@
self.reg = self.reg + 10;
pir = """
$P%d = new 'PAST::Exp'
- $P%d = new PerlArray
+ $P%d = new .PerlArray
push $P%d, $P%d
$P%d.set_node('1', 1, $P%d)
@@ -160,7 +160,7 @@
self.reg = self.reg + 10;
pir = """
$P%d = new 'PAST::Op'
- $P%d = new PerlArray
+ $P%d = new .PerlArray
push $P%d, $P%d
$P%d.set_node('1', 1, 'print' ,$P%d)
Modified: trunk/languages/bc/grammar/antlr_3/AntlrPast2PirPast.java
==============================================================================
--- trunk/languages/bc/grammar/antlr_3/AntlrPast2PirPast.java (original)
+++ trunk/languages/bc/grammar/antlr_3/AntlrPast2PirPast.java Fri Mar 17
09:49:10 2006
@@ -1,4 +1,4 @@
-// $ANTLR 3.0ea7 grammar/antlr_3/antlr_past2pir_past.g 2006-02-23 21:51:43
+// $ANTLR 3.0ea8 grammar/antlr_3/antlr_past2pir_past.g 2006-03-17 18:45:47
import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;import java.util.Stack;
@@ -7,11 +7,13 @@
public class AntlrPast2PirPast extends TreeParser {
public static final String[] tokenNames = new String[] {
- "<invalid>", "<EOR>", "<DOWN>", "<UP>", "PROGRAM", "INT",
"ML_COMMENT", "WS"
+ "<invalid>", "<EOR>", "<DOWN>", "<UP>", "PROGRAM", "UNARY_MINUS",
"INT", "ML_COMMENT", "WS", "\'-\'", "\'quit\'"
};
- public static final int INT=5;
- public static final int WS=7;
- public static final int ML_COMMENT=6;
+ public static final int UNARY_MINUS=5;
+ public static final int INT=6;
+ public static final int EOF=-1;
+ public static final int WS=8;
+ public static final int ML_COMMENT=7;
public static final int PROGRAM=4;
public AntlrPast2PirPast(TreeNodeStream input) {
super(input);
@@ -21,21 +23,18 @@
public String[] getTokenNames() { return tokenNames; }
+ int asdf = 200;
+
// $ANTLR start gen_pir_past
// grammar/antlr_3/antlr_past2pir_past.g:20:1: gen_pir_past : ^( PROGRAM (
expr )+ ) ;
public void gen_pir_past() throws RecognitionException {
-
-
-
-
try {
// grammar/antlr_3/antlr_past2pir_past.g:22:3: ( ^( PROGRAM ( expr
)+ ) )
// grammar/antlr_3/antlr_past2pir_past.g:22:3: ^( PROGRAM ( expr
)+ )
{
-
String pirBefore = ""
+ "#!/usr/bin/env parrot" + "\n"
+ "\n"
@@ -48,17 +47,14 @@
+ " load_bytecode 'languages/punie/lib/POST.pir'" + "\n"
+ "\n"
+ " .local pmc stmts_children" + "\n"
- + " stmts_children = new PerlArray" + "\n"
+ + " stmts_children = new .PerlArray" + "\n"
;
System.out.println( pirBefore );
+ match(input,PROGRAM,FOLLOW_PROGRAM_in_gen_pir_past62);
-
- match(input,PROGRAM,FOLLOW_PROGRAM_in_gen_pir_past62);
-
- match(input, Token.DOWN, null);
-
+ match(input, Token.DOWN, null);
// grammar/antlr_3/antlr_past2pir_past.g:40:15: ( expr )+
int cnt1=0;
loop1:
@@ -74,7 +70,6 @@
case 1 :
// grammar/antlr_3/antlr_past2pir_past.g:40:15: expr
{
-
following.push(FOLLOW_expr_in_gen_pir_past64);
expr();
following.pop();
@@ -93,8 +88,7 @@
} while (true);
- match(input, Token.UP, null);
-
+ match(input, Token.UP, null);
String pirAfter = ""
+ "# entering gen_pir_past" + "\n"
@@ -185,32 +179,25 @@
recover(input,re);
}
finally {
-
-
}
-
+ return ;
}
// $ANTLR end gen_pir_past
-
public static class expr_int_1_return extends TreeRuleReturnScope {
};
// $ANTLR start expr_int_1
// grammar/antlr_3/antlr_past2pir_past.g:124:1: expr_int_1 : INT ;
public expr_int_1_return expr_int_1() throws RecognitionException {
-
expr_int_1_return retval = new expr_int_1_return();
- retval.start = (CommonTree)input.LT(1);
-
-
+ retval.start = input.LT(1);
try {
// grammar/antlr_3/antlr_past2pir_past.g:125:5: ( INT )
// grammar/antlr_3/antlr_past2pir_past.g:125:5: INT
{
-
- match(input,INT,FOLLOW_INT_in_expr_int_186);
+ match(input,INT,FOLLOW_INT_in_expr_int_186);
}
@@ -220,23 +207,17 @@
recover(input,re);
}
finally {
-
- retval.stop = (CommonTree)input.LT(-1);
+ retval.stop = input.LT(-1);
}
-
return retval;
-
}
// $ANTLR end expr_int_1
-
// $ANTLR start expr
// grammar/antlr_3/antlr_past2pir_past.g:129:1: expr returns [String reg]
: expr_int_1 ;
public String expr() throws RecognitionException {
-
String reg;
-
expr_int_1_return expr_int_11 = null;
@@ -247,13 +228,11 @@
// grammar/antlr_3/antlr_past2pir_past.g:134:5: ( expr_int_1 )
// grammar/antlr_3/antlr_past2pir_past.g:134:5: expr_int_1
{
-
following.push(FOLLOW_expr_int_1_in_expr113);
expr_int_11=expr_int_1();
following.pop();
-
String pir = ""
+ "# entering expr" + "\n"
+ ".local pmc " + reg + "\n"
@@ -262,19 +241,19 @@
+ reg + ".valtype( 'num' )" + "\n"
+ "# leaving expr" + "\n"
+ " $P20 = new 'PAST::Exp' " + "\n"
- + " $P21 = new PerlArray " + "\n"
+ + " $P21 = new .PerlArray " + "\n"
+ " push $P21, " + reg + " \n"
+ " $P20.set_node('1', 1, $P21) " + "\n"
+ " $P30 = new 'PAST::Op' " + "\n"
- + " $P31 = new PerlArray " + "\n"
+ + " $P31 = new .PerlArray " + "\n"
+ " push $P31, $P20 " + "\n"
+ " $P30.set_node('1', 1, 'print' ,$P31) " + "\n"
+ " $P40 = new 'PAST::Exp' " + "\n"
- + " $P41 = new PerlArray " + "\n"
+ + " $P41 = new .PerlArray " + "\n"
+ " push $P41, $P30 " + "\n"
+ " $P40.set_node('1', 1, $P41) " + "\n"
+ " $P50 = new 'PAST::Stmt' " + "\n"
- + " $P51 = new PerlArray " + "\n"
+ + " $P51 = new .PerlArray " + "\n"
+ " push $P51, $P40 " + "\n"
+ " $P50.set_node('1', 1 ,$P51) " + "\n"
+ " push stmts_children, $P50 " + "\n"
@@ -282,19 +261,19 @@
+ " $P60.set_node( '1', 0, '\\n' ) " + "\n"
+ " $P60.valtype( 'strqq' ) " + "\n"
+ " $P70 = new 'PAST::Exp' " + "\n"
- + " $P71 = new PerlArray " + "\n"
+ + " $P71 = new .PerlArray " + "\n"
+ " push $P71, $P60 " + "\n"
+ " $P70.set_node('1', 1, $P71) " + "\n"
+ " $P80 = new 'PAST::Op' " + "\n"
- + " $P81 = new PerlArray " + "\n"
+ + " $P81 = new .PerlArray " + "\n"
+ " push $P81, $P70 " + "\n"
+ " $P80.set_node('1', 1, 'print' ,$P81) " + "\n"
+ " $P90 = new 'PAST::Exp' " + "\n"
- + " $P91 = new PerlArray " + "\n"
+ + " $P91 = new .PerlArray " + "\n"
+ " push $P91, $P80 " + "\n"
+ " $P90.set_node('1', 1, $P91) " + "\n"
+ " $P100 = new 'PAST::Stmt' " + "\n"
- + " $P101 = new PerlArray " + "\n"
+ + " $P101 = new .PerlArray " + "\n"
+ " push $P101, $P90 " + "\n"
+ " $P100.set_node('1', 1 ,$P101) " + "\n"
+ " push stmts_children, $P100 " + "\n"
@@ -311,21 +290,17 @@
recover(input,re);
}
finally {
-
-
}
-
return reg;
-
}
// $ANTLR end expr
- public static final BitSet FOLLOW_PROGRAM_in_gen_pir_past62 = new
BitSet(new long[]{4L});
- public static final BitSet FOLLOW_expr_in_gen_pir_past64 = new BitSet(new
long[]{40L});
- public static final BitSet FOLLOW_INT_in_expr_int_186 = new BitSet(new
long[]{2L});
- public static final BitSet FOLLOW_expr_int_1_in_expr113 = new BitSet(new
long[]{2L});
+ public static final BitSet FOLLOW_PROGRAM_in_gen_pir_past62 = new
BitSet(new long[]{0x0000000000000004L});
+ public static final BitSet FOLLOW_expr_in_gen_pir_past64 = new BitSet(new
long[]{0x0000000000000048L});
+ public static final BitSet FOLLOW_INT_in_expr_int_186 = new BitSet(new
long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_expr_int_1_in_expr113 = new BitSet(new
long[]{0x0000000000000002L});
}
\ No newline at end of file
Modified: trunk/languages/bc/grammar/antlr_3/BcParser.java
==============================================================================
--- trunk/languages/bc/grammar/antlr_3/BcParser.java (original)
+++ trunk/languages/bc/grammar/antlr_3/BcParser.java Fri Mar 17 09:49:10 2006
@@ -1,4 +1,4 @@
-// $ANTLR 3.0ea7 grammar/antlr_3/bc.g 2006-02-23 21:51:42
+// $ANTLR 3.0ea8 grammar/antlr_3/bc.g 2006-03-17 18:45:45
import org.antlr.runtime.*;
import java.util.Stack;
@@ -10,11 +10,13 @@
public class BcParser extends Parser {
public static final String[] tokenNames = new String[] {
- "<invalid>", "<EOR>", "<DOWN>", "<UP>", "PROGRAM", "INT",
"ML_COMMENT", "WS", "\'quit\'"
+ "<invalid>", "<EOR>", "<DOWN>", "<UP>", "PROGRAM", "UNARY_MINUS",
"INT", "ML_COMMENT", "WS", "\'-\'", "\'quit\'"
};
- public static final int INT=5;
- public static final int WS=7;
- public static final int ML_COMMENT=6;
+ public static final int UNARY_MINUS=5;
+ public static final int INT=6;
+ public static final int WS=8;
+ public static final int EOF=-1;
+ public static final int ML_COMMENT=7;
public static final int PROGRAM=4;
public BcParser(TokenStream input) {
super(input);
@@ -33,22 +35,19 @@
public String[] getTokenNames() { return tokenNames; }
-
- public static class program_return extends RuleReturnScope {
+ public static class program_return extends ParserRuleReturnScope {
CommonTree tree;
public Object getTree() { return tree; }
};
// $ANTLR start program
- // grammar/antlr_3/bc.g:21:1: program : input_item quit -> ^( PROGRAM
input_item ) ;
+ // grammar/antlr_3/bc.g:22:1: program : input_item quit -> ^( PROGRAM
input_item ) ;
public program_return program() throws RecognitionException {
-
program_return retval = new program_return();
- retval.start = (Token)input.LT(1);
+ retval.start = input.LT(1);
CommonTree root_0 = null;
-
input_item_return input_item1 = null;
quit_return quit2 = null;
@@ -57,32 +56,27 @@
List list_input_item=new ArrayList();
try {
- // grammar/antlr_3/bc.g:22:5: ( input_item quit -> ^( PROGRAM
input_item ) )
- // grammar/antlr_3/bc.g:22:5: input_item quit
+ // grammar/antlr_3/bc.g:23:5: ( input_item quit -> ^( PROGRAM
input_item ) )
+ // grammar/antlr_3/bc.g:23:5: input_item quit
{
-
- following.push(FOLLOW_input_item_in_program61);
+ following.push(FOLLOW_input_item_in_program66);
input_item1=input_item();
following.pop();
list_input_item.add(input_item1.tree);
-
- following.push(FOLLOW_quit_in_program63);
+ following.push(FOLLOW_quit_in_program68);
quit2=quit();
following.pop();
list_quit.add(quit2.tree);
-
// AST REWRITE
- if ( list_input_item.size()!=1 ) throw new
RuntimeException("element input_item length="+list_input_item.size()+" != 1");
-
int i_0 = 0;
retval.tree = root_0;
root_0 = (CommonTree)adaptor.nil();
- // 22:21: -> ^( PROGRAM input_item )
+ // 23:21: -> ^( PROGRAM input_item )
{
- // grammar/antlr_3/bc.g:22:24: ^( PROGRAM input_item )
+ // grammar/antlr_3/bc.g:23:24: ^( PROGRAM input_item )
{
CommonTree root_1 = (CommonTree)adaptor.nil();
root_1 =
(CommonTree)adaptor.becomeRoot(adaptor.create(PROGRAM, "PROGRAM"), root_1);
@@ -95,6 +89,7 @@
}
+
}
}
@@ -103,65 +98,59 @@
recover(input,re);
}
finally {
-
- retval.stop = (Token)input.LT(-1);
- retval.tree = root_0;
-
+ retval.stop = input.LT(-1);
+ retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
+ adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
}
-
return retval;
-
}
// $ANTLR end program
-
- public static class input_item_return extends RuleReturnScope {
+ public static class input_item_return extends ParserRuleReturnScope {
CommonTree tree;
public Object getTree() { return tree; }
};
// $ANTLR start input_item
- // grammar/antlr_3/bc.g:25:1: input_item : ( INT )+ ;
+ // grammar/antlr_3/bc.g:26:1: input_item : ( expression )+ ;
public input_item_return input_item() throws RecognitionException {
-
input_item_return retval = new input_item_return();
- retval.start = (Token)input.LT(1);
+ retval.start = input.LT(1);
CommonTree root_0 = null;
- Token INT3=null;
+ expression_return expression3 = null;
+
- CommonTree INT3_tree=null;
try {
- // grammar/antlr_3/bc.g:26:5: ( ( INT )+ )
- // grammar/antlr_3/bc.g:26:5: ( INT )+
+ // grammar/antlr_3/bc.g:27:5: ( ( expression )+ )
+ // grammar/antlr_3/bc.g:27:5: ( expression )+
{
root_0 = (CommonTree)adaptor.nil();
-
- // grammar/antlr_3/bc.g:26:5: ( INT )+
+ // grammar/antlr_3/bc.g:27:5: ( expression )+
int cnt1=0;
loop1:
do {
int alt1=2;
int LA1_0 = input.LA(1);
- if ( LA1_0==INT ) {
+ if ( LA1_0==INT||LA1_0==9 ) {
alt1=1;
}
switch (alt1) {
case 1 :
- // grammar/antlr_3/bc.g:26:5: INT
+ // grammar/antlr_3/bc.g:27:5: expression
{
CommonTree root_1 = (CommonTree)adaptor.nil();
+ following.push(FOLLOW_expression_in_input_item91);
+ expression3=expression();
+ following.pop();
- INT3=(Token)input.LT(1);
- match(input,INT,FOLLOW_INT_in_input_item86);
- INT3_tree = (CommonTree)adaptor.create(INT3);
- adaptor.addChild(root_1, INT3_tree);
+ adaptor.addChild(root_1, expression3.tree);
adaptor.addChild(root_0, root_1);
@@ -186,47 +175,145 @@
recover(input,re);
}
finally {
-
- retval.stop = (Token)input.LT(-1);
- retval.tree = root_0;
-
+ retval.stop = input.LT(-1);
+ retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
+ adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
}
-
return retval;
-
}
// $ANTLR end input_item
+ public static class expression_return extends ParserRuleReturnScope {
+ CommonTree tree;
+ public Object getTree() { return tree; }
+ };
+
+ // $ANTLR start expression
+ // grammar/antlr_3/bc.g:30:1: expression : ( INT | '-' expression -> ^(
UNARY_MINUS expression ) );
+ public expression_return expression() throws RecognitionException {
+ expression_return retval = new expression_return();
+ retval.start = input.LT(1);
+
+ CommonTree root_0 = null;
+
+ Token INT4=null;
+ Token char_literal5=null;
+ expression_return expression6 = null;
+
+ List list_expression=new ArrayList();
+ List list_9=new ArrayList();
+ CommonTree INT4_tree=null;
+ CommonTree char_literal5_tree=null;
+
+ try {
+ // grammar/antlr_3/bc.g:31:5: ( INT | '-' expression -> ^(
UNARY_MINUS expression ) )
+ int alt2=2;
+ int LA2_0 = input.LA(1);
+ if ( LA2_0==INT ) {
+ alt2=1;
+ }
+ else if ( LA2_0==9 ) {
+ alt2=2;
+ }
+ else {
+ NoViableAltException nvae =
+ new NoViableAltException("30:1: expression : ( INT | \'-\'
expression -> ^( UNARY_MINUS expression ) );", 2, 0, input);
+
+ throw nvae;
+ }
+ switch (alt2) {
+ case 1 :
+ // grammar/antlr_3/bc.g:31:5: INT
+ {
+ root_0 = (CommonTree)adaptor.nil();
+
+ INT4=(Token)input.LT(1);
+ match(input,INT,FOLLOW_INT_in_expression106);
+ INT4_tree = (CommonTree)adaptor.create(INT4);
+ adaptor.addChild(root_0, INT4_tree);
+
+
+ }
+ break;
+ case 2 :
+ // grammar/antlr_3/bc.g:32:5: '-' expression
+ {
+ char_literal5=(Token)input.LT(1);
+ match(input,9,FOLLOW_9_in_expression112);
+ list_9.add(char_literal5);
+
+ following.push(FOLLOW_expression_in_expression114);
+ expression6=expression();
+ following.pop();
+
+ list_expression.add(expression6.tree);
+
+ // AST REWRITE
+ int i_0 = 0;
+ retval.tree = root_0;
+ root_0 = (CommonTree)adaptor.nil();
+ // 32:20: -> ^( UNARY_MINUS expression )
+ {
+ // grammar/antlr_3/bc.g:32:23: ^( UNARY_MINUS
expression )
+ {
+ CommonTree root_1 = (CommonTree)adaptor.nil();
+ root_1 =
(CommonTree)adaptor.becomeRoot(adaptor.create(UNARY_MINUS, "UNARY_MINUS"),
root_1);
+
+ adaptor.addChild(root_1, list_expression.get(i_0));
+
+ adaptor.addChild(root_0, root_1);
+ }
+
+ }
+
+
+
+ }
+ break;
+
+ }
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ retval.stop = input.LT(-1);
+ retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
+ adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
+ }
+ return retval;
+ }
+ // $ANTLR end expression
- public static class quit_return extends RuleReturnScope {
+ public static class quit_return extends ParserRuleReturnScope {
CommonTree tree;
public Object getTree() { return tree; }
};
// $ANTLR start quit
- // grammar/antlr_3/bc.g:34:1: quit : 'quit' ;
+ // grammar/antlr_3/bc.g:40:1: quit : 'quit' ;
public quit_return quit() throws RecognitionException {
-
quit_return retval = new quit_return();
- retval.start = (Token)input.LT(1);
+ retval.start = input.LT(1);
CommonTree root_0 = null;
- Token string_literal4=null;
+ Token string_literal7=null;
- CommonTree string_literal4_tree=null;
+ CommonTree string_literal7_tree=null;
try {
- // grammar/antlr_3/bc.g:35:5: ( 'quit' )
- // grammar/antlr_3/bc.g:35:5: 'quit'
+ // grammar/antlr_3/bc.g:41:5: ( 'quit' )
+ // grammar/antlr_3/bc.g:41:5: 'quit'
{
root_0 = (CommonTree)adaptor.nil();
+ string_literal7=(Token)input.LT(1);
+ match(input,10,FOLLOW_10_in_quit154);
+ string_literal7_tree = (CommonTree)adaptor.create(string_literal7);
+ adaptor.addChild(root_0, string_literal7_tree);
- string_literal4=(Token)input.LT(1);
- match(input,8,FOLLOW_8_in_quit118);
- string_literal4_tree = (CommonTree)adaptor.create(string_literal4);
- adaptor.addChild(root_0, string_literal4_tree);
}
@@ -236,23 +323,23 @@
recover(input,re);
}
finally {
-
- retval.stop = (Token)input.LT(-1);
- retval.tree = root_0;
-
+ retval.stop = input.LT(-1);
+ retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
+ adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
}
-
return retval;
-
}
// $ANTLR end quit
- public static final BitSet FOLLOW_input_item_in_program61 = new BitSet(new
long[]{256L});
- public static final BitSet FOLLOW_quit_in_program63 = new BitSet(new
long[]{2L});
- public static final BitSet FOLLOW_INT_in_input_item86 = new BitSet(new
long[]{34L});
- public static final BitSet FOLLOW_8_in_quit118 = new BitSet(new
long[]{2L});
+ public static final BitSet FOLLOW_input_item_in_program66 = new BitSet(new
long[]{0x0000000000000400L});
+ public static final BitSet FOLLOW_quit_in_program68 = new BitSet(new
long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_expression_in_input_item91 = new
BitSet(new long[]{0x0000000000000242L});
+ public static final BitSet FOLLOW_INT_in_expression106 = new BitSet(new
long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_9_in_expression112 = new BitSet(new
long[]{0x0000000000000240L});
+ public static final BitSet FOLLOW_expression_in_expression114 = new
BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_10_in_quit154 = new BitSet(new
long[]{0x0000000000000002L});
}
\ No newline at end of file
Modified: trunk/languages/bc/grammar/antlr_3/BcParserLexer.java
==============================================================================
--- trunk/languages/bc/grammar/antlr_3/BcParserLexer.java (original)
+++ trunk/languages/bc/grammar/antlr_3/BcParserLexer.java Fri Mar 17
09:49:10 2006
@@ -1,4 +1,4 @@
-// $ANTLR 3.0ea7 grammar/antlr_3/BcParser.lexer.g 2006-02-23 21:51:42
+// $ANTLR 3.0ea8 grammar/antlr_3/bc.g 2006-03-17 18:45:45
import org.antlr.runtime.*;
import java.util.Stack;
@@ -6,225 +6,255 @@
import java.util.ArrayList;
public class BcParserLexer extends Lexer {
- public static final int INT=5;
- public static final int WS=7;
- public static final int ML_COMMENT=6;
- public static final int T8=8;
+ public static final int T10=10;
+ public static final int UNARY_MINUS=5;
+ public static final int T9=9;
+ public static final int INT=6;
+ public static final int EOF=-1;
+ public static final int WS=8;
+ public static final int Tokens=11;
+ public static final int ML_COMMENT=7;
public static final int PROGRAM=4;
+ public BcParserLexer() {;}
public BcParserLexer(CharStream input) {
super(input);
}
- public Token nextToken() {
- token=null;
-retry:
- while (true) {
- if ( input.LA(1)==CharStream.EOF ) {
- return Token.EOF_TOKEN;
- }
- try {
- mTokens();
- break retry;
- }
- catch (RecognitionException re) {
- reportError(re);
- recover(re);
+
+
+ // $ANTLR start T9
+ public void mT9() throws RecognitionException {
+ try {
+ int type = T9;
+ int start = getCharIndex();
+ int line = getLine();
+ int charPosition = getCharPositionInLine();
+ int channel = Token.DEFAULT_CHANNEL;
+ // grammar/antlr_3/bc.g:3:6: ( '-' )
+ // grammar/antlr_3/bc.g:3:6: '-'
+ {
+ match('-');
+
}
+
+ if ( token==null )
{emit(type,line,charPosition,channel,start,getCharIndex()-1);}
+ }
+ finally {
}
- return token;
}
+ // $ANTLR end T9
- public void mT8() throws RecognitionException {
- int type = T8;
- int start = getCharIndex();
- int line = getLine();
- int charPosition = getCharPositionInLine();
- int channel = Token.DEFAULT_CHANNEL;
- // grammar/antlr_3/BcParser.lexer.g:3:6: ( 'quit' )
- // grammar/antlr_3/BcParser.lexer.g:3:6: 'quit'
- {
- match("quit");
+ // $ANTLR start T10
+ public void mT10() throws RecognitionException {
+ try {
+ int type = T10;
+ int start = getCharIndex();
+ int line = getLine();
+ int charPosition = getCharPositionInLine();
+ int channel = Token.DEFAULT_CHANNEL;
+ // grammar/antlr_3/bc.g:4:7: ( 'quit' )
+ // grammar/antlr_3/bc.g:4:7: 'quit'
+ {
+ match("quit");
- }
+ }
- if ( token==null )
{emit(type,line,charPosition,channel,start,getCharIndex()-1);}
+ if ( token==null )
{emit(type,line,charPosition,channel,start,getCharIndex()-1);}
+ }
+ finally {
+ }
}
+ // $ANTLR end T10
+
+ // $ANTLR start INT
public void mINT() throws RecognitionException {
- int type = INT;
- int start = getCharIndex();
- int line = getLine();
- int charPosition = getCharPositionInLine();
- int channel = Token.DEFAULT_CHANNEL;
- // grammar/antlr_3/BcParser.lexer.g:5:7: ( ( '0' .. '9' )+ )
- // grammar/antlr_3/BcParser.lexer.g:5:7: ( '0' .. '9' )+
- {
-
- // grammar/antlr_3/BcParser.lexer.g:5:7: ( '0' .. '9' )+
- int cnt1=0;
- loop1:
- do {
- int alt1=2;
- int LA1_0 = input.LA(1);
- if ( (LA1_0>='0' && LA1_0<='9') ) {
- alt1=1;
- }
+ try {
+ int type = INT;
+ int start = getCharIndex();
+ int line = getLine();
+ int charPosition = getCharPositionInLine();
+ int channel = Token.DEFAULT_CHANNEL;
+ // grammar/antlr_3/bc.g:36:4: ( ( '0' .. '9' )+ )
+ // grammar/antlr_3/bc.g:36:4: ( '0' .. '9' )+
+ {
+ // grammar/antlr_3/bc.g:36:4: ( '0' .. '9' )+
+ int cnt1=0;
+ loop1:
+ do {
+ int alt1=2;
+ int LA1_0 = input.LA(1);
+ if ( (LA1_0>='0' && LA1_0<='9') ) {
+ alt1=1;
+ }
- switch (alt1) {
- case 1 :
- // grammar/antlr_3/BcParser.lexer.g:5:9: '0' .. '9'
- {
-
- matchRange('0','9');
-
- }
- break;
-
- default :
- if ( cnt1 >= 1 ) break loop1;
- EarlyExitException eee =
- new EarlyExitException(1, input);
- throw eee;
- }
- cnt1++;
- } while (true);
+ switch (alt1) {
+ case 1 :
+ // grammar/antlr_3/bc.g:36:5: '0' .. '9'
+ {
+ matchRange('0','9');
+
+ }
+ break;
+
+ default :
+ if ( cnt1 >= 1 ) break loop1;
+ EarlyExitException eee =
+ new EarlyExitException(1, input);
+ throw eee;
+ }
+ cnt1++;
+ } while (true);
- }
+ }
- if ( token==null )
{emit(type,line,charPosition,channel,start,getCharIndex()-1);}
+ if ( token==null )
{emit(type,line,charPosition,channel,start,getCharIndex()-1);}
+ }
+ finally {
+ }
}
+ // $ANTLR end INT
+
+ // $ANTLR start ML_COMMENT
public void mML_COMMENT() throws RecognitionException {
- int type = ML_COMMENT;
- int start = getCharIndex();
- int line = getLine();
- int charPosition = getCharPositionInLine();
- int channel = Token.DEFAULT_CHANNEL;
- // grammar/antlr_3/BcParser.lexer.g:7:14: ( '/*' ( options
{greedy=false; } : . )* '*/' )
- // grammar/antlr_3/BcParser.lexer.g:7:14: '/*' ( options
{greedy=false; } : . )* '*/'
- {
-
- match("/*");
-
-
- // grammar/antlr_3/BcParser.lexer.g:7:19: ( options {greedy=false; } :
. )*
- loop2:
- do {
- int alt2=2;
- int LA2_0 = input.LA(1);
- if ( LA2_0=='*' ) {
- int LA2_1 = input.LA(2);
- if ( LA2_1=='/' ) {
- alt2=2;
+ try {
+ int type = ML_COMMENT;
+ int start = getCharIndex();
+ int line = getLine();
+ int charPosition = getCharPositionInLine();
+ int channel = Token.DEFAULT_CHANNEL;
+ // grammar/antlr_3/bc.g:48:5: ( '/*' ( options {greedy=false; } :
. )* '*/' )
+ // grammar/antlr_3/bc.g:48:5: '/*' ( options {greedy=false; } : .
)* '*/'
+ {
+ match("/*");
+
+ // grammar/antlr_3/bc.g:49:5: ( options {greedy=false; } : . )*
+ loop2:
+ do {
+ int alt2=2;
+ int LA2_0 = input.LA(1);
+ if ( LA2_0=='*' ) {
+ int LA2_1 = input.LA(2);
+ if ( LA2_1=='/' ) {
+ alt2=2;
+ }
+ else if ( (LA2_1>='\u0000' && LA2_1<='.')||(LA2_1>='0' &&
LA2_1<='\uFFFE') ) {
+ alt2=1;
+ }
+
+
}
- else if ( (LA2_1>='\u0000' && LA2_1<='.')||(LA2_1>='0' &&
LA2_1<='\uFFFE') ) {
+ else if ( (LA2_0>='\u0000' && LA2_0<=')')||(LA2_0>='+' &&
LA2_0<='\uFFFE') ) {
alt2=1;
}
- }
- else if ( (LA2_0>='\u0000' && LA2_0<=')')||(LA2_0>='+' &&
LA2_0<='\uFFFE') ) {
- alt2=1;
- }
-
-
- switch (alt2) {
- case 1 :
- // grammar/antlr_3/BcParser.lexer.g:7:48: .
- {
+ switch (alt2) {
+ case 1 :
+ // grammar/antlr_3/bc.g:49:33: .
+ {
+ matchAny();
- matchAny();
-
- }
- break;
-
- default :
- break loop2;
- }
- } while (true);
+ }
+ break;
+ default :
+ break loop2;
+ }
+ } while (true);
- match("*/");
+ match("*/");
+ channel = 99; // send into nirwana
+
- channel = 99; // send into nirwana
-
+ }
+ if ( token==null )
{emit(type,line,charPosition,channel,start,getCharIndex()-1);}
+ }
+ finally {
}
-
- if ( token==null )
{emit(type,line,charPosition,channel,start,getCharIndex()-1);}
}
+ // $ANTLR end ML_COMMENT
+
+ // $ANTLR start WS
public void mWS() throws RecognitionException {
- int type = WS;
- int start = getCharIndex();
- int line = getLine();
- int charPosition = getCharPositionInLine();
- int channel = Token.DEFAULT_CHANNEL;
- // grammar/antlr_3/BcParser.lexer.g:11:6: ( ( (' '|'\t'|'\r'|'\n'))+ )
- // grammar/antlr_3/BcParser.lexer.g:11:6: ( (' '|'\t'|'\r'|'\n'))+
- {
-
- // grammar/antlr_3/BcParser.lexer.g:11:6: ( (' '|'\t'|'\r'|'\n'))+
- int cnt3=0;
- loop3:
- do {
- int alt3=2;
- int LA3_0 = input.LA(1);
- if ( (LA3_0>='\t' && LA3_0<='\n')||LA3_0=='\r'||LA3_0==' ' ) {
- alt3=1;
- }
+ try {
+ int type = WS;
+ int start = getCharIndex();
+ int line = getLine();
+ int charPosition = getCharPositionInLine();
+ int channel = Token.DEFAULT_CHANNEL;
+ // grammar/antlr_3/bc.g:57:5: ( ( (' '|'\t'|'\r'|'\n'))+ )
+ // grammar/antlr_3/bc.g:57:5: ( (' '|'\t'|'\r'|'\n'))+
+ {
+ // grammar/antlr_3/bc.g:57:5: ( (' '|'\t'|'\r'|'\n'))+
+ int cnt3=0;
+ loop3:
+ do {
+ int alt3=2;
+ int LA3_0 = input.LA(1);
+ if ( (LA3_0>='\t' && LA3_0<='\n')||LA3_0=='\r'||LA3_0==' ' ) {
+ alt3=1;
+ }
- switch (alt3) {
- case 1 :
- // grammar/antlr_3/BcParser.lexer.g:11:8: ('
'|'\t'|'\r'|'\n')
- {
-
- if ( (input.LA(1)>='\t' &&
input.LA(1)<='\n')||input.LA(1)=='\r'||input.LA(1)==' ' ) {
- input.consume();
- errorRecovery=false;
- }
- else {
- MismatchedSetException mse =
- new MismatchedSetException(null,input);
- recover(mse); throw mse;
- }
-
-
- }
- break;
-
- default :
- if ( cnt3 >= 1 ) break loop3;
- EarlyExitException eee =
- new EarlyExitException(3, input);
- throw eee;
- }
- cnt3++;
- } while (true);
+ switch (alt3) {
+ case 1 :
+ // grammar/antlr_3/bc.g:57:9: (' '|'\t'|'\r'|'\n')
+ {
+ if ( (input.LA(1)>='\t' &&
input.LA(1)<='\n')||input.LA(1)=='\r'||input.LA(1)==' ' ) {
+ input.consume();
+
+ }
+ else {
+ MismatchedSetException mse =
+ new MismatchedSetException(null,input);
+ recover(mse); throw mse;
+ }
+
+
+ }
+ break;
+
+ default :
+ if ( cnt3 >= 1 ) break loop3;
+ EarlyExitException eee =
+ new EarlyExitException(3, input);
+ throw eee;
+ }
+ cnt3++;
+ } while (true);
+ channel = 99; // send into nirwana
+
- channel = 99; // send into nirwana
-
+ }
+ if ( token==null )
{emit(type,line,charPosition,channel,start,getCharIndex()-1);}
+ }
+ finally {
}
-
- if ( token==null )
{emit(type,line,charPosition,channel,start,getCharIndex()-1);}
}
+ // $ANTLR end WS
public void mTokens() throws RecognitionException {
- // grammar/antlr_3/BcParser.lexer.g:1:10: ( T8 | INT | ML_COMMENT | WS
)
- int alt4=4;
+ // grammar/antlr_3/bc.g:1:10: ( T9 | T10 | INT | ML_COMMENT | WS )
+ int alt4=5;
switch ( input.LA(1) ) {
- case 'q':
+ case '-':
alt4=1;
break;
+ case 'q':
+ alt4=2;
+ break;
case '0':
case '1':
case '2':
@@ -235,55 +265,57 @@
case '7':
case '8':
case '9':
- alt4=2;
+ alt4=3;
break;
case '/':
- alt4=3;
+ alt4=4;
break;
case '\t':
case '\n':
case '\r':
case ' ':
- alt4=4;
+ alt4=5;
break;
default:
-
NoViableAltException nvae =
- new NoViableAltException("1:1: Tokens : ( T8 | INT |
ML_COMMENT | WS );", 4, 0, input);
+ new NoViableAltException("1:1: Tokens : ( T9 | T10 | INT |
ML_COMMENT | WS );", 4, 0, input);
throw nvae;
}
switch (alt4) {
case 1 :
- // grammar/antlr_3/BcParser.lexer.g:1:10: T8
+ // grammar/antlr_3/bc.g:1:10: T9
{
-
- mT8();
+ mT9();
}
break;
case 2 :
- // grammar/antlr_3/BcParser.lexer.g:1:13: INT
+ // grammar/antlr_3/bc.g:1:13: T10
{
-
- mINT();
+ mT10();
}
break;
case 3 :
- // grammar/antlr_3/BcParser.lexer.g:1:17: ML_COMMENT
+ // grammar/antlr_3/bc.g:1:17: INT
{
-
- mML_COMMENT();
+ mINT();
}
break;
case 4 :
- // grammar/antlr_3/BcParser.lexer.g:1:28: WS
+ // grammar/antlr_3/bc.g:1:21: ML_COMMENT
{
+ mML_COMMENT();
- mWS();
+ }
+ break;
+ case 5 :
+ // grammar/antlr_3/bc.g:1:32: WS
+ {
+ mWS();
}
break;
Modified: trunk/languages/bc/grammar/antlr_3/antlr_past2pir_past.g
==============================================================================
--- trunk/languages/bc/grammar/antlr_3/antlr_past2pir_past.g (original)
+++ trunk/languages/bc/grammar/antlr_3/antlr_past2pir_past.g Fri Mar 17
09:49:10 2006
@@ -32,7 +32,7 @@
+ " load_bytecode 'languages/punie/lib/POST.pir'" + "\n"
+ "\n"
+ " .local pmc stmts_children" + "\n"
- + " stmts_children = new PerlArray" + "\n"
+ + " stmts_children = new .PerlArray" + "\n"
;
System.out.println( pirBefore );
@@ -141,19 +141,19 @@
+ $reg + ".valtype( 'num' )" + "\n"
+ "# leaving expr" + "\n"
+ " \$P20 = new 'PAST::Exp' " + "\n"
- + " \$P21 = new PerlArray " + "\n"
+ + " \$P21 = new .PerlArray " + "\n"
+ " push \$P21, " + $reg + " \n"
+ " \$P20.set_node('1', 1, \$P21) " + "\n"
+ " \$P30 = new 'PAST::Op' " + "\n"
- + " \$P31 = new PerlArray " + "\n"
+ + " \$P31 = new .PerlArray " + "\n"
+ " push \$P31, \$P20 " + "\n"
+ " \$P30.set_node('1', 1, 'print' ,\$P31) " + "\n"
+ " \$P40 = new 'PAST::Exp' " + "\n"
- + " \$P41 = new PerlArray " + "\n"
+ + " \$P41 = new .PerlArray " + "\n"
+ " push \$P41, \$P30 " + "\n"
+ " \$P40.set_node('1', 1, \$P41) " + "\n"
+ " \$P50 = new 'PAST::Stmt' " + "\n"
- + " \$P51 = new PerlArray " + "\n"
+ + " \$P51 = new .PerlArray " + "\n"
+ " push \$P51, \$P40 " + "\n"
+ " \$P50.set_node('1', 1 ,\$P51) " + "\n"
+ " push stmts_children, \$P50 " + "\n"
@@ -161,19 +161,19 @@
+ " \$P60.set_node( '1', 0, '\\n' ) " + "\n"
+ " \$P60.valtype( 'strqq' ) " + "\n"
+ " \$P70 = new 'PAST::Exp' " + "\n"
- + " \$P71 = new PerlArray " + "\n"
+ + " \$P71 = new .PerlArray " + "\n"
+ " push \$P71, \$P60 " + "\n"
+ " \$P70.set_node('1', 1, \$P71) " + "\n"
+ " \$P80 = new 'PAST::Op' " + "\n"
- + " \$P81 = new PerlArray " + "\n"
+ + " \$P81 = new .PerlArray " + "\n"
+ " push \$P81, \$P70 " + "\n"
+ " \$P80.set_node('1', 1, 'print' ,\$P81) " + "\n"
+ " \$P90 = new 'PAST::Exp' " + "\n"
- + " \$P91 = new PerlArray " + "\n"
+ + " \$P91 = new .PerlArray " + "\n"
+ " push \$P91, \$P80 " + "\n"
+ " \$P90.set_node('1', 1, \$P91) " + "\n"
+ " \$P100 = new 'PAST::Stmt' " + "\n"
- + " \$P101 = new PerlArray " + "\n"
+ + " \$P101 = new .PerlArray " + "\n"
+ " push \$P101, \$P90 " + "\n"
+ " \$P100.set_node('1', 1 ,\$P101) " + "\n"
+ " push stmts_children, \$P100 " + "\n"
Modified: trunk/languages/bc/grammar/antlr_3/bc.g
==============================================================================
--- trunk/languages/bc/grammar/antlr_3/bc.g (original)
+++ trunk/languages/bc/grammar/antlr_3/bc.g Fri Mar 17 09:49:10 2006
@@ -16,6 +16,7 @@
tokens
{
PROGRAM;
+ UNARY_MINUS;
}
program
@@ -23,7 +24,12 @@
;
input_item
- : INT +
+ : expression +
+ ;
+
+expression
+ : INT
+ | '-' expression -> ^( UNARY_MINUS expression )
;
INT
Modified: trunk/languages/bc/t/basic.t
==============================================================================
--- trunk/languages/bc/t/basic.t (original)
+++ trunk/languages/bc/t/basic.t Fri Mar 17 09:49:10 2006
@@ -12,6 +12,8 @@
=cut
use strict;
+use warnings;
+
use FindBin;
use lib "$FindBin::Bin/../lib", "$FindBin::Bin/../../../lib";
@@ -20,7 +22,7 @@
use Test::More;
if ( $PConfig{has_python} ) {
- plan tests => 78;
+ plan tests => 80;
}
else {
plan skip_all => 'ANTLR2 based bc needs Python';
@@ -53,18 +55,22 @@
my @tests = (
# single non-negative integer
- [ '1', [ 1 ], 'positive int 1', with_past => 1,
with_antlr3 => 1 ],
- [ '0', [ 0 ], 'zero', with_past => 1,
with_antlr3 => 1 ],
- [ '2', [ 2 ], 'positive int', with_past => 1,
with_antlr3 => 1 ],
- [ '12345678', [ 12345678 ], 'another positive int', with_past => 1,
with_antlr3 => 1 ],
+ [ '1', [ 1 ], 'positive int 1', with_past => 1,
with_antlr3 => 1 ],
+ [ '0', [ 0 ], 'zero', with_past => 1,
with_antlr3 => 1 ],
+ [ '2', [ 2 ], 'positive int', with_past => 1,
with_antlr3 => 1 ],
+ [ '12345678', [ 12345678 ], 'another positive int', with_past => 1,
with_antlr3 => 1 ],
+
+ # single negative integer
+ [ '-1', [ -1 ], 'negative int 1', with_past => 1,
with_antlr3 => 0 ],
+ [ '-12345678', [ -12345678 ], 'another negative int', with_past => 1,
with_antlr3 => 0 ],
# multiple lines
- [ "1\n2", [ 1, 2 ], 'two lines', with_past => 1,
with_antlr3 => 1 ],
+ [ "1\n2", [ 1, 2 ], 'two lines', with_past => 1,
with_antlr3 => 1 ],
[ "1\n2\n3\n4\n\n5\n6\n7", [ 1, 2, 3, 4, 5, 6, 7 ], 'seven lines',
with_past => 1, with_antlr3 => 1 ],
# comments
[ '/* */7', 7, 'one line comment', with_past => 1,
with_antlr3 => 1 ],
- [ "/* line1 \n line2 \n line 3 */ -2 ", -2, 'multi line comment',
with_past => 1 ],
+ [ "/* line1 \n line2 \n line 3 */ -2 ", -2, 'multi line comment',
with_past => 1, with_antlr3 => 0 ],
# Strings
[ qq{1;2;"asdf" ; 3 }, [ 1, 2, 'asdf3' ], 'string', with_past =>
0 ],