aboutsummaryrefslogblamecommitdiff
path: root/parser.cpp
blob: c53ec14dd2a45d6931a503a9d0b06e903fccf5c7 (plain) (tree)
1
2
3
4
5
6
7
8



                   

                   
                    
               



                                  
                                               
                        
 
                                                                          



                                           

                        



                      
                        
                                
                      
                                                   

                        

                        
                          

                                         
 
             




                             
                             
 
                                 
                              
                                    

                                           
               

 




                                        
                     
         

                             
             





                                                     
                                                              

                                                                  
             



                                                                
                                 
             
                                                            



                                
                                                               
                 












                                                                               
                                          



                                                                    
                                                                       
                     

                 
                                          
             

                                             
                    
                                     
             
                                  
         

                              
                                    


                               



                                                  

                                                      




                                                         
                                                                            
 







                                     
                                           
                                     

            


                                                               
                                        






                                                            

                                                                              




                                                              
                                                                 
                     
                                               
                                         
                                             



                                                           

                              

                                                                     

                                      
                                                                      
             


                                                                               

                                            
                                                        
                                                                 
                                    
                                            


                    
                                                                           

                               
             
 




                                                      
                                                                       
                                           
                                                                                          

                                             
                                                  
             
         

                                                     

     
#include <cstdio>
#include <cctype>
#include <sstream>
#include "parser.h"
#include "exc.h"
#include "consts.h"
#include "builtin.h"
#include "gc.h"

using std::stringstream;

static char buff[TOKEN_BUFF_SIZE];
static FrameObj *parse_stack[PARSE_STACK_SIZE];
extern Pair *empty_list;

Tokenizor::Tokenizor() : stream(stdin), buff_ptr(buff), escaping(false) {}
void Tokenizor::set_stream(FILE *_stream) {
    stream = _stream;
}

#define IS_NEWLINE(ch) \
    ((ch) == '\n')
#define IS_QUOTE(ch) \
    ((ch) == '\"')
#define IS_SLASH(ch) \
    ((ch) == '\\')
#define IS_BRACKET(ch) \
    ((ch) == '(' || (ch) == ')')
#define IS_SPACE(ch) \
    ((ch) == ' ' || (ch) == '\t' || IS_NEWLINE(ch))
#define IS_COMMENT(ch) \
    ((ch) == ';')
#define IS_LITERAL(ch) \
    ((ch) == '\'')
#define IS_DELIMITER(ch) \
    (IS_BRACKET(ch) || IS_SPACE(ch) ||  \
     IS_COMMENT(ch) || IS_QUOTE(ch))

#define POP \
    do { \
        *buff_ptr = 0; \
        ret = string(buff); \
        buff_ptr = buff; \
    } while (0)
#define TOP (*(buff_ptr - 1))

string str_to_lower(string str) {
    size_t len = str.length();
    for (size_t i = 0; i <