Example #1
0
lcpp::Ptr<lcpp::LispObject>
lcpp::Reader::read(ezStringIterator& input, bool resetSyntaxChecker)
{
    if(resetSyntaxChecker)
    {
        m_pSyntaxCheckResult->reset();
    }

    skipSeparators(input);

    if(!input.IsValid())
    {
        return LCPP_VOID;
    }

    switch(input.GetCharacter())
    {
    case ')':
        throw exceptions::InvalidInput("Unexpected character ')'.");
    case '\'':
        // TODO read quote
        throw exceptions::NotImplemented("Not supporting quote yet.");
        break;
    case '"':
        return parseString(input);
        break;
    case '(':
        return parseList(input);
        break;
    }

    return parseAtom(input);
}
Example #2
0
bool SamiParser::isParsable() const {
    if (_Same(file().suffix(), "smi") || _Same(file().suffix(), "sami"))
        return true;
    if (skipSeparators())
        return false;
    if (all().startsWith("<sami", Qt::CaseInsensitive))
        return true;
    return false;
}
Example #3
0
 Token TokenStream::next()
 {
   Token token;
   skipSeparators();
   ParseLocation loc = cin->loc();
   if (trySymbols   (token,loc)) return token;      /**< try to parse a symbol */
   if (tryFloat     (token,loc)) return token;      /**< try to parse float */
   if (tryInt       (token,loc)) return token;      /**< try to parse integer */
   if (tryString    (token,loc)) return token;      /**< try to parse string */
   if (tryIdentifier(token,loc)) return token;      /**< try to parse identifier */
   if (cin->peek() == EOF  )     return Token(loc); /**< return EOF token */
   return Token((char)cin->get(),loc);       /**< return invalid character token */
 }
Example #4
0
t_token AlexicalAnalizer::nextToken(void) {
  t_token token;
  int token2 = -1;

  // Trata comentários
  skipSeparators();
  // Alfa numerico
  if (isalpha(next_char)) {
    // Palavras Reservadas
    char text[MAX_STRING_SIZE];
    // init text
    for (int i=0; i<MAX_STRING_SIZE ;i++) { text[i] = '\0'; }
    int i = 0;
    do {
      text[i++] = next_char;
      next_char = readChar();
    } while (isalnum(next_char) || next_char == '_');
    // discover alpha type
    token = searchKeyWord(text);
    // if is a id, add to table
    if (token == ID) { token2 = searchName(text); }
  }
  // Numeral
  else if (isdigit(next_char)) {
    int n = 0;
    do {
      n = n * 10 + (next_char - '0');
      next_char = readChar();
    } while (isdigit(next_char));

    // update token variables
    token = NUMERAL;
    token2 = addIntConst(n);
  }
  // Stringval
  else if (next_char == '"') {
    char string[MAX_STRING_SIZE + 1];
    int i = 0;
    // to remove '"' from string
    next_char = readChar();
    // store value of string on variable
    do {
      string[i++] = next_char;
      next_char = readChar();
    } while (next_char != '"');
    next_char = readChar();

    // update token variables
    token = STRINGVAL;
    token2 = addStringConst(string);
  } else {
    switch (next_char) {
    /************
     * SIMBOLOS *
     ************/
    case '.':
      next_char = readChar();
      token = DOT;
      break;
    // COLON
    case ':':
      next_char = readChar();
      token = COLON;
      break;
    // SEMI_COLON
    case ';':
      next_char = readChar();
      token = SEMI_COLON;
      break;
    // COMMA
    case ',':
      next_char = readChar();
      token = COMMA;
      break;
    // 'Squares'
    case '[':
      next_char = readChar();
      token = LEFT_SQUARE;
      break;
    case ']':
      next_char = readChar();
      token = RIGHT_SQUARE;
      break;
    // Braces
    case '{':
      next_char = readChar();
      token = LEFT_BRACES;
      break;
    case '}':
      next_char = readChar();
      token = RIGHT_BRACES;
      break;
    // Parenthesis
    case '(':
      next_char = readChar();
      token = LEFT_PARENTHESIS;
      break;
    case ')':
      next_char = readChar();
      token = RIGHT_PARENTHESIS;
      break;
    // Less_than and Less_or_equal
    case '<':
      next_char = readChar();
      token = LESS_THAN;
      if (next_char == '=') {
        token = LESS_OR_EQUAL;
        next_char = readChar();
      }
      break;
    // Greater_than and Greater_or_equal
    case '>':
      next_char = readChar();
      token = GREATER_THAN;
      if (next_char == '=') {
        token = GREATER_OR_EQUAL;
        next_char = readChar();
      }
      break;
    // Not_equal
    case '!':
      next_char = readChar();
      if (next_char == '=') {
        token = NOT_EQUAL;
        next_char = readChar();
      } else {
        token = NOT;
      }
      break;
    // Equals and equal_equal
    case '=':
      next_char = readChar();
      if (next_char == '=') {
        token = EQUAL_EQUAL;
        next_char = readChar();
      } else {
        token = EQUALS;
      }
      break;
    // Plus and plus_plus
    case '+':
      next_char = readChar();
      if (next_char == '+') {
        token = PLUS_PLUS;
        next_char = readChar();
      } else {
        token = PLUS;
      }
      break;
    // Minus and minus_minus
    case '-':
      next_char = readChar();
      if (next_char == '-') {
        token = MINUS_MINUS;
        next_char = readChar();
      } else {
        token = MINUS;
      }
      break;
    // Times
    case '*':
      next_char = readChar();
      token = TIMES;
      break;
    // Divide
    case '/':
      next_char = readChar();
      token = DIVIDE;
      break;
    /********************
     * Tokens Regulares *
     ********************/
    // Character
    case '\'':
      next_char = readChar();
      // update token variable
      token = CHARACTER;
      token2 = addCharConst(next_char);
      next_char = readChar();
      if ('\'' != next_char)
        token = UNKNOWN;
      next_char = readChar();
      break;
    }
  }
  // setup last token variables
  last_token = token;
  last_token2 = token2;

  return token;
}