Permalink
Browse files

the whole AST builds\!

  • Loading branch information...
1 parent 1cc96c0 commit 87900320af14f613ae487a4326396562cdbab896 @Swizec committed Apr 21, 2012
@@ -1,7 +1,7 @@
//----------------------------------------------------
// The following code was generated by CUP v0.11a beta 20060608
-// Sat Apr 21 22:28:57 CEST 2012
+// Sat Apr 21 23:06:32 CEST 2012
//----------------------------------------------------
package compiler.synanal;
@@ -12,7 +12,7 @@
import compiler.abstree.tree.*;
/** CUP v0.11a beta 20060608 generated parser.
- * @version Sat Apr 21 22:28:57 CEST 2012
+ * @version Sat Apr 21 23:06:32 CEST 2012
*/
public class PascalSyn extends java_cup.runtime.lr_parser {
@@ -53,7 +53,7 @@
"\000\002\022\003\000\002\022\003\000\002\022\003\000" +
"\002\023\006\000\002\024\002\000\002\024\003\000\002" +
"\024\005\000\002\005\005\000\002\042\002\000\002\042" +
- "\005\000\002\042\003\000\002\041\003\000\002\041\005" +
+ "\003\000\002\042\005\000\002\041\003\000\002\041\005" +
"\000\002\041\003\000\002\041\003\000\002\041\003\000" +
"\002\043\006\000\002\043\010\000\002\044\006\000\002" +
"\044\012" });
@@ -74,7 +74,7 @@
"\004\016\166\001\002\000\042\004\025\005\044\006\032" +
"\007\030\010\023\020\027\021\034\025\035\040\022\042" +
"\020\043\031\051\016\055\uffb2\056\042\060\026\071\021" +
- "\001\002\000\006\024\164\055\uffb0\001\002\000\030\004" +
+ "\001\002\000\006\024\164\055\uffb1\001\002\000\030\004" +
"\uffc5\005\uffc5\006\uffc5\007\uffc5\010\uffc5\020\uffc5\021\uffc5" +
"\025\uffc5\040\uffc5\042\uffc5\043\uffc5\001\002\000\030\004" +
"\025\005\044\006\032\007\030\010\023\020\027\021\034" +
@@ -273,7 +273,7 @@
"\001\002\000\042\004\025\005\044\006\032\007\030\010" +
"\023\020\027\021\034\025\035\040\022\042\020\043\031" +
"\051\016\055\uffb2\056\042\060\026\071\021\001\002\000" +
- "\004\055\uffb1\001\002\000\004\002\uffff\001\002\000\012" +
+ "\004\055\uffb0\001\002\000\004\002\uffff\001\002\000\012" +
"\051\uffe3\057\uffe3\062\uffe3\070\200\001\002\000\004\010" +
"\172\001\002\000\012\051\ufff6\057\ufff6\062\ufff6\070\ufff6" +
"\001\002\000\004\030\175\001\002\000\014\010\172\051" +
@@ -487,7 +487,24 @@ public void report_fatal_error(String message, Object info) throws Exception {
case 90: // loop ::= FOR IDENTIFIER ASSIGN value TO value DO statement
{
Object RESULT =null;
-
+ int idleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-6)).left;
+ int idright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-6)).right;
+ String id = (String)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-6)).value;
+ int loleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-4)).left;
+ int loright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-4)).right;
+ Object lo = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-4)).value;
+ int hileft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).left;
+ int hiright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).right;
+ Object hi = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).value;
+ int sleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).left;
+ int sright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).right;
+ Object s = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.peek()).value;
+
+ RESULT = new AbsForStmt(new AbsValName(id),
+ (AbsValExpr)lo,
+ (AbsValExpr)hi,
+ (AbsStmt)s);
+
CUP$PascalSyn$result = parser.getSymbolFactory().newSymbol("loop",34, ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-7)), ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), RESULT);
}
return CUP$PascalSyn$result;
@@ -496,7 +513,16 @@ public void report_fatal_error(String message, Object info) throws Exception {
case 89: // loop ::= WHILE value DO statement
{
Object RESULT =null;
-
+ int condleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).left;
+ int condright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).right;
+ Object cond = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).value;
+ int sleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).left;
+ int sright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).right;
+ Object s = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.peek()).value;
+
+ RESULT = new AbsWhileStmt((AbsValExpr)cond,
+ (AbsStmt)s);
+
CUP$PascalSyn$result = parser.getSymbolFactory().newSymbol("loop",34, ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-3)), ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), RESULT);
}
return CUP$PascalSyn$result;
@@ -505,7 +531,20 @@ public void report_fatal_error(String message, Object info) throws Exception {
case 88: // conditional ::= IF value THEN statement ELSE statement
{
Object RESULT =null;
-
+ int condleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-4)).left;
+ int condright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-4)).right;
+ Object cond = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-4)).value;
+ int thenleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).left;
+ int thenright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).right;
+ Object then = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).value;
+ int elsleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).left;
+ int elsright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).right;
+ Object els = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.peek()).value;
+
+ RESULT = new AbsIfStmt((AbsValExpr)cond,
+ (AbsStmt)then,
+ (AbsStmt)els);
+
CUP$PascalSyn$result = parser.getSymbolFactory().newSymbol("conditional",33, ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-5)), ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), RESULT);
}
return CUP$PascalSyn$result;
@@ -514,7 +553,17 @@ public void report_fatal_error(String message, Object info) throws Exception {
case 87: // conditional ::= IF value THEN statement
{
Object RESULT =null;
-
+ int condleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).left;
+ int condright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).right;
+ Object cond = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).value;
+ int thenleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).left;
+ int thenright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).right;
+ Object then = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.peek()).value;
+
+ RESULT = new AbsIfStmt((AbsValExpr)cond,
+ (AbsStmt)then,
+ new AbsBlockStmt(new AbsStmts()));
+
CUP$PascalSyn$result = parser.getSymbolFactory().newSymbol("conditional",33, ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-3)), ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), RESULT);
}
return CUP$PascalSyn$result;
@@ -523,7 +572,10 @@ public void report_fatal_error(String message, Object info) throws Exception {
case 86: // statement ::= block_statement
{
Object RESULT =null;
-
+ int blockleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).left;
+ int blockright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).right;
+ Object block = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.peek()).value;
+ RESULT = block;
CUP$PascalSyn$result = parser.getSymbolFactory().newSymbol("statement",31, ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), RESULT);
}
return CUP$PascalSyn$result;
@@ -532,7 +584,10 @@ public void report_fatal_error(String message, Object info) throws Exception {
case 85: // statement ::= loop
{
Object RESULT =null;
-
+ int loopleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).left;
+ int loopright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).right;
+ Object loop = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.peek()).value;
+ RESULT = loop;
CUP$PascalSyn$result = parser.getSymbolFactory().newSymbol("statement",31, ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), RESULT);
}
return CUP$PascalSyn$result;
@@ -541,7 +596,10 @@ public void report_fatal_error(String message, Object info) throws Exception {
case 84: // statement ::= conditional
{
Object RESULT =null;
-
+ int condleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).left;
+ int condright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).right;
+ Object cond = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.peek()).value;
+ RESULT = cond;
CUP$PascalSyn$result = parser.getSymbolFactory().newSymbol("statement",31, ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), RESULT);
}
return CUP$PascalSyn$result;
@@ -550,7 +608,14 @@ public void report_fatal_error(String message, Object info) throws Exception {
case 83: // statement ::= value ASSIGN value
{
Object RESULT =null;
-
+ int dstleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).left;
+ int dstright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).right;
+ Object dst = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).value;
+ int srcleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).left;
+ int srcright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).right;
+ Object src = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.peek()).value;
+ RESULT = new AbsAssignStmt((AbsValExpr)dst,
+ (AbsValExpr)src);
CUP$PascalSyn$result = parser.getSymbolFactory().newSymbol("statement",31, ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)), ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), RESULT);
}
return CUP$PascalSyn$result;
@@ -559,34 +624,55 @@ public void report_fatal_error(String message, Object info) throws Exception {
case 82: // statement ::= value
{
Object RESULT =null;
-
+ int vleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).left;
+ int vright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).right;
+ Object v = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.peek()).value;
+ RESULT = new AbsExprStmt((AbsValExpr)v);
CUP$PascalSyn$result = parser.getSymbolFactory().newSymbol("statement",31, ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), RESULT);
}
return CUP$PascalSyn$result;
/*. . . . . . . . . . . . . . . . . . . .*/
- case 81: // statement_ ::= statement
+ case 81: // statement_ ::= statement SEMIC statement_
{
Object RESULT =null;
-
- CUP$PascalSyn$result = parser.getSymbolFactory().newSymbol("statement_",32, ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), RESULT);
+ int sleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).left;
+ int sright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).right;
+ Object s = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)).value;
+ int restleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).left;
+ int restright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).right;
+ Object rest = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.peek()).value;
+
+ AbsStmts stmts = new AbsStmts();
+ stmts.stmts.add((AbsStmt)s);
+ stmts.stmts.addAll(((AbsStmts)rest).stmts);
+ RESULT = stmts;
+
+ CUP$PascalSyn$result = parser.getSymbolFactory().newSymbol("statement_",32, ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)), ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), RESULT);
}
return CUP$PascalSyn$result;
/*. . . . . . . . . . . . . . . . . . . .*/
- case 80: // statement_ ::= statement SEMIC statement_
+ case 80: // statement_ ::= statement
{
Object RESULT =null;
-
- CUP$PascalSyn$result = parser.getSymbolFactory().newSymbol("statement_",32, ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)), ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), RESULT);
+ int sleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).left;
+ int sright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()).right;
+ Object s = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.peek()).value;
+
+ AbsStmts stmts = new AbsStmts();
+ stmts.stmts.add((AbsStmt)s);
+ RESULT = stmts;
+
+ CUP$PascalSyn$result = parser.getSymbolFactory().newSymbol("statement_",32, ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), RESULT);
}
return CUP$PascalSyn$result;
/*. . . . . . . . . . . . . . . . . . . .*/
case 79: // statement_ ::=
{
Object RESULT =null;
-
+ RESULT = new AbsStmts();
CUP$PascalSyn$result = parser.getSymbolFactory().newSymbol("statement_",32, ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), RESULT);
}
return CUP$PascalSyn$result;
@@ -595,8 +681,11 @@ public void report_fatal_error(String message, Object info) throws Exception {
case 78: // block_statement ::= BEGIN statement_ END
{
Object RESULT =null;
+ int sleft = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-1)).left;
+ int sright = ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-1)).right;
+ Object s = (Object)((java_cup.runtime.Symbol) CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-1)).value;
- RESULT = new AbsBlockStmt(new AbsStmts());
+ RESULT = new AbsBlockStmt((AbsStmts)s);
CUP$PascalSyn$result = parser.getSymbolFactory().newSymbol("block_statement",3, ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.elementAt(CUP$PascalSyn$top-2)), ((java_cup.runtime.Symbol)CUP$PascalSyn$stack.peek()), RESULT);
}
@@ -1,7 +1,7 @@
//----------------------------------------------------
// The following code was generated by CUP v0.11a beta 20060608
-// Sat Apr 21 22:28:57 CEST 2012
+// Sat Apr 21 23:06:31 CEST 2012
//----------------------------------------------------
package compiler.synanal;
@@ -277,16 +277,47 @@ parameter_call ::= {: RESULT = new AbsValExprs(); :}
/*
statements
*/
-block_statement ::= BEGIN statement_ END
+block_statement ::= BEGIN statement_:s END
{:
- RESULT = new AbsBlockStmt(new AbsStmts());
+ RESULT = new AbsBlockStmt((AbsStmts)s);
:};
-statement_ ::= | statement SEMIC statement_ | statement;
-statement ::= value
- | value ASSIGN value
- | conditional
- | loop
- | block_statement;
-conditional ::= IF value THEN statement | IF value THEN statement ELSE statement;
-loop ::= WHILE value DO statement
- | FOR IDENTIFIER ASSIGN value TO value DO statement;
+statement_ ::= {: RESULT = new AbsStmts(); :}
+ | statement:s {:
+ AbsStmts stmts = new AbsStmts();
+ stmts.stmts.add((AbsStmt)s);
+ RESULT = stmts;
+ :}
+ | statement:s SEMIC statement_:rest {:
+ AbsStmts stmts = new AbsStmts();
+ stmts.stmts.add((AbsStmt)s);
+ stmts.stmts.addAll(((AbsStmts)rest).stmts);
+ RESULT = stmts;
+ :};
+statement ::= value:v {: RESULT = new AbsExprStmt((AbsValExpr)v); :}
+ | value:dst ASSIGN value:src {: RESULT = new AbsAssignStmt((AbsValExpr)dst,
+ (AbsValExpr)src); :}
+ | conditional:cond {: RESULT = cond; :}
+ | loop:loop {: RESULT = loop; :}
+ | block_statement:block {: RESULT = block; :};
+conditional ::= IF value:cond THEN statement:then
+{:
+ RESULT = new AbsIfStmt((AbsValExpr)cond,
+ (AbsStmt)then,
+ new AbsBlockStmt(new AbsStmts()));
+ :}
+| IF value:cond THEN statement:then ELSE statement:els
+{:
+ RESULT = new AbsIfStmt((AbsValExpr)cond,
+ (AbsStmt)then,
+ (AbsStmt)els);
+ :};
+loop ::= WHILE value:cond DO statement:s {:
+ RESULT = new AbsWhileStmt((AbsValExpr)cond,
+ (AbsStmt)s);
+ :}
+ | FOR IDENTIFIER:id ASSIGN value:lo TO value:hi DO statement:s {:
+ RESULT = new AbsForStmt(new AbsValName(id),
+ (AbsValExpr)lo,
+ (AbsValExpr)hi,
+ (AbsStmt)s);
+ :};
View
@@ -86,4 +86,35 @@ begin
end;
begin
+ ohai3(true);
+ 6+4 := ohai2(false);
+ if ohai() then
+ a := hai;
+
+ if ohai3() then
+ b := 'l'
+ else
+ if 5+3*(3+5) then
+ meow()
+ else
+ 6 := 7 div ohai4();
+
+ while 5+23 or 5*10 do
+ a := ohai2(false);
+
+ for i := 8 to ohai(7+b[a+5]) do
+ meow();
+
+ for i := 1 to 100+false do
+ while i div 6 < 6 do
+ i := i+5;
+
+ if mew() then
+ begin
+ ohai_thar()
+ end
+ else
+ begin
+ a := 5+3
+ end
end.

0 comments on commit 8790032

Please sign in to comment.