ply

Python/YACC: Resolving a shift/reduce conflict

£可爱£侵袭症+ 提交于 2019-12-02 15:40:59
问题 I'm using PLY. Here is one of my states from parser.out : state 3 (5) course_data -> course . (6) course_data -> course . course_list_tail (3) or_phrase -> course . OR_CONJ COURSE_NUMBER (7) course_list_tail -> . , COURSE_NUMBER (8) course_list_tail -> . , COURSE_NUMBER course_list_tail ! shift/reduce conflict for OR_CONJ resolved as shift $end reduce using rule 5 (course_data -> course .) OR_CONJ shift and go to state 7 , shift and go to state 8 ! OR_CONJ [ reduce using rule 5 (course_data -

Pyinstaller and Ply IOError: source code not available

余生长醉 提交于 2019-12-02 08:56:21
问题 I am pretty new to pyinstaller but I have been banging my head against this problem for a couple of days now and I can't seem to figure out what's wrong. My script runs fine normally but throws IOerror when i try to build with pyinstaller, my modules (including ply.lex) seem to be included but maybe i'm being an idiot? If anyone has any advice it would be much appreciated... Here's my error (line 65 is where my lexer is built) Traceback (most recent call last): File "<string>", line 65, in

Parsing tokens with PLY

淺唱寂寞╮ 提交于 2019-12-02 06:26:07
问题 I've been trying to parse some given text with PLY for a while and I haven't been able to figure it out. I have these tokens defined: tokens = ['ID', 'INT', 'ASSIGNMENT'] And I want to classify the words I find into these tokens. For example, if the scanner is given: var = 5 It should print this: ID : 'var' ASSIGNMENT : '=' INT : 5 This works just fine. The problem is when the program is given the following text: 9var = 5 The output for this would be: INT : 9 ID : 'var' ASSIGNMENT : '=' INT :

Ply Lex parsing problem

ぐ巨炮叔叔 提交于 2019-12-01 17:23:00
I'm using ply as my lex parser. My specifications are the following : t_WHILE = r'while' t_THEN = r'then' t_ID = r'[a-zA-Z_][a-zA-Z0-9_]*' t_NUMBER = r'\d+' t_LESSEQUAL = r'<=' t_ASSIGN = r'=' t_ignore = r' \t' When i try to parse the following string : "while n <= 0 then h = 1" It gives following output : LexToken(ID,'while',1,0) LexToken(ID,'n',1,6) LexToken(LESSEQUAL,'<=',1,8) LexToken(NUMBER,'0',1,11) LexToken(ID,'hen',1,14) ------> PROBLEM! LexToken(ID,'h',1,18) LexToken(ASSIGN,'=',1,20) LexToken(NUMBER,'1',1,22) It doesn't recognize the token THEN, instead it takes "hen" as an identifier

yacc - Precedence of a rule with no operator?

扶醉桌前 提交于 2019-12-01 12:03:09
Thinking about parsing regular expressions using yacc (I'm actually using PLY), some of the rules would be like the following: expr : expr expr expr : expr '|' expr expr : expr '*' The problem is, the first rule(concatenation) must take precedence over the second rule, but not the third one. However, the concatenation rule has no operator in it. How can I specify the precedence correctly in this case? Thank you! EDIT: I modified the rules to avoid the issue, but I'm still curious what was the problem. Here is the source code: tokens = ['PLEFT', 'PRIGHT', 'BAR', 'ASTERISK', 'NORMAL'] t_PLEFT =

How best to parse a simple grammar?

拜拜、爱过 提交于 2019-11-28 16:14:00
Ok, so I've asked a bunch of smaller questions about this project, but I still don't have much confidence in the designs I'm coming up with, so I'm going to ask a question on a broader scale. I am parsing pre-requisite descriptions for a course catalog. The descriptions almost always follow a certain form, which makes me think I can parse most of them. From the text, I would like to generate a graph of course pre-requisite relationships. (That part will be easy, after I have parsed the data.) Some sample inputs and outputs: "CS 2110" => ("CS", 2110) # 0 "CS 2110 and INFO 3300" => [("CS", 2110)