Code Monkey home page Code Monkey logo

Comments (13)

dabeaz avatar dabeaz commented on July 29, 2024

The current Github version of PLY writes no such files. In older versions, there are optional arguments to lex() and yacc() that control this. I can't recall what they are off the top of my head, but honestly, you should probably be using the Github version of code instead.

from ply.

masics avatar masics commented on July 29, 2024

I tried to use a latest version but it throws me errors:

ERROR: Rule 't_STRING_LITERAL' defined for an unspecified token STRING_LITERAL
ERROR: Rule 't_LBRACKET' defined for an unspecified token LBRACKET
ERROR: Rule 't_PERIOD' defined for an unspecified token PERIOD
ERROR: Rule 't_RBRACKET' defined for an unspecified token RBRACKET
ERROR: Rule 't_LNOT' defined for an unspecified token LNOT
ERROR: Rule 't_NOT' defined for an unspecified token NOT

and won't allow to proceed.

It is working fine with the pervious version. And I have a lot other tokens.

from ply.

dabeaz avatar dabeaz commented on July 29, 2024

These errors have nothing to do with files and are probably due to a bad tokens specification. Can't say without any example code.

from ply.

masics avatar masics commented on July 29, 2024

I don't know what could be wrong here (and it worked fine with previous version):

tokens = reserved + (
    # Literals (identifier, integer constant, float constant, string constant,
    # char const)
    'ID', 'SCONST',

    # constants
    'INT_CONST_DEC', 'INT_CONST_OCT', 'INT_CONST_HEX', 'INT_CONST_BIN',

    # Operators (+,-,*,/,%,|,&,~,^,<<,>>, ||, &&, !, <, <=, >, >=, ==, !=)
    'PLUS', 'MINUS', 'TIMES', 'DIVIDE', 'MOD',
    'OR', 'AND', 'NOT', 'XOR', 'LSHIFT', 'RSHIFT',
    'LOR', 'LAND', 'LNOT',
    'LT', 'LE', 'GT', 'GE', 'EQ', 'NE',

    # Assignment (=, *=, /=, %=, +=, -=, <<=, >>=, &=, ^=, |=)
    'EQUALS', 'TIMESEQUAL', 'DIVEQUAL', 'MODEQUAL', 'PLUSEQUAL', 'MINUSEQUAL',
    'LSHIFTEQUAL', 'RSHIFTEQUAL', 'ANDEQUAL', 'XOREQUAL', 'OREQUAL',

    # Increment/decrement (++,--)
    'PLUSPLUS', 'MINUSMINUS',

    # Structure dereference (->)
    'ARROW',

    # Conditional operator (?)
    'CONDOP',

    # Delimeters ( ) [ ] { } , . ; :
    'LPAREN', 'RPAREN',
    'LBRACKET', 'RBRACKET',
    'LBRACE', 'RBRACE',
    'COMMA', 'PERIOD', 'SEMI', 'COLON',

    # Ellipsis (...)
    'ELLIPSIS',
)

# Completely ignored characters
t_ignore = ' \t\x0c'

# Newlines


def t_NEWLINE(t):
    r'\n+'
    t.lexer.lineno += t.value.count("\n")

# Operators
t_PLUS = r'\+'
t_MINUS = r'-'
t_TIMES = r'\*'
t_DIVIDE = r'/'
t_MOD = r'%'
t_OR = r'\|'
t_AND = r'&'
t_NOT = r'~'
t_XOR = r'\^'
t_LSHIFT = r'<<'
t_RSHIFT = r'>>'
t_LOR = r'\|\|'
t_LAND = r'&&'
t_LNOT = r'!'
t_LT = r'<'
t_GT = r'>'
t_LE = r'<='
t_GE = r'>='
t_EQ = r'=='
t_NE = r'!='

from ply.

dabeaz avatar dabeaz commented on July 29, 2024

You don't show how you're creating the lexer and the error messages reference variables that aren't even defined in the above code sample. So, hard to say.

from ply.

masics avatar masics commented on July 29, 2024

I build it as:

        self.clex = lexer(
            error_func=self._lex_error_func,
            on_lbrace_func=self._lex_on_lbrace_func,
            on_rbrace_func=self._lex_on_rbrace_func,
            type_lookup_func=self._lex_type_lookup_func)

        self.clex.build()

from ply.

dabeaz avatar dabeaz commented on July 29, 2024

I don't know what this lexer() function/object is, but it's not part of PLY (old or new). So, I have no idea. Sorry.

from ply.

masics avatar masics commented on July 29, 2024

this is a class with all the definitions. Like this

from ply.

dabeaz avatar dabeaz commented on July 29, 2024

Will have to investigate further. Do you know the last known version of PLY that worked with this?

from ply.

masics avatar masics commented on July 29, 2024

This version worked:

# PLY package
# Author: David Beazley ([email protected])

__version__ = '3.9'
__all__ = ['lex','yacc']

from ply.

dabeaz avatar dabeaz commented on July 29, 2024

And what are you doing exactly? Is the goal to simply use pycparser or is something else going on? Are you extending it?

from ply.

masics avatar masics commented on July 29, 2024

I just used it as a template for my own parser (for another custom language).

from ply.

masics avatar masics commented on July 29, 2024

I made changes and it is working now.

from ply.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.