Skip to content

Instantly share code, notes, and snippets.

@alksl
Created November 17, 2014 17:52
Show Gist options
  • Save alksl/7daf717c0f414906192b to your computer and use it in GitHub Desktop.
Save alksl/7daf717c0f414906192b to your computer and use it in GitHub Desktop.
#include <iterator>
#include <algorithm>
#include <schemese/scanner.h>
using namespace Schemese;
extern int yylex();
extern int yyleng;
extern char* yytext;
ScannerBuffer Scanner::buffer;
void ScannerBuffer::read_bytes(std::istream& stream) {
char c;
while((c = stream.get()) >= 0){
buffer.push(c);
}
}
unsigned long ScannerBuffer::write_bytes(char* buf, int max_size) {
unsigned long written_bytes = 0;
while(written_bytes < max_size && !buffer.empty()) {
buf[written_bytes] = buffer.front();
buffer.pop();
written_bytes++;
}
return written_bytes;
}
Scanner::Scanner(std::istream& input) : input_stream(input) {
}
TokenStream& Scanner::scan() {
// buffer.read_bytes(input_stream);
// return Token((TokenType)yylex(), std::string(yytext));
return token_stream;
}
unsigned long Scanner::read(char* buf, int max_size) {
return buffer.write_bytes(buf, max_size);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment