cc: fix typo

This commit is contained in:
Paul Mathieu 2021-03-20 21:25:01 -07:00
parent f7b7118278
commit eb303641d9
2 changed files with 8 additions and 8 deletions

View File

@ -10,7 +10,7 @@ fun_decl: fun_prot ";"
fun_prot: type symbol "(" [fun_param ("," fun_param)*] ")"
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
@ -109,7 +109,7 @@ initializer_list: "{" [init_list_field ("," init_list_field)* ","? ] "}"
| "&" prec2_expr -> address_of
| "sizeof" prec2_expr -> sizeof
?prec1_expr: litteral
?prec1_expr: literal
| identifier
| "(" expression ")"
| prec1_expr "++" -> post_increment
@ -123,7 +123,7 @@ initializer_list: "{" [init_list_field ("," init_list_field)* ","? ] "}"
label: IDENTIFIER
litteral: SIGNED_NUMBER | ESCAPED_STRING | HEX_LITTERAL | CHARACTER
literal: SIGNED_NUMBER | ESCAPED_STRING | HEX_LITTERAL | CHARACTER
field: IDENTIFIER
identifier: IDENTIFIER
?symbol: IDENTIFIER

View File

@ -313,8 +313,8 @@ class CcTransform(lark.visitors.Transformer):
@lark.v_args(tree=True)
def _f(self, tree):
left, right = tree.children
if left.data == 'litteral' and right.data == 'litteral':
tree.data = 'litteral'
if left.data == 'literal' and right.data == 'literal':
tree.data = 'literal'
tree.children = [litt(left.children[0], right.children[0])]
return tree
return _f
@ -360,7 +360,7 @@ class CcTransform(lark.visitors.Transformer):
addop = lark.Tree('add', children)
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)
sub = _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)
return token
def litteral(self, tree):
def literal(self, tree):
imm = tree.children[0]
if isinstance(imm, str):
tok = self._make_string(imm)
@ -1064,7 +1064,7 @@ class CcInterp(lark.visitors.Interpreter):
strct = self.global_scope.structs[type.struct]
offs = strct.offset(ch_field)
if offs > 0:
load_offs = lark.Tree('litteral', [offs])
load_offs = lark.Tree('literal', [offs])
addop = lark.Tree('add', [tree.children[0], load_offs])
self.visit(addop)
addop.type = PointerType(pointed=strct.field_type(ch_field))