home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.pdx.edu / 2014.02.ftp.ee.pdx.edu.tar / ftp.ee.pdx.edu / pub / users / Harry / compilers / p4 / Ast.java next >
Text File  |  2005-10-25  |  10KB  |  426 lines

  1. // --------------------------- Ast ------------------------------
  2. //
  3. // This files contains the classes used to represent an
  4. // Abstract Syntax Tree.
  5. //
  6. // Harry Porter -- 10/21/05
  7. //
  8.  
  9. class Ast {
  10.  
  11.  
  12.  
  13.     //-------------------------- Node ---------------------------
  14.  
  15.     abstract static class Node {
  16.         int lineNumber;
  17.  
  18.         Node() {
  19.             super();
  20.             lineNumber = Main.parser.lexer.lineNumber;
  21.         }
  22.  
  23.     }
  24.  
  25.  
  26.  
  27.     //-------------------------- Body ---------------------------
  28.  
  29.     static class Body extends Node {
  30.         TypeDecl    typeDecls;
  31.         ProcDecl    procDecls;
  32.         VarDecl     varDecls;
  33.         Stmt        stmts;
  34.         int         frameSize;               // Not used until proj 9
  35.     }
  36.  
  37.  
  38.  
  39.     //-------------------------- VarDecl ---------------------------
  40.         
  41.     static class VarDecl extends Node {
  42.         String      id;
  43.         TypeName    typeName;
  44.         Expr        expr;
  45.         VarDecl     next;
  46.         int         lexLevel;                // Not used until proj 5
  47.         int         offset;                  // Not used until proj 9
  48.     }
  49.  
  50.  
  51.  
  52.     //-------------------------- TypeDecl ---------------------------
  53.  
  54.     static class TypeDecl extends Node {
  55.         String       id;
  56.         CompoundType compoundType;
  57.         TypeDecl     next;
  58.     }
  59.  
  60.  
  61.  
  62.     //-------------------------- TypeName ---------------------------
  63.  
  64.     static class TypeName extends Node {
  65.         String       id;
  66.         CompoundType myDef;                  // Not used until proj 5
  67.     }
  68.  
  69.  
  70.  
  71.     //-------------------------- ProcDecl ---------------------------
  72.  
  73.     static class ProcDecl extends Node {
  74.         String      id;
  75.         Formal      formals;
  76.         TypeName    retType;
  77.         Body        body;
  78.         ProcDecl    next;
  79.         int         lexLevel;                // Not used until proj 5
  80.     }
  81.  
  82.  
  83.  
  84.     //-------------------------- Formal ---------------------------
  85.  
  86.     static class Formal extends Node {
  87.         String      id;
  88.         TypeName    typeName;
  89.         Formal      next;
  90.         int         lexLevel;                // Not used until proj 5
  91.         int         offset;                  // Not used until proj 9
  92.     }
  93.  
  94.  
  95.  
  96.     //-------------------------- CompoundType ---------------------------
  97.  
  98.     abstract static class CompoundType extends Node { }
  99.  
  100.  
  101.  
  102.     //-------------------------- ArrayType ---------------------------
  103.  
  104.     static class ArrayType extends CompoundType {
  105.         TypeName     elementType;
  106.     }
  107.  
  108.  
  109.  
  110.     //-------------------------- RecordType ---------------------------
  111.  
  112.     static class RecordType extends CompoundType {
  113.         FieldDecl    fieldDecls;
  114.         int          size;                   // Not used until proj 9
  115.     }
  116.  
  117.  
  118.  
  119.     //-------------------------- FieldDecl ---------------------------
  120.  
  121.     static class FieldDecl extends Node {
  122.         String       id;
  123.         TypeName     typeName;
  124.         FieldDecl    next;
  125.         int          offset;                 // Not used until proj 9
  126.     }
  127.  
  128.  
  129.  
  130.     //-------------------------- Stmt ---------------------------
  131.  
  132.     abstract static class Stmt extends Node {
  133.         Stmt     next;
  134.     }
  135.  
  136.  
  137.  
  138.     //-------------------------- AssignStmt ---------------------------
  139.  
  140.     static class AssignStmt extends Stmt {
  141.         LValue      lValue;
  142.         Expr        expr;
  143.     }
  144.  
  145.  
  146.  
  147.     //-------------------------- CallStmt ---------------------------
  148.  
  149.     static class CallStmt extends Stmt {
  150.         String      id;
  151.         Argument    args;
  152.         ProcDecl    myDef;                   // Not used until proj 5
  153.     }
  154.  
  155.  
  156.  
  157.     //-------------------------- ReadStmt ---------------------------
  158.  
  159.     static class ReadStmt extends Stmt {
  160.         ReadArg     readArgs;
  161.     }
  162.  
  163.  
  164.  
  165.     //-------------------------- ReadArg ---------------------------
  166.  
  167.     static class ReadArg extends Node {
  168.         ReadArg     next;
  169.         LValue      lValue;
  170.         int         mode;                    // Not used until proj 6
  171.     }
  172.  
  173.  
  174.  
  175.     //-------------------------- WriteStmt ---------------------------
  176.  
  177.     static class WriteStmt extends Stmt {
  178.         Argument  args;
  179.     }
  180.  
  181.  
  182.  
  183.     //-------------------------- IfStmt ---------------------------
  184.  
  185.     static class IfStmt extends Stmt {
  186.         Expr        expr;
  187.         Stmt        thenStmts;
  188.         Stmt        elseStmts;
  189.     }
  190.  
  191.  
  192.  
  193.     //-------------------------- WhileStmt ---------------------------
  194.  
  195.     static class WhileStmt extends Stmt {
  196.         Expr        expr;
  197.         Stmt        stmts;
  198.         String      exitLabel;               // Not used until proj 8
  199.     }
  200.  
  201.  
  202.  
  203.     //-------------------------- LoopStmt ---------------------------
  204.  
  205.     static class LoopStmt extends Stmt {
  206.         Stmt        stmts;
  207.         String      exitLabel;               // Not used until proj 8
  208.     }
  209.  
  210.  
  211.  
  212.     //-------------------------- ForStmt ---------------------------
  213.  
  214.     static class ForStmt extends Stmt {
  215.         LValue      lValue;
  216.         Expr        expr1;
  217.         Expr        expr2;
  218.         Expr        expr3;
  219.         Stmt        stmts;
  220.         String      exitLabel;               // Not used until proj 8
  221.     }
  222.  
  223.  
  224.  
  225.     //-------------------------- ExitStmt ---------------------------
  226.  
  227.     static class ExitStmt extends Stmt {
  228.         Stmt        myLoop;                  // Not used until proj 6
  229.     }
  230.  
  231.  
  232.  
  233.     //-------------------------- ReturnStmt ---------------------------
  234.  
  235.     static class ReturnStmt extends Stmt {
  236.         Expr         expr;
  237.         ProcDecl     myProc;                 // Not used until proj 6
  238.     }
  239.  
  240.  
  241.  
  242.     //-------------------------- Expr ---------------------------
  243.  
  244.     abstract static class Expr extends Node { }
  245.  
  246.  
  247.  
  248.     //-------------------------- BinaryOp ---------------------------
  249.  
  250.     static class BinaryOp extends Expr {
  251.         int         op;
  252.         Expr        expr1;
  253.         Expr        expr2;
  254.         int         mode;                    // Not used until proj 6
  255.     }
  256.  
  257.  
  258.  
  259.     //-------------------------- UnaryOp ---------------------------
  260.  
  261.     static class UnaryOp extends Expr {
  262.         int         op;
  263.         Expr        expr;
  264.         int         mode;                    // Not used until proj 6
  265.     }
  266.  
  267.  
  268.  
  269.     //-------------------------- IntToReal ---------------------------
  270.  
  271.     static class IntToReal extends Expr {    // Not used until proj 6
  272.         Expr        expr;
  273.     }
  274.  
  275.  
  276.  
  277.     //-------------------------- FunctionCall ---------------------------
  278.  
  279.     static class FunctionCall extends Expr {
  280.         String      id;
  281.         Argument    args;
  282.         ProcDecl    myDef;                   // Not used until proj 5
  283.     }
  284.  
  285.  
  286.  
  287.     //-------------------------- Argument ---------------------------
  288.  
  289.     static class Argument extends Node {
  290.         Argument    next;
  291.         Expr        expr;
  292.         int         mode;                    // Not used until proj 6
  293.         Node        location;                // Not used until proj 8
  294.     }
  295.  
  296.  
  297.  
  298.     //-------------------------- ArrayConstructor ---------------------------
  299.  
  300.     static class ArrayConstructor extends Expr {
  301.         String        id;
  302.         ArrayValue    values;
  303.         TypeDecl      myDef;                 // Not used until proj 5
  304.     }
  305.  
  306.  
  307.  
  308.     //-------------------------- ArrayValue ---------------------------
  309.  
  310.     static class ArrayValue extends Node {
  311.         ArrayValue    next;
  312.         Expr          countExpr;
  313.         Expr          valueExpr;
  314.         Node          tempCount;             // Not used until proj 9
  315.         Node          tempValue;             // Not used until proj 9
  316.     }
  317.  
  318.  
  319.  
  320.     //-------------------------- RecordConstructor ---------------------------
  321.  
  322.     static class RecordConstructor extends Expr {
  323.         String             id;
  324.         FieldInit          fieldInits;
  325.         TypeDecl           myDef;            // Not used until proj 5
  326.     }
  327.  
  328.  
  329.  
  330.     //-------------------------- FieldInit ---------------------------
  331.  
  332.     static class FieldInit extends Node {
  333.         FieldInit           next;
  334.         String              id;
  335.         Expr                expr;
  336.         FieldDecl           myFieldDecl;     // Not used until proj 6
  337.     }
  338.  
  339.  
  340.  
  341.     //-------------------------- IntegerConst ---------------------------
  342.  
  343.     static class IntegerConst extends Expr {
  344.         int            iValue;
  345.     }
  346.  
  347.  
  348.  
  349.     //-------------------------- RealConst ---------------------------
  350.  
  351.     static class RealConst extends Expr {
  352.         double       rValue;
  353.         String       nameOfConstant;         // Not used until proj 9
  354.         RealConst    next;                   // Not used until proj 9
  355.     }
  356.  
  357.  
  358.  
  359.     //-------------------------- StringConst ---------------------------
  360.  
  361.     static class StringConst extends Expr {
  362.         String         sValue;
  363.         String         nameOfConstant;       // Not used until proj 9
  364.         StringConst    next;                 // Not used until proj 9
  365.     }
  366.  
  367.  
  368.  
  369.     //-------------------------- BooleanConst ---------------------------
  370.  
  371.     static class BooleanConst extends Expr {
  372.         int            iValue;
  373.     }
  374.  
  375.  
  376.  
  377.     //-------------------------- NilConst ---------------------------
  378.  
  379.     static class NilConst extends Expr {
  380.     }
  381.  
  382.  
  383.  
  384.     //-------------------------- ValueOf ---------------------------
  385.  
  386.     static class ValueOf extends Expr {
  387.         LValue         lValue;
  388.     }
  389.  
  390.  
  391.  
  392.     //-------------------------- LValue ---------------------------
  393.  
  394.     abstract static class LValue extends Node { }
  395.  
  396.  
  397.  
  398.     //-------------------------- Variable ---------------------------
  399.  
  400.     static class Variable extends LValue {
  401.         String      id;
  402.         Node        myDef;                  // Not used until proj 5
  403.                                             // (will be either Formal or VarDecl)
  404.         int         currentLevel;           // Not used until proj 5
  405.     }
  406.  
  407.  
  408.  
  409.     //-------------------------- ArrayDeref ---------------------------
  410.  
  411.     static class ArrayDeref extends LValue {
  412.         LValue      lValue;
  413.         Expr        expr;
  414.     }
  415.  
  416.  
  417.  
  418.     //-------------------------- RecordDeref ---------------------------
  419.  
  420.     static class RecordDeref extends LValue {
  421.         LValue        lValue;
  422.         String        id;
  423.         FieldDecl     myFieldDecl;          // Not used until proj 6
  424.     }
  425.  
  426. }