Ejemplo n.º 1
0
 def p_constant_1(self, p):
     """ constant    : INT_CONST_DEC
                     | INT_CONST_OCT
                     | INT_CONST_HEX
     """
     p[0] = c_ast.Constant(
         'int', p[1], self._coord(p.lineno(1)))
Ejemplo n.º 2
0
 def p_constant_2(self, p):
     """ constant : FLOAT_CONST """
     if p[1][-1] in ('f', 'F'):
         t = 'float'
     elif p[1][-1] in ('l', 'L'):
         t = 'long double'
     else:
         t = 'double'
     p[0] = c_ast.Constant(t, p[1], self._token_coord(p, 1))
Ejemplo n.º 3
0
 def p_constant_1(self, p):
     """ constant : INT_CONST """
     uCount = 0
     lCount = 0
     for x in p[1][-3:]:
         if x in ('l', 'L'):
             lCount += 1
         elif x in ('u', 'U'):
             uCount += 1
     if uCount > 1:
         raise ValueError('常量尾缀错误,含有多于1个u/U')
     elif lCount > 2:
         raise ValueError('常量尾缀错误,含有多余2个l/L')
     prefix = 'unsigned ' * uCount + 'long ' * lCount
     p[0] = c_ast.Constant(prefix + 'int', p[1], self._token_coord(p, 1))
Ejemplo n.º 4
0
 def p_string_literal(self, p):
     """ string_literal : STRING_LITERAL """
     p[0] = c_ast.Constant(
         'string', p[1].replace('\n', '\\n'), self._token_coord(p, 1))
Ejemplo n.º 5
0
 def p_constant_3(self, p):
     """ constant : CHAR_CONST """
     p[0] = c_ast.Constant('char', p[1], self._token_coord(p, 1))
Ejemplo n.º 6
0
 def p_constant_3(self, p):
     """ constant    : CHAR_CONST
                     | WCHAR_CONST
     """
     p[0] = c_ast.Constant(
         'char', p[1], self._coord(p.lineno(1)))
Ejemplo n.º 7
0
 def p_constant_2(self, p):
     """ constant    : FLOAT_CONST """
     p[0] = c_ast.Constant(
         'float', p[1], self._coord(p.lineno(1)))
Ejemplo n.º 8
0
 def p_primary_expression_3(self, p):
     """ primary_expression  : STRING_LITERAL
                             | WSTRING_LITERAL
     """
     p[0] = c_ast.Constant(
         'string', p[1], self._coord(p.lineno(1)))