cc: fix typo
This commit is contained in:
parent
f7b7118278
commit
eb303641d9
@ -10,7 +10,7 @@ fun_decl: fun_prot ";"
|
|||||||
fun_prot: type symbol "(" [fun_param ("," fun_param)*] ")"
|
fun_prot: type symbol "(" [fun_param ("," fun_param)*] ")"
|
||||||
fun_param: type [symbol]
|
fun_param: type [symbol]
|
||||||
|
|
||||||
global_var: type symbol sized_array* empty_array? [ "=" litteral ] ";"
|
global_var: type symbol sized_array* empty_array? [ "=" literal ] ";"
|
||||||
|
|
||||||
fun_def: fun_prot body
|
fun_def: fun_prot body
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ initializer_list: "{" [init_list_field ("," init_list_field)* ","? ] "}"
|
|||||||
| "&" prec2_expr -> address_of
|
| "&" prec2_expr -> address_of
|
||||||
| "sizeof" prec2_expr -> sizeof
|
| "sizeof" prec2_expr -> sizeof
|
||||||
|
|
||||||
?prec1_expr: litteral
|
?prec1_expr: literal
|
||||||
| identifier
|
| identifier
|
||||||
| "(" expression ")"
|
| "(" expression ")"
|
||||||
| prec1_expr "++" -> post_increment
|
| prec1_expr "++" -> post_increment
|
||||||
@ -123,7 +123,7 @@ initializer_list: "{" [init_list_field ("," init_list_field)* ","? ] "}"
|
|||||||
|
|
||||||
|
|
||||||
label: IDENTIFIER
|
label: IDENTIFIER
|
||||||
litteral: SIGNED_NUMBER | ESCAPED_STRING | HEX_LITTERAL | CHARACTER
|
literal: SIGNED_NUMBER | ESCAPED_STRING | HEX_LITTERAL | CHARACTER
|
||||||
field: IDENTIFIER
|
field: IDENTIFIER
|
||||||
identifier: IDENTIFIER
|
identifier: IDENTIFIER
|
||||||
?symbol: IDENTIFIER
|
?symbol: IDENTIFIER
|
||||||
|
10
tools/cc.py
10
tools/cc.py
@ -313,8 +313,8 @@ class CcTransform(lark.visitors.Transformer):
|
|||||||
@lark.v_args(tree=True)
|
@lark.v_args(tree=True)
|
||||||
def _f(self, tree):
|
def _f(self, tree):
|
||||||
left, right = tree.children
|
left, right = tree.children
|
||||||
if left.data == 'litteral' and right.data == 'litteral':
|
if left.data == 'literal' and right.data == 'literal':
|
||||||
tree.data = 'litteral'
|
tree.data = 'literal'
|
||||||
tree.children = [litt(left.children[0], right.children[0])]
|
tree.children = [litt(left.children[0], right.children[0])]
|
||||||
return tree
|
return tree
|
||||||
return _f
|
return _f
|
||||||
@ -360,7 +360,7 @@ class CcTransform(lark.visitors.Transformer):
|
|||||||
addop = lark.Tree('add', children)
|
addop = lark.Tree('add', children)
|
||||||
return lark.Tree('dereference', [addop])
|
return lark.Tree('dereference', [addop])
|
||||||
|
|
||||||
# operations on litterals can be done by the compiler
|
# operations on literals can be done by the compiler
|
||||||
add = _binary_op(lambda a, b: a+b)
|
add = _binary_op(lambda a, b: a+b)
|
||||||
sub = _binary_op(lambda a, b: a-b)
|
sub = _binary_op(lambda a, b: a-b)
|
||||||
mul = _binary_op(lambda a, b: a*b)
|
mul = _binary_op(lambda a, b: a*b)
|
||||||
@ -862,7 +862,7 @@ class CcInterp(lark.visitors.Interpreter):
|
|||||||
self.global_scope.symbols[token] = Variable(litt_type(s), token)
|
self.global_scope.symbols[token] = Variable(litt_type(s), token)
|
||||||
return token
|
return token
|
||||||
|
|
||||||
def litteral(self, tree):
|
def literal(self, tree):
|
||||||
imm = tree.children[0]
|
imm = tree.children[0]
|
||||||
if isinstance(imm, str):
|
if isinstance(imm, str):
|
||||||
tok = self._make_string(imm)
|
tok = self._make_string(imm)
|
||||||
@ -1064,7 +1064,7 @@ class CcInterp(lark.visitors.Interpreter):
|
|||||||
strct = self.global_scope.structs[type.struct]
|
strct = self.global_scope.structs[type.struct]
|
||||||
offs = strct.offset(ch_field)
|
offs = strct.offset(ch_field)
|
||||||
if offs > 0:
|
if offs > 0:
|
||||||
load_offs = lark.Tree('litteral', [offs])
|
load_offs = lark.Tree('literal', [offs])
|
||||||
addop = lark.Tree('add', [tree.children[0], load_offs])
|
addop = lark.Tree('add', [tree.children[0], load_offs])
|
||||||
self.visit(addop)
|
self.visit(addop)
|
||||||
addop.type = PointerType(pointed=strct.field_type(ch_field))
|
addop.type = PointerType(pointed=strct.field_type(ch_field))
|
||||||
|
Loading…
Reference in New Issue
Block a user