<commit_before>//
//  automaton.cpp
//  lut-lang
//
//  Created by <NAME> on 06/03/2015.
//  Copyright (c) 2015 H4314. All rights reserved.
//
#include <string>
#include <stack>
#include "Automaton.h"
#include "states/E0.h"
using std::string;

Automaton::Automaton(string inputString) {
  lexer = new Lexer(inputString);
  stackStates.push(new E0());
  accepted = false;
}

/**
 * Push token and states on the stack : Decalage case
 */
void Automaton::decalage(ASTNode* t, State* s) {
  stackStates.push(s);
  stackASTTokenNodes.push(t);
}

/**
 * @return The wether or not the program is correct syntaxically
 */
bool Automaton::analyze() {
  while ( lexer->top()->getTokenType() != TokenType::ENDOFFILE ) {
    lexer->shift();
    if ( stackStates.empty() ) return false;
    ASTTokenNode *t = lexer->top();
    if ( t == NULL ) return false;  //  wrong token case
    if ( !stackStates.top()->transition(this, t) ) return false;
  }
  if ( stackStates.empty() ) return false;

  return accepted;
}

stack<State*> *Automaton::getStackStates() {
  return &this->stackStates;
}

stack<ASTNode*> *Automaton::getStackASTNodes() {
  return &this->stackASTTokenNodes;
}

/**
 * @Accepted is set to true when the end transition is runned.
 */
void Automaton::setAccepted(bool acc) {
  this->accepted = acc;
}<commit_msg>print program<commit_after>//
//  automaton.cpp
//  lut-lang
//
//  Created by <NAME> on 06/03/2015.
//  Copyright (c) 2015 H4314. All rights reserved.
//
#include <string>
#include <stack>
#include "Automaton.h"
#include "states/E0.h"
#include "ASTProgramNode.h"
using std::string;

Automaton::Automaton(string inputString) {
  lexer = new Lexer(inputString);
  stackStates.push(new E0());
  accepted = false;
}

/**
 * Push token and states on the stack : Decalage case
 */
void Automaton::decalage(ASTNode* t, State* s) {
  stackStates.push(s);
  stackASTTokenNodes.push(t);
}

/**
 * @return The wether or not the program is correct syntaxically
 */
bool Automaton::analyze() {
  while ( lexer->top()->getTokenType() != TokenType::ENDOFFILE ) {
    lexer->shift();
    if ( stackStates.empty() ) return false;
    ASTTokenNode *t = lexer->top();
    if ( t == NULL ) return false;  //  wrong token case
    if ( !stackStates.top()->transition(this, t) ) return false;
  }
  if ( stackStates.empty() ) return false;

  if (accepted) {
    ASTProgramNode *program = (ASTProgramNode *) stackASTTokenNodes.top();
    program->print();
  }
  return accepted;
}

stack<State*> *Automaton::getStackStates() {
  return &this->stackStates;
}

stack<ASTNode*> *Automaton::getStackASTNodes() {
  return &this->stackASTTokenNodes;
}

/**
 * @Accepted is set to true when the end transition is runned.
 */
void Automaton::setAccepted(bool acc) {
  this->accepted = acc;
}
{'fraction_non_alphanumeric': 0.15700396110911055, 'fraction_numerical': 0.012963629816348578, 'mean_word_length': 3.8397212543554007, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5677554', 'n_tokens_mistral': 978, 'n_tokens_neox': 939, 'n_words': 242}