uppaal2jetracer.parser.declarationparser package
Subpackages
- uppaal2jetracer.parser.declarationparser.ply package
- Submodules
- uppaal2jetracer.parser.declarationparser.ply.lex module
- uppaal2jetracer.parser.declarationparser.ply.yacc module
Grammar
Grammar.add_production()
Grammar.build_lritems()
Grammar.compute_first()
Grammar.compute_follow()
Grammar.find_unreachable()
Grammar.infinite_cycles()
Grammar.set_precedence()
Grammar.set_start()
Grammar.undefined_symbols()
Grammar.unused_precedence()
Grammar.unused_rules()
Grammar.unused_terminals()
GrammarError
LALRError
LRGeneratedTable
LRGeneratedTable.add_lalr_lookaheads()
LRGeneratedTable.add_lookaheads()
LRGeneratedTable.compute_follow_sets()
LRGeneratedTable.compute_lookback_includes()
LRGeneratedTable.compute_nullable_nonterminals()
LRGeneratedTable.compute_read_sets()
LRGeneratedTable.dr_relation()
LRGeneratedTable.find_nonterminal_transitions()
LRGeneratedTable.lr0_closure()
LRGeneratedTable.lr0_goto()
LRGeneratedTable.lr0_items()
LRGeneratedTable.lr_parse_table()
LRGeneratedTable.pickle_table()
LRGeneratedTable.reads_relation()
LRGeneratedTable.write_table()
LRItem
LRParser
LRTable
MiniProduction
NullLogger
ParserReflect
ParserReflect.get_all()
ParserReflect.get_error_func()
ParserReflect.get_pfunctions()
ParserReflect.get_precedence()
ParserReflect.get_start()
ParserReflect.get_tokens()
ParserReflect.signature()
ParserReflect.validate_all()
ParserReflect.validate_error_func()
ParserReflect.validate_modules()
ParserReflect.validate_pfunctions()
ParserReflect.validate_precedence()
ParserReflect.validate_start()
ParserReflect.validate_tokens()
PlyLogger
Production
VersionError
YaccError
YaccProduction
YaccSymbol
call_errorfunc()
digraph()
errok()
format_result()
format_stack_entry()
get_caller_module_dict()
parse()
parse_grammar()
restart()
rightmost_terminal()
token()
traverse()
yacc()
- uppaal2jetracer.parser.declarationparser.ply.ygen module
- Module contents
Submodules
uppaal2jetracer.parser.declarationparser.declaration_lexer module
This module provides a lexer for the UPPAAL declaration language. It leverages the PLY (Python Lex-Yacc) library to tokenize input strings according to the specific syntax rules of UPPAAL declarations. The lexer is implemented in the DeclarationLexer class, which includes support for handling custom errors, tracking file-related metadata, and identifying specific tokens such as keywords, identifiers, constants, operators, and string literals.
Based on the c_lexer.py from the pycparser project by Eli Bendersky (https://eli.thegreenplace.net) under the BSD license.
- Classes:
DeclarationLexer: Implements a custom lexer for UPPAAL declarations with methods for input handling, token generation, and error handling.
- Key Features:
Recognizes reserved keywords, custom identifiers, constants, and various operators.
Provides hooks for handling specific events like opening and closing braces.
Offers mechanisms to handle typographical lookups for typedef names.
- Usage:
This lexer can be used to tokenize UPPAAL declaration files by creating an instance of DeclarationLexer, providing necessary callback functions, and calling its build, input, and token methods as needed.
- class DeclarationLexer(error_func, on_lbrace_func, on_rbrace_func, type_lookup_func)[source]
Bases:
object
A lexer for the UPPAAL declaration language. After building it, set the input text with input(), and call token() to get new tokens.
The public attribute filename can be set to an initial filename, but the lexer will update it upon #line directives.
- Variables:
error_func – An error function. Will be called with an error message, line, and column as arguments, in case of an error during lexing.
on_lbrace_func – Function triggered when an opening brace ‘{’ is encountered.
on_rbrace_func – Function triggered when a closing brace ‘}’ is encountered.
type_lookup_func – A type lookup function. Given a string, it must return True if this string is a name of a type that was defined with a typedef earlier.
filename – Tracks the filename, updating it upon #line directives.
last_token – Keeps track of the last token returned from self.token().
line_pattern – A compiled regular expression for matching “# line” or “# <num>” patterns.
pragma_pattern – A compiled regular expression for matching “# pragma” patterns.
lexer – The PLY lexer object created after calling the build() method.
- BAD_CHAR_CONST = '(\'([^\'\\\\\\n]|(\\\\(([a-wyzA-Z._~!=&\\^\\-\\\\?\'"]|x(?![0-9a-fA-F]))|(\\d+)(?!\\d))))[^\'\\n]+\')|(\'\')|(\'([\\\\][^a-zA-Z._~^!=&\\^\\-\\\\?\'"x0-9])[^\'\\n]*\')'
- BAD_ESCAPE = '([\\\\][^a-zA-Z._~^!=&\\^\\-\\\\?\'"x0-9])'
- BOOL_CONST = '(true|false)'
- CCONST_CHAR = '([^\'\\\\\\n]|(\\\\(([a-wyzA-Z._~!=&\\^\\-\\\\?\'"]|x(?![0-9a-fA-F]))|(\\d+)(?!\\d))))'
- DECIMAL_ESCAPE = '(\\d+)(?!\\d)'
- ESCAPE_SEQUENCE_START_IN_STRING = '(\\\\[0-9a-zA-Z._~!=&\\^\\-\\\\?\'"])'
- EXPONENT_PART = '([eE][-+]?[0-9]+)'
- FRACTIONAL_CONSTANT = '([0-9]*\\.[0-9]+)|([0-9]+\\.)'
- IDENTIFIER = '[a-zA-Z_][0-9a-zA-Z_]*'
- SIMPLE_ESCAPE = '([a-wyzA-Z._~!=&\\^\\-\\\\?\'"]|x(?![0-9a-fA-F]))'
- STRING_CHAR = '([^"\\\\\\n]|(\\\\[0-9a-zA-Z._~!=&\\^\\-\\\\?\'"]))'
- bad_string_literal = '"([^"\\\\\\n]|(\\\\[0-9a-zA-Z._~!=&\\^\\-\\\\?\'"]))*([\\\\][^a-zA-Z._~^!=&\\^\\-\\\\?\'"x0-9])([^"\\\\\\n]|(\\\\[0-9a-zA-Z._~!=&\\^\\-\\\\?\'"]))*"'
- build(**kwargs)[source]
Builds the lexer from the specification. Must be called after the lexer object is created.
This method exists separately, because the PLY manual warns against calling lex.lex inside __init__
- char_const = '\'([^\'\\\\\\n]|(\\\\(([a-wyzA-Z._~!=&\\^\\-\\\\?\'"]|x(?![0-9a-fA-F]))|(\\d+)(?!\\d))))\''
- decimal_constant = '(0)|([1-9][0-9]*)'
- double_constant = '(((( ([0-9]*\\.[0-9]+)|([0-9]+\\.) )([eE][-+]?[0-9]+)?)|([0-9]+([eE][-+]?[0-9]+)))[FfLl]?)'
- escape_sequence = '(\\\\(([a-wyzA-Z._~!=&\\^\\-\\\\?\'"]|x(?![0-9a-fA-F]))|(\\d+)(?!\\d)))'
- keyword = 'WHILE'
- keyword_map = {'bool': 'BOOL', 'broadcast': 'BROADCAST', 'chan': 'CHAN', 'char': 'CHAR', 'clock': 'CLOCK', 'const': 'CONST', 'do': 'DO', 'double': 'DOUBLE', 'else': 'ELSE', 'for': 'FOR', 'if': 'IF', 'int': 'INT', 'return': 'RETURN', 'string': 'STRING', 'struct': 'STRUCT', 'typedef': 'TYPEDEF', 'void': 'VOID', 'while': 'WHILE'}
- keywords = ('BOOL', 'BROADCAST', 'CLOCK', 'CHAN', 'CHAR', 'STRING', 'CONST', 'DO', 'DOUBLE', 'ELSE', 'FOR', 'IF', 'INT', 'RETURN', 'STRUCT', 'TYPEDEF', 'VOID', 'WHILE')
- string_literal = '"([^"\\\\\\n]|(\\\\[0-9a-zA-Z._~!=&\\^\\-\\\\?\'"]))*"'
- t_AND = '&'
- t_ANDEQUAL = '&='
- t_ARROW = '->'
- t_BAD_STRING_LITERAL(t)[source]
Matches invalid string literals that contain invalid escape codes and raises an error.
- t_COLON = ':'
- t_COMMA = ','
- t_DIVEQUAL = '/='
- t_DIVIDE = '/'
- t_EQ = '=='
- t_EQUALS = '='
- t_GE = '>='
- t_GT = '>'
- t_ID(t)[source]
Matches identifiers and checks if they are keywords or type identifiers. Updates the token type accordingly.
- t_LAND = '&&'
- t_LBRACE(t)[source]
Handles the opening brace “{” token. Triggers the on_lbrace_func to update the scope.
- t_LBRACKET = '\\['
- t_LE = '<='
- t_LNOT = '!'
- t_LOR = '\\|\\|'
- t_LPAREN = '\\('
- t_LSHIFT = '<<'
- t_LSHIFTEQUAL = '<<='
- t_LT = '<'
- t_MINUS = '-'
- t_MINUSEQUAL = '-='
- t_MOD = '%'
- t_MODEQUAL = '%='
- t_NE = '!='
- t_NOT = '~'
- t_OR = '\\|'
- t_OREQUAL = '\\|='
- t_PERIOD = '\\.'
- t_PLUS = '\\+'
- t_PLUSEQUAL = '\\+='
- t_RBRACE(t)[source]
Handles the closing brace “}” token. Triggers the on_rbrace_func to update the scope.
- t_RBRACKET = '\\]'
- t_RPAREN = '\\)'
- t_RSHIFT = '>>'
- t_RSHIFTEQUAL = '>>='
- t_SEMI = ';'
- t_STRING_LITERAL = '"([^"\\\\\\n]|(\\\\[0-9a-zA-Z._~!=&\\^\\-\\\\?\'"]))*"'
- t_TIMES = '\\*'
- t_TIMESEQUAL = '\\*='
- t_XOR = '\\^'
- t_XOREQUAL = '\\^='
- t_ignore = ' \t'
- tokens = ('BOOL', 'BROADCAST', 'CLOCK', 'CHAN', 'CHAR', 'STRING', 'CONST', 'DO', 'DOUBLE', 'ELSE', 'FOR', 'IF', 'INT', 'RETURN', 'STRUCT', 'TYPEDEF', 'VOID', 'WHILE', 'ID', 'TYPEID', 'INT_CONST_DEC', 'DOUBLE_CONST', 'CHAR_CONST', 'BOOL_CONST', 'STRING_LITERAL', 'PLUS', 'MINUS', 'TIMES', 'DIVIDE', 'MOD', 'OR', 'AND', 'NOT', 'XOR', 'LSHIFT', 'RSHIFT', 'LOR', 'LAND', 'LNOT', 'LT', 'LE', 'GT', 'GE', 'EQ', 'NE', 'EQUALS', 'TIMESEQUAL', 'DIVEQUAL', 'MODEQUAL', 'PLUSEQUAL', 'MINUSEQUAL', 'LSHIFTEQUAL', 'RSHIFTEQUAL', 'ANDEQUAL', 'XOREQUAL', 'OREQUAL', 'ARROW', 'LPAREN', 'RPAREN', 'LBRACKET', 'RBRACKET', 'LBRACE', 'RBRACE', 'COMMA', 'PERIOD', 'SEMI', 'COLON')
- unmatched_quote = '(\'([^\'\\\\\\n]|(\\\\(([a-wyzA-Z._~!=&\\^\\-\\\\?\'"]|x(?![0-9a-fA-F]))|(\\d+)(?!\\d))))*\\n)|(\'([^\'\\\\\\n]|(\\\\(([a-wyzA-Z._~!=&\\^\\-\\\\?\'"]|x(?![0-9a-fA-F]))|(\\d+)(?!\\d))))*$)'
uppaal2jetracer.parser.declarationparser.declaration_parser module
This module defines the DeclarationParser class for parsing UPPAAL declarations and generating an Abstract Syntax Tree (AST). It leverages the PLY (Python Lex-Yacc) framework to build a lexer and parser, enabling the parsing of complex declaration rules and structures.
Based on the c_parser.py from the pycparser project by Eli Bendersky (https://eli.thegreenplace.net) under the BSD license.
- Classes:
DeclarationParser: Main parser class responsible for processing UPPAAL declarations.
SingleStatementParser: Parser for single statements with relaxed rules on typing.
- Key Features:
Manages scope information with a stack-based system for accurate type and identifier resolution.
Supports lexer and parser customization, as well as optimization for performance.
Includes utility methods for handling specific parsing scenarios, such as typedef management.
Provides detailed debugging capabilities, such as generating lexer and parser tables and debug outputs.
- class DeclarationParser(lex_optimize=False, lexer=<class 'uppaal2jetracer.parser.declarationparser.declaration_lexer.DeclarationLexer'>, lextab='pycparser.lextab', yacc_optimize=False, yacctab='pycparser.yacctab', yacc_debug=False, taboutputdir='')[source]
Bases:
PLYParser
Parses UPPAAL declarations and generates an Abstract Syntax Tree (AST).
This class is responsible for parsing code fom UPPAAL declarations, handling lexer and parser configurations, and managing scope information during parsing. It uses the PLY (Python Lex-Yacc) parser framework. It provides mechanisms to configure and optimize the lexer and parser, as well as utility methods for scope management and type lookup.
The class maintains a stack-based scope system to resolve identifiers and types, supports typedef name management, and facilitates interaction with the lexer and parser.
- Variables:
dlex – The lexer used by the parser. Configured during the initialization phase.
tokens – List of tokens supported by the lexer for the parser.
_scope_stack – Maintains the stack of scopes for tracking symbols and types. Each scope is a dictionary of name-to-type mappings. A value of True indicates the name is a typedef; False means not a typedef.
_last_yielded_token – Stores the most recently seen token during parsing.
- dlex
- p_abstract_declarator_opt(p)
abstract_declarator_opt : empty | abstract_declarator
- p_argument_expression_list(p)[source]
argument_expression_list : assignment_expression | argument_expression_list COMMA assignment_expression
- p_assignment_expression(p)[source]
assignment_expression : conditional_expression | unary_expression assignment_operator assignment_expression
- p_assignment_expression_opt(p)
assignment_expression_opt : empty | assignment_expression
- p_assignment_operator(p)[source]
assignment_operator : EQUALS | XOREQUAL | TIMESEQUAL | DIVEQUAL | MODEQUAL | PLUSEQUAL | MINUSEQUAL | LSHIFTEQUAL | RSHIFTEQUAL | ANDEQUAL | OREQUAL
- p_binary_expression(p)[source]
binary_expression : unary_expression | binary_expression TIMES binary_expression | binary_expression DIVIDE binary_expression | binary_expression MOD binary_expression | binary_expression PLUS binary_expression | binary_expression MINUS binary_expression | binary_expression RSHIFT binary_expression | binary_expression LSHIFT binary_expression | binary_expression LT binary_expression | binary_expression LE binary_expression | binary_expression GE binary_expression | binary_expression GT binary_expression | binary_expression EQ binary_expression | binary_expression NE binary_expression | binary_expression AND binary_expression | binary_expression OR binary_expression | binary_expression XOR binary_expression | binary_expression LAND binary_expression | binary_expression LOR binary_expression
- p_block_item_list_opt(p)
block_item_list_opt : empty | block_item_list
- p_decl_body(p)[source]
decl_body : declaration_specifiers init_declarator_list_opt | declaration_specifiers_no_type id_init_declarator_list_opt
- p_declaration_list_opt(p)
declaration_list_opt : empty | declaration_list
- p_declaration_specifiers_1(p)[source]
declaration_specifiers : declaration_specifiers type_qualifier
- p_declaration_specifiers_4(p)[source]
declaration_specifiers : declaration_specifiers type_specifier_no_typeid
- p_declaration_specifiers_6(p)[source]
declaration_specifiers : declaration_specifiers_no_type type_specifier
- p_declaration_specifiers_no_type_1(p)[source]
declaration_specifiers_no_type : type_qualifier declaration_specifiers_no_type_opt
- p_declaration_specifiers_no_type_2(p)[source]
declaration_specifiers_no_type : TYPEDEF declaration_specifiers_no_type_opt
- p_declaration_specifiers_no_type_opt(p)
declaration_specifiers_no_type_opt : empty | declaration_specifiers_no_type
- p_designation_opt(p)
designation_opt : empty | designation
- p_direct_abstract_declarator_1(p)[source]
direct_abstract_declarator : LPAREN abstract_declarator RPAREN
- p_direct_abstract_declarator_2(p)[source]
direct_abstract_declarator : direct_abstract_declarator LBRACKET assignment_expression_opt RBRACKET
- p_direct_abstract_declarator_3(p)[source]
direct_abstract_declarator : LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET
- p_direct_abstract_declarator_6(p)[source]
direct_abstract_declarator : direct_abstract_declarator LPAREN parameter_type_list_opt RPAREN
- p_direct_abstract_declarator_7(p)[source]
direct_abstract_declarator : LPAREN parameter_type_list_opt RPAREN
- p_direct_id_declarator_1(p)
direct_id_declarator : ID
- p_direct_id_declarator_2(p)
direct_id_declarator : LPAREN id_declarator RPAREN
- p_direct_id_declarator_3(p)
direct_id_declarator : direct_id_declarator LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET
- p_direct_id_declarator_4(p)
direct_id_declarator : direct_id_declarator LBRACKET type_qualifier_list_opt assignment_expression RBRACKET | direct_id_declarator LBRACKET type_qualifier_list assignment_expression RBRACKET
- p_direct_id_declarator_5(p)
direct_id_declarator : direct_id_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET
- p_direct_id_declarator_6(p)
direct_id_declarator : direct_id_declarator LPAREN parameter_type_list RPAREN | direct_id_declarator LPAREN identifier_list_opt RPAREN
- p_direct_id_declarator_7(p)
direct_id_declarator : LBRACKET assignment_expression_opt COMMA assignment_expression_opt RBRACKET direct_id_declarator
- p_direct_typeid_declarator_1(p)
direct_typeid_declarator : TYPEID
- p_direct_typeid_declarator_2(p)
direct_typeid_declarator : LPAREN typeid_declarator RPAREN
- p_direct_typeid_declarator_3(p)
direct_typeid_declarator : direct_typeid_declarator LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET
- p_direct_typeid_declarator_4(p)
direct_typeid_declarator : direct_typeid_declarator LBRACKET type_qualifier_list_opt assignment_expression RBRACKET | direct_typeid_declarator LBRACKET type_qualifier_list assignment_expression RBRACKET
- p_direct_typeid_declarator_5(p)
direct_typeid_declarator : direct_typeid_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET
- p_direct_typeid_declarator_6(p)
direct_typeid_declarator : direct_typeid_declarator LPAREN parameter_type_list RPAREN | direct_typeid_declarator LPAREN identifier_list_opt RPAREN
- p_direct_typeid_declarator_7(p)
direct_typeid_declarator : LBRACKET assignment_expression_opt COMMA assignment_expression_opt RBRACKET direct_typeid_declarator
- p_direct_typeid_noparen_declarator_1(p)
direct_typeid_noparen_declarator : TYPEID
- p_direct_typeid_noparen_declarator_3(p)
direct_typeid_noparen_declarator : direct_typeid_noparen_declarator LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET
- p_direct_typeid_noparen_declarator_4(p)
direct_typeid_noparen_declarator : direct_typeid_noparen_declarator LBRACKET type_qualifier_list_opt assignment_expression RBRACKET | direct_typeid_noparen_declarator LBRACKET type_qualifier_list assignment_expression RBRACKET
- p_direct_typeid_noparen_declarator_5(p)
direct_typeid_noparen_declarator : direct_typeid_noparen_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET
- p_direct_typeid_noparen_declarator_6(p)
direct_typeid_noparen_declarator : direct_typeid_noparen_declarator LPAREN parameter_type_list RPAREN | direct_typeid_noparen_declarator LPAREN identifier_list_opt RPAREN
- p_direct_typeid_noparen_declarator_7(p)
direct_typeid_noparen_declarator : LBRACKET assignment_expression_opt COMMA assignment_expression_opt RBRACKET direct_typeid_noparen_declarator
- p_expression(p)[source]
expression : assignment_expression | expression COMMA assignment_expression
- p_expression_opt(p)
expression_opt : empty | expression
- p_function_definition(p)[source]
function_definition : declaration_specifiers id_declarator declaration_list_opt compound_statement
- p_id_declarator_1(p)
id_declarator : direct_id_declarator
- p_id_init_declarator(p)[source]
id_init_declarator : id_declarator | id_declarator EQUALS initializer
- p_id_init_declarator_list(p)[source]
id_init_declarator_list : id_init_declarator | id_init_declarator_list COMMA init_declarator
- p_id_init_declarator_list_opt(p)
id_init_declarator_list_opt : empty | id_init_declarator_list
- p_identifier_list_opt(p)
identifier_list_opt : empty | identifier_list
- p_init_declarator_list(p)[source]
init_declarator_list : init_declarator | init_declarator_list COMMA init_declarator
- p_init_declarator_list_opt(p)
init_declarator_list_opt : empty | init_declarator_list
- p_initializer_2(p)[source]
initializer : brace_open initializer_list_opt brace_close | brace_open initializer_list COMMA brace_close
- p_initializer_list(p)[source]
initializer_list : designation_opt initializer | initializer_list COMMA designation_opt initializer
- p_initializer_list_opt(p)
initializer_list_opt : empty | initializer_list
- p_iteration_statement_2(p)[source]
iteration_statement : DO statement WHILE LPAREN expression RPAREN SEMI
- p_iteration_statement_3(p)[source]
iteration_statement : FOR LPAREN expression_opt SEMI expression_opt SEMI expression_opt RPAREN statement
- p_iteration_statement_4(p)[source]
iteration_statement : FOR LPAREN declaration expression_opt SEMI expression_opt RPAREN statement
- p_parameter_declaration_1(p)[source]
parameter_declaration : declaration_specifiers id_declarator | declaration_specifiers typeid_noparen_declarator
- p_parameter_declaration_2(p)[source]
parameter_declaration : declaration_specifiers abstract_declarator_opt
- p_parameter_list(p)[source]
parameter_list : parameter_declaration | parameter_list COMMA parameter_declaration
- p_parameter_type_list_opt(p)
parameter_type_list_opt : empty | parameter_type_list
- p_parenthesized_compound_expression(p)[source]
assignment_expression : LPAREN compound_statement RPAREN
- p_postfix_expression_2(p)[source]
postfix_expression : postfix_expression LBRACKET expression RBRACKET
- p_postfix_expression_3(p)[source]
postfix_expression : postfix_expression LPAREN argument_expression_list RPAREN | postfix_expression LPAREN RPAREN
- p_postfix_expression_4(p)[source]
postfix_expression : postfix_expression PERIOD ID | postfix_expression PERIOD TYPEID | postfix_expression ARROW ID | postfix_expression ARROW TYPEID
- p_postfix_expression_6(p)[source]
postfix_expression : LPAREN type_name RPAREN brace_open initializer_list brace_close | LPAREN type_name RPAREN brace_open initializer_list COMMA brace_close
- p_selection_statement_2(p)[source]
selection_statement : IF LPAREN expression RPAREN statement ELSE statement
- p_specifier_qualifier_list_1(p)[source]
specifier_qualifier_list : specifier_qualifier_list type_specifier_no_typeid
- p_specifier_qualifier_list_2(p)[source]
specifier_qualifier_list : specifier_qualifier_list type_qualifier
- p_specifier_qualifier_list_4(p)[source]
specifier_qualifier_list : type_qualifier_list type_specifier
- p_statement(p)[source]
statement : expression_statement | compound_statement | selection_statement | iteration_statement | jump_statement
- p_struct_declaration_1(p)[source]
struct_declaration : specifier_qualifier_list struct_declarator_list_opt SEMI
- p_struct_declaration_list(p)[source]
struct_declaration_list : struct_declaration | struct_declaration_list struct_declaration
- p_struct_declarator_list(p)[source]
struct_declarator_list : struct_declarator | struct_declarator_list COMMA struct_declarator
- p_struct_declarator_list_opt(p)
struct_declarator_list_opt : empty | struct_declarator_list
- p_struct_specifier_2(p)[source]
struct_specifier : STRUCT brace_open struct_declaration_list brace_close | STRUCT brace_open brace_close
- p_struct_specifier_3(p)[source]
struct_specifier : STRUCT ID brace_open struct_declaration_list brace_close | STRUCT ID brace_open brace_close | STRUCT TYPEID brace_open struct_declaration_list brace_close | STRUCT TYPEID brace_open brace_close
- p_type_qualifier_list(p)[source]
type_qualifier_list : type_qualifier | type_qualifier_list type_qualifier
- p_type_qualifier_list_opt(p)
type_qualifier_list_opt : empty | type_qualifier_list
- p_type_specifier(p)[source]
type_specifier : typedef_name | struct_specifier | type_specifier_no_typeid
- p_type_specifier_no_typeid(p)[source]
type_specifier_no_typeid : VOID | BOOL | CHAN | CHAR | STRING | CLOCK | INT | DOUBLE
- p_typeid_declarator_1(p)
typeid_declarator : direct_typeid_declarator
- p_typeid_noparen_declarator_1(p)
typeid_noparen_declarator : direct_typeid_noparen_declarator
- p_unified_string_literal(p)[source]
unified_string_literal : STRING_LITERAL | unified_string_literal STRING_LITERAL
- parse(text, filename='', debug=False)[source]
Parses C code and returns an AST.
- text:
A string containing the C source code
- filename:
Name of the file being parsed (for meaningful error messages)
- debug:
Debug flag to YACC
- precedence = (('left', 'LOR'), ('left', 'LAND'), ('left', 'OR'), ('left', 'XOR'), ('left', 'AND'), ('left', 'EQ', 'NE'), ('left', 'GT', 'GE', 'LT', 'LE'), ('left', 'RSHIFT', 'LSHIFT'), ('left', 'PLUS', 'MINUS'), ('left', 'TIMES', 'DIVIDE', 'MOD'))
- class SingleStatementParser(*args, **kwargs)[source]
Bases:
DeclarationParser
SingleStatementParser class.
Parses single expressions or statements (without requiring a semicolon or declared variables). Supports simple assignments, function calls, and expressions.
Ensures the root node of the generated AST is always a FileAST.
- dlex
- p_abstract_declarator_opt(p)
abstract_declarator_opt : empty | abstract_declarator
- p_assignment_expression_opt(p)
assignment_expression_opt : empty | assignment_expression
- p_block_item_list_opt(p)
block_item_list_opt : empty | block_item_list
- p_declaration_list_opt(p)
declaration_list_opt : empty | declaration_list
- p_declaration_specifiers_no_type_opt(p)
declaration_specifiers_no_type_opt : empty | declaration_specifiers_no_type
- p_designation_opt(p)
designation_opt : empty | designation
- p_expression_opt(p)
expression_opt : empty | expression
- p_id_init_declarator_list_opt(p)
id_init_declarator_list_opt : empty | id_init_declarator_list
- p_identifier_list_opt(p)
identifier_list_opt : empty | identifier_list
- p_init_declarator_list_opt(p)
init_declarator_list_opt : empty | init_declarator_list
- p_initializer_list_opt(p)
initializer_list_opt : empty | initializer_list
- p_parameter_type_list_opt(p)
parameter_type_list_opt : empty | parameter_type_list
- p_struct_declarator_list_opt(p)
struct_declarator_list_opt : empty | struct_declarator_list
- p_type_qualifier_list_opt(p)
type_qualifier_list_opt : empty | type_qualifier_list
uppaal2jetracer.parser.declarationparser.plyparser module
This module contains the implementation of a PLY-based parser utility designed to aid in constructing and using parsers. It includes classes for representing coordinates of syntax elements (Coord), custom exception handling (ParseError), and a PLYParser class that provides helper methods for rule creation, error handling, and token coordinate computation.
Additionally, the module defines utilities for dynamic rule generation, including parameterized rule decorators (parameterized) and a class decorator (template) to facilitate the creation of PLY rules from templates.
Based on the plyparser.py from the pycparser module by Eli Bendersky (https://eli.thegreenplace.net) under the BSD license.
- Key Components:
Coord: Represents the file, line, and optionally column for syntax elements.
PLYParser: Provides methods to handle optional rules, error reporting, and coordinate management for tokens during parsing.
parameterized: Decorator for creating parameterized parsing rules.
template: Class decorator for generating rules from parameterized templates.
This module can be used as part of a larger system to build a parser using the PLY (Python Lex-Yacc) library.
- class Coord(file, line, column=None)[source]
Bases:
object
Coordinates of a syntactic element. Consists of: :ivar file: Name of the file. :type file: str :ivar line: The line number of the coordinate in the input string :type line: int :ivar column: The column number of the coordinate in the input string :type column: int
- column
- file
- line
- class PLYParser[source]
Bases:
object
Facilitates parsing tasks with helper methods and error handling specifically designed to work with the PLY parsing library. This class aids in managing parsing rules, tracking coordinates during parsing, and generating useful error messages for syntax issues.
- Variables:
dlex – Lexer instance providing input and tokens for parsing.
- dlex