koscript_parser.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <iostream>
00021
00022 #include <qstring.h>
00023
00024 #include <klocale.h>
00025
00026 #include "koscript_parser.h"
00027 #include "koscript_parsenode.h"
00028
00029 extern FILE* yyin;
00030 extern char* yytext;
00031 extern int yylex();
00032
00033 KSParser *theParser;
00034
00035 QString idl_lexFile;
00036 QString toplevelFile;
00037 int idl_line_no;
00038
00039
00040 extern void kscriptParse( const char *_code, int extension, KLocale* locale );
00041 extern void kscriptParse( int extension, KLocale* locale );
00042
00043 KSParser::KSParser()
00044 {
00045 rootNode = 0;
00046 }
00047
00048 KSParser::~KSParser()
00049 {
00050 if ( rootNode )
00051 delete rootNode;
00052 }
00053
00054 bool KSParser::parse( FILE *inp_file, const char *filename, int extension, KLocale* locale )
00055 {
00056 idl_lexFile = toplevelFile = const_cast<char *>(filename);
00057 yyin = inp_file;
00058
00059 m_errorMessage = "";
00060 theParser = this;
00061 idl_line_no = 1;
00062 kscriptParse( extension, locale );
00063
00064 return m_errorMessage.isEmpty();
00065 }
00066
00067 bool KSParser::parse( const char* code, int extension, KLocale* locale )
00068 {
00069 m_errorMessage = "";
00070 theParser = this;
00071 idl_line_no = 1;
00072 kscriptParse( code, extension, locale );
00073
00074 return m_errorMessage.isEmpty();
00075 }
00076
00077 void KSParser::setRootNode( KSParseNode *node )
00078 {
00079 rootNode = node;
00080 }
00081
00082
00083 KSParseNode *KSParser::getRootNode()
00084 {
00085 return rootNode;
00086 }
00087
00088
00089 void KSParser::parse_error( const char *file, const char *err, int line )
00090 {
00091 m_errorMessage = "%1:%2: %3 before '%4'";
00092 m_errorMessage = m_errorMessage.arg( file ).arg( line ).arg( err ).arg( yytext );
00093 }
00094
00095 void KSParser::print( bool detailed )
00096 {
00097 if ( rootNode )
00098 rootNode->print( detailed );
00099 }
00100
00101 bool KSParser::eval( KSContext& context )
00102 {
00103 if ( !rootNode )
00104 return FALSE;
00105
00106 return rootNode->eval( context );
00107 }
00108
00109 KSParseNode* KSParser::donateParseTree()
00110 {
00111 KSParseNode* n = rootNode;
00112 rootNode = 0;
00113 return n;
00114 }
This file is part of the documentation for lib Library Version 1.3.5.