Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lextab.py and yacctab.py #293

Closed
masics opened this issue Nov 4, 2023 · 13 comments
Closed

lextab.py and yacctab.py #293

masics opened this issue Nov 4, 2023 · 13 comments

Comments

@masics
Copy link

masics commented Nov 4, 2023

I tried to read and understand the documentation about creating and using those file. My goal is not to create those files every time user runs my app (command line). What is the right procedure?

@dabeaz
Copy link
Owner

dabeaz commented Nov 4, 2023

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.

@masics
Copy link
Author

masics commented Nov 5, 2023

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.

@dabeaz
Copy link
Owner

dabeaz commented Nov 5, 2023

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

@masics
Copy link
Author

masics commented Nov 5, 2023

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'!='

@dabeaz
Copy link
Owner

dabeaz commented Nov 5, 2023

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.

@masics
Copy link
Author

masics commented Nov 6, 2023

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()

@dabeaz
Copy link
Owner

dabeaz commented Nov 6, 2023

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.

@masics
Copy link
Author

masics commented Nov 6, 2023

this is a class with all the definitions. Like this

@dabeaz
Copy link
Owner

dabeaz commented Nov 6, 2023

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

@masics
Copy link
Author

masics commented Nov 6, 2023

This version worked:

# PLY package
# Author: David Beazley (dave@dabeaz.com)

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

@dabeaz
Copy link
Owner

dabeaz commented Nov 6, 2023

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

@masics
Copy link
Author

masics commented Nov 6, 2023

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

@masics
Copy link
Author

masics commented Nov 13, 2023

I made changes and it is working now.

@masics masics closed this as completed Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants