/*! Initialize the Expression Evalutor*/ int InitEva() { /*Create symbol table for handling variables*/ symtab = antlr3HashTableNew(1); if (symtab == NULL) { return 1; } fExpressionResult = AllocateAndInitNumber(); mpf_set_d(*fExpressionResult, 0); return 0; }
int main(int argc, char *argv[]) { pANTLR3_UINT8 filename; pANTLR3_INPUT_STREAM input=NULL; pProtoJSLexer lxr; pANTLR3_COMMON_TOKEN_STREAM tstream; pProtoJSParser psr; ProtoJSParser_protocol_return pbjAST; if (argc < 2 || argv[1] == NULL) filename = (pANTLR3_UINT8)"./input"; else filename = (pANTLR3_UINT8)argv[1]; const char * outputFilename="output"; if (argc>=3) { outputFilename=argv[2]; } char * csOut=NULL; char * cppOut=NULL; char * cppInclude=NULL; int argindex; const char *outputInternalNamespace="_ProtoJS_Internal"; const char *outputExternalNamespace=""; for (argindex=3;argindex<argc;++argindex) { if (strncmp(argv[argindex],"--cpp=",6)==0) { cppOut=argv[argindex]+6; } if (strncmp(argv[argindex],"--cs=",5)==0) { csOut=argv[argindex]+5; } if (strncmp(argv[argindex],"--include=",10)==0) { cppInclude=argv[argindex]+10; } if (strncmp(argv[argindex],"--inamespace=",13)==0) { outputInternalNamespace=argv[argindex]+13; } if (strncmp(argv[argindex],"--namespace=",12)==0) { outputExternalNamespace=argv[argindex]+12; } } char*package=parsePackage((const char*)filename,outputFilename,outputInternalNamespace,outputExternalNamespace); pANTLR3_HASH_TABLE qualifiedTypes=antlr3HashTableNew(11); parseTypes((const char*)filename,outputFilename,outputInternalNamespace,outputExternalNamespace,package,qualifiedTypes); if(generateASTProto((const char*)filename,outputFilename,outputInternalNamespace,outputExternalNamespace,package,qualifiedTypes,&pbjAST,&lxr,&psr,&tstream,&input)) { pANTLR3_COMMON_TREE_NODE_STREAM nodes; nodes = antlr3CommonTreeNodeStreamNewTree(pbjAST.tree, ANTLR3_SIZE_HINT); // sIZE HINT WILL SOON BE DEPRECATED!! pANTLR3_STRING s = nodes->stringFactory->newRaw(nodes->stringFactory); grammarToString(nodes->tnstream,nodes->root,NULL,s); FILE*fp=fopen(outputFilename,"w"); if (!fp) { perror("Unable to open output file!"); exit(2); } if (s->size>1) fwrite(s->chars,s->size-1,1,fp); fclose(fp); stringFree(s); nodes ->free (nodes); nodes = NULL; } psr->free(psr); psr = NULL; tstream->free(tstream); tstream = NULL; lxr->free(lxr); lxr = NULL; input->close(input); input = NULL; return 0; }