from common_lex import make_lexer (lexer, tokens) = make_lexer({ 'nt': 'NT', 'reg': 'REG', 'imm_const': 'IMMC'}) ##--------------------------------------------------------------------------------------------------------------------## start = 'content' # results are here extra_widths_reg = {} extra_widths_nt = {} extra_widths_imm_const = {} def p_content_nt(p): '''content : NT ID ID''' extra_widths_nt[p[2]] = p[3] def p_content_reg(p): '''content : REG ID ID''' extra_widths_reg[p[2]] = p[3] def p_content_immc(p): '''content : IMMC ID ID''' extra_widths_imm_const[p[2]] = p[3] def p_error(p): if p: print('extra-widths', p, p.lexer.lexdata)
from common_lex import make_lexer (lexer, tokens) = make_lexer() ##--------------------------------------------------------------------------------------------------------------------## start = 'content' pointer_names = [] def p_content(p): '''content : NUMBER ID ID''' pointer_names.append(tuple(p[1:])) def p_error(p): if p: print('pointer-names', p, p.lexer.lexdata) from ply.yacc import yacc parser = yacc(tabmodule='pointer_names_table') def parse(line): parser.parse(line, lexer=lexer)
from common_lex import make_lexer (lexer, tokens) = make_lexer(literals=':') ##--------------------------------------------------------------------------------------------------------------------## start = 'content' # result is here cpuid = {} def p_content(p): '''content : ID ":" args''' if p[1] in cpuid and cpuid[p[1]] != p[3]: print('WARNING: incoherent cpuid', p[3], cpuid[p[1]]) cpuid[p[1]] = p[3] def p_args_more(p): '''args : args ID''' p[0] = p[1] p[0].append(p[2]) def p_args_none(p): '''args : ''' p[0] = [] def p_error(p): if p: print('cpuid', p, p.lexer.lexdata)
# rewrite this file to parse a file rather than a line from common_lex import make_lexer (lexer, tokens) = make_lexer( { 'clear': 'CLEAR', 'define': 'DEFINE', 'remove-source': 'REMSRC', 'add-source': 'ADDSRC', 'remplace-source': 'REPLSRC', 'remove': 'REM', 'add': 'ADD' }, ':') ##--------------------------------------------------------------------------------------------------------------------## import os import re start = 'content' __path = '.' # result is here configs = {} path_expand = re.compile(r'%[(].+?[)]') def p_content_add(p): '''content : ADD ":" ID ":" ID ":" NUMBER | ADD ":" ID ":" ID | ID ":" ID ":" NUMBER
from common_lex import make_lexer (lexer, tokens) = make_lexer({ 'EI': 'EI', 'EO': 'EO', 'DI': 'DI', 'DO': 'DO', 'DS': 'DS', 'SCALAR': 'SCALAR', 'NOPRINT': 'NOPRINT', 'PRINT': 'PRINT', 'INTERNAL': 'INTERNAL', 'PUBLIC': 'PUBLIC', 'enum': 'ENUM', 'xed_reg_enum_t': 'XRET', 'xed_iclass_enum_t': 'XIET' }) ##--------------------------------------------------------------------------------------------------------------------## start = 'content' # result is here fields = {} def p_content(p): '''content : ID SCALAR type NUMBER ID xp ip dio eio''' fields[p[1]] = tuple(p[3:]) def p_type(p): '''type : ID