Beispiel #1
0
  public StringLiteral(GOLDParser parser) {
    // The null test is being performed because this class is used in a test where the parser
    // is not completely initialized.  In production, the current reduction will always be set.
    String str =
        parser.getCurrentReduction() == null
            ? "\"\""
            : parser.getCurrentReduction().get(0).asString();

    StringBuilder sb = new StringBuilder(str);
    sb.deleteCharAt(sb.length() - 1);
    sb.deleteCharAt(0);
    setValue(new Variable(sb.toString()));
  }
Beispiel #2
0
 public Statements(GOLDParser parser) {
   Reduction reduction = parser.getCurrentReduction();
   if (reduction != null) {
     if (reduction.size() > 0 && reduction.size() < 3) {
       statement1 = reduction.get(0).asReduction();
       statement2 = (reduction.size() > 1) ? reduction.get(1).asReduction() : null;
     } else {
       parser.raiseParserException(
           Simple2.formatMessage(
               "error.param_count_range", "1", "2", String.valueOf(reduction.size())));
     }
   } else {
     parser.raiseParserException(Simple2.formatMessage("error.no_reduction"));
   }
 }
Beispiel #3
0
 @Override
 public void execute() throws ParserException {
   // Write the data to the console
   ioDriver.write(dataToPrint.getValue().asObject().toString());
   if (variableName != null) {
     // Read console input from the user (assuming that EOLN is not echoed to console)
     StringBuilder sb = new StringBuilder(ioDriver.read());
     theParser.setProgramVariable(variableName, new Variable(sb.toString()));
   } else {
     ioDriver.write(EOLN);
   }
 }
Beispiel #4
0
 public Print(GOLDParser parser) {
   theParser = parser;
   Reduction reduction = parser.getCurrentReduction();
   if (reduction != null) {
     if (reduction.size() == 2) {
       dataToPrint = reduction.get(1).asReduction();
       variableName = null;
     } else if (reduction.size() == 4) {
       dataToPrint = reduction.get(1).asReduction();
       variableName = reduction.get(3).asString();
     } else {
       if (reduction.size() < 3) {
         // print x form
         parser.raiseParserException(
             Simple3.formatMessage("error.param_count", "2", String.valueOf(reduction.size())));
       }
       // print x read y form
       parser.raiseParserException(
           Simple3.formatMessage("error.param_count", "4", String.valueOf(reduction.size())));
     }
   } else {
     parser.raiseParserException(Simple3.formatMessage("error.no_reduction"));
   }
 }