ply

How to parse multiple line code using RPLY library?

一世执手 提交于 2021-02-04 08:36:45
问题 I am working on the development of a new language and I am using RPLY library for lexing and parsing purposes. Now I am stuck at getting an error when I use more than one line in the code file. here are my files:- mylexer.py from rply import LexerGenerator class Lexer(): def __init__(self): self.lexer = LexerGenerator() def _add_tokens(self): # Print self.lexer.add('PRINT', r'print') # Parenthesis self.lexer.add('OPEN_PAREN', r'\(') self.lexer.add('CLOSE_PAREN', r'\)') # Semi Colon self.lexer

Ply shift/reduce conflicts: dangling else and empty productions

笑着哭i 提交于 2021-01-29 08:46:34
问题 I had lots of conflicts, most of them were due to operators and relational operators which had different precedences. But I still face some conflicts that I don't really know how to tackle them. some of them are below. I suspect that maybe I should do epsilon elimination for stmtlist but to be honest I'm not sure about it. state 70: state 70 (27) block -> LCB varlist . stmtlist RCB (25) varlist -> varlist . vardec (28) stmtlist -> . stmt (29) stmtlist -> . stmtlist stmt (30) stmtlist -> . (15

Syntax error using empty production rule in python PLY(lex/yacc)

萝らか妹 提交于 2021-01-02 03:47:34
问题 The full example is given here: import ply.lex as lex import Property # List of token names. This is always required tokens = [ 'CheckupInformation', 'Introduction', 'Information', 'perfect', 'sick', 'LPAREN', 'RPAREN', 'CHAR', 'NUMBER' ] def t_CheckupInformation(t) : 'CheckupInformation' ; return t def t_Introduction(t) : 'Introduction' ; return t def t_Information(t) : 'Information' ; return t def t_perfect(t): 'perfect'; return t def t_sick(t) : 'sick'; return t t_LPAREN = r'\(' t_RPAREN =

Python - Display 3D Point Cloud [closed]

为君一笑 提交于 2020-03-17 07:09:07
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I have a .PLY file that contains a 3D Point Cloud: I want to plot it and visualize it in Python. The .PLY file contains ONLY vertex and NOT faces. Could you indicate me a simple Python library that will take care of plotting the 3D Point Cloud? It is important to remark that I am not interested in plotting a

Python - Display 3D Point Cloud [closed]

萝らか妹 提交于 2020-03-17 07:09:02
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I have a .PLY file that contains a 3D Point Cloud: I want to plot it and visualize it in Python. The .PLY file contains ONLY vertex and NOT faces. Could you indicate me a simple Python library that will take care of plotting the 3D Point Cloud? It is important to remark that I am not interested in plotting a

Problems with PLY LEX and YACC

寵の児 提交于 2020-03-01 03:59:30
问题 I am trying to run the first part of a simple example of the PLY but I encounter a strange error. When I run the following code, it gives me an error regarding lex.lex() Anyone knows what the problem is? import ply.lex as lex tokens = [ 'NAME','NUMBER','PLUS','MINUS','TIMES', 'DIVIDE', 'EQUALS' ] t_ignore = '\t' t_PLUS = r'\+' t_MINUS = r'-' t_TIMES = r'\*' t_DIVIDE = r'/' t_EQUALS = r'=' t_NAME = r'[a-zA-Z_][a-zA-Z0-9_]*' def t_NUMBER(t): r'\d+' t.value = int(t.value) return t lex.lex() #

How best to parse a simple grammar?

依然范特西╮ 提交于 2020-01-09 12:18:09
问题 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.)

PLY lexer for numbers always returns double

痞子三分冷 提交于 2020-01-07 07:53:20
问题 I am having trouble in ply lex with int and double using the following program. DOUBLE_VAL is returned for 1 whereas i expected INT_VAL. On changing order of INT_VAL and DOUBLE_VAL functions, i get an error on decimal point. How can i resolve them ? tokens = ( 'VERSION', 'ID', 'INT_VAL', 'DOUBLE_VAL' ) t_ignore = ' \t' def t_VERSION(t): r'VERSION' return t def t_DOUBLE_VAL(t): '[-+]?[0-9]+(\.[0-9]+)?([eE][-+]?[0-9]+)?' return t def t_INT_VAL(t): r'[-+]?[0-9]+' return t def t_ID(t): r'[a-zA-Z_

ambiguity in parsing comma as a operator using PLY python

六眼飞鱼酱① 提交于 2019-12-25 01:34:34
问题 I have following tokens and many more, but I want to keep my question short that's why not including the whole code. tokens = ( 'COMMA', 'OP', 'FUNC1', 'FUNC2' ) def t_OP(t): r'&|-|\||,' return t def t_FUNC1(t): r'FUNC1' return t def t_FUNC2(t): r'FUNC2' return t Other methods: def FUNC1(param): return {'a','b','c','d'} def FUNC2(param,expression_result): return {'a','b','c','d'} My grammar rules in YACC are and few more are there but listed important ones: 'expression : expression OP

How do I implement this in ply, given how pyparsing works

*爱你&永不变心* 提交于 2019-12-24 05:51:09
问题 I'm trying to implement something in ply, which I'm very new to, based on what I have done in pyparsing, which I'm also quite new to. How can I write a simple nesting search such as this: thecontent = pyparsing.Word(pyparsing.alphanums) | '&' | '|' parens = pyparsing.nestedExpr( '(', ')', content=thecontent) By using PLY? 回答1: What you have written in pyparsing does not translate well to PLY because, well, it's barely even a parser. nestedExpr is a helper for quickly defining an expression of