lex

Lex and Yacc in PHP [closed]

泪湿孤枕 提交于 2019-11-27 19:01:51
Is there an implementation of Lex and Yacc in PHP? If not, can anyone suggest a lexical analyser and parser generator (ie, anything like Lex and Yacc) that will create PHP code. I'm not too worried about the performance of the resulting parser. I am sick of using regex to parse things that really shouldn't be parsed with regex... There's JLexPHP: https://github.com/wez/JLexPHP/blob/master/jlex.php I've not used it, but there's this: http://pear.php.net/package/PHP_ParserGenerator , which creates a PHP Parser from a Lemon grammar. The project seems to be inactive though. I also found this

Unable to compile output of lex

青春壹個敷衍的年華 提交于 2019-11-27 18:53:02
问题 When I attempt to compile the output of this trivial lex program: # lex.l integer printf("found keyword INT"); using: $ gcc lex.yy.c I get: Undefined symbols: "_yywrap", referenced from: _yylex in ccMsRtp7.o _input in ccMsRtp7.o "_main", referenced from: start in crt1.10.6.o ld: symbol(s) not found collect2: ld returned 1 exit status lex --version tells me I'm actually using 'flex 2.5.35' although ls -fla `which lex` isn't a symlink. Any ideas why the output won't compile? 回答1: From the Flex

bison end of file

╄→尐↘猪︶ㄣ 提交于 2019-11-27 18:00:02
问题 If I forget to put an empty line at the end of any of my files my program gets a syntax error. The problem is my grammar expects a newline to end the current line. Since a newline doesn't exist bison generates a syntax error because it does not finish the rule. How do I solve this? I tried making <<EOF>> return MY_EOF BUT when I do that lex crashes a horrible death. I guess there's code in its default EOF that I am not calling. I have no idea what functions they may be. Using EOF create the

how to use yy_scan_string in lex

隐身守侯 提交于 2019-11-27 14:30:23
I want to parse a string which I give to the parser in the main function of yacc . I know that this could be done by using yy_scan_string but I don't know how to use it. I searched the web and the man pages but it is still not clear to me. Please help me. In case anyone needs the sample for a re-entrant lexer: int main(void) { yyscan_t scanner; YY_BUFFER_STATE buf; yylex_init(&scanner); buf = yy_scan_string("replace me with the string youd like to scan", scanner); yylex(scanner); yy_delete_buffer(buf, scanner); yylex_destroy(scanner); return 0; } This works for me. I have this code in the

error: unknown type name ‘bool’

眉间皱痕 提交于 2019-11-27 10:04:43
问题 I downloaded the source code and wanted to compile the file of scanner. It produces this error: [meepo@localhost cs143-pp1]$ gcc -o lex.yy.o lex.yy.c -ll In file included from scanner.l:15:0: scanner.h:59:5: error: unknown type name ‘bool’ In file included from scanner.l:16:0: utility.h:64:38: error: unknown type name ‘bool’ utility.h:74:1: error: unknown type name ‘bool’ In file included from scanner.l:17:0: errors.h:16:18: fatal error: string: No such file or directory compilation

How to make YY_INPUT point to a string rather than stdin in Lex & Yacc (Solaris)

狂风中的少年 提交于 2019-11-27 08:55:42
I want my yylex() to parse a string rather than a file or standard input. How can I do it with the Lex and Yacc provided with Solaris? Redefine YY_INPUT. Here's a working example, compile and run with the commands yacc -d parser.y lex lexer.l gcc -o myparser *.c Input is read from globalInputText. You can modify this example so that global input text is whatever string you want or from any input source you want. parser.y: %{ #include <stdio.h> extern void yyerror(char* s); extern int yylex(); extern int readInputForLexer(char* buffer,int *numBytesRead,int maxBytesToRead); %} %token FUNCTION

Is it possible to have two or more Lex/Yacc parsers in the same application

断了今生、忘了曾经 提交于 2019-11-27 07:45:21
问题 I have an application where I already have a parser for one sort of grammar and I need to add a second different grammar for another purpose. Is it possible to have more than one? And if so how do you get another entry point? Thanks david allan finch 回答1: I think you can to this by using the --name-prefix option to Bison, and the --prefix option to Flex. In both cases they allow you to replace the default " yy " prefix used on the functions generated with a prefix of your own choice. 回答2: Yes

String input to flex lexer

一笑奈何 提交于 2019-11-27 03:47:34
I want to create a read-eval-print loop using flex/bison parser. Trouble is, the flex generated lexer wants input of type FILE* and i would like it to be char*. Is there anyway to do this? One suggestion has been to create a pipe, feed it the string and open the file descriptor and send to the lexer. This is fairly simple but it feels convoluted and not very platform independent. Is there a better way? The following routines are available for setting up input buffers for scanning in-memory strings instead of files (as yy_create_buffer does): YY_BUFFER_STATE yy_scan_string(const char *str) :

Resources for lexing, tokenising and parsing in python

旧街凉风 提交于 2019-11-26 23:53:05
问题 Can people point me to resources on lexing, parsing and tokenising with Python? I'm doing a little hacking on an open source project (hotwire) and wanted to do a few changes to the code that lexes, parses and tokenises the commands entered into it. As it is real working code it is fairly complex and a bit hard to work out. I haven't worked on code to lex/parse/tokenise before, so I was thinking one approach would be to work through a tutorial or two on this aspect. I would hope to learn