Skip to content

Commit

Permalink
Fix bug in expression--> variable production
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian13579 committed Feb 27, 2021
1 parent b64d572 commit 5662575
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/lexing/lexing_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def t_aux_rcomment(t):
r'\*\)'
t.lexer.level -= 1
if t.lexer.level == 0:
t.value = t.lexer.lexdata[t.lexer.comm_start:t.lexer.lexpos+1]
t.value = t.lexer.lexdata[t.lexer.comm_start:t.lexer.lexpos]
t.type = "COMMENT"
t.lexer.lineno += t.value.count('\n')
t.lexer.begin('INITIAL')
Expand All @@ -131,7 +131,7 @@ def t_aux_pass(t):
# Rule so we can track line numbers


def t_ANY_newline(t):
def t_newline(t):
r'\n+'
t.lexer.lineno += len(t.value)
t.lexer.col = 1
Expand Down
11 changes: 7 additions & 4 deletions src/parsing/parsing_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
InstantiateNode, IntNode, IsVoidNode, LessNode,
LessOrEqualNode, LetNode, LoopNode, MethodCallNode, MethodDeclarationNode,
MinusNode, NotNode, PlusNode, ProgramNode, StarNode,
StringNode, VarDeclarationNode)
StringNode, VarDeclarationNode, VariableNode)


def p_program(p):
Expand All @@ -30,6 +30,9 @@ def p_class(p):
p[0] = ClassDeclarationNode(p[2], p[6], p[4])
elif len(p) == 6:
p[0] = ClassDeclarationNode(p[2], p[4])

p[0].set_position(p.slice[1].lineno, p.slice[1].col)



def p_feature_list(p):
Expand Down Expand Up @@ -238,7 +241,7 @@ def p_expression_string(p):

def p_expression_variable(p):
"""expression : ID"""
p[0] = InstantiateNode(p[1])
p[0] = VariableNode(p[1])


def p_expression_true(p):
Expand All @@ -261,8 +264,8 @@ def p_empty(p):
p[0] = []


def p_error(p):
print(f"Syntax error in input! {p} ")#line:{p.lineno} col:{p.col}")
def p_error(t):
print(f"Syntax error in input! {t} ")#line:{p.lineno} col:{p.col}")



Expand Down
2 changes: 1 addition & 1 deletion src/semantics/type_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, context: Context):
self.errors = []

@visitor.on('node')
def visit(self, node):
def visit(self, node):
pass

@visitor.when(ProgramNode)
Expand Down
2 changes: 1 addition & 1 deletion tests/parser_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import os
from utils import compare_errors
from .utils import compare_errors

tests_dir = __file__.rpartition('/')[0] + '/parser/'
tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')]
Expand Down
2 changes: 1 addition & 1 deletion tests/semantic_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import os
from utils import compare_errors, first_error_only_line
from .utils import compare_errors, first_error_only_line

tests_dir = __file__.rpartition('/')[0] + '/semantic/'
tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')]
Expand Down

0 comments on commit 5662575

Please sign in to comment.