Skip to content
This repository has been archived by the owner on Nov 24, 2024. It is now read-only.

Commit

Permalink
fix a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
SaptakBhoumik committed Dec 22, 2021
1 parent b726ecd commit 3f4ada2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 33 deletions.
6 changes: 2 additions & 4 deletions Peregrine/ast/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,12 @@ AstKind VariableStatement::type() const { return KAstVariableStmt; }

std::string VariableStatement::stringify() const {
std::string res = "";

res += m_name->stringify();
if (m_type->type() != KAstNoLiteral) {
res+=":";
res += m_type->stringify();
res += " ";
}

res += m_name->stringify();

if (m_value->type() != KAstNoLiteral) {
res += " = ";
res += m_value->stringify();
Expand Down
11 changes: 7 additions & 4 deletions Peregrine/parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,9 @@ AstNodePtr Parser::parseExpression(PrecedenceType currPrecedence) {
Token m_prevToken;
if(m_tokIndex>0){
m_prevToken=m_tokens[m_tokIndex-1];
if (nextPrecedence()!=pr_lowest&&m_prevToken.tkType==tk_dot){
break;
}
}
advance();

Expand Down Expand Up @@ -763,11 +766,11 @@ AstNodePtr Parser::parseDotExpression(AstNodePtr left) {

// TODO: validate output of parseExpression
AstNodePtr referenced = parseExpression();
if(precedenceMap.count(m_currentToken.tkType) != 0){
if (precedenceMap[m_currentToken.tkType]>pr_lowest){
std::cout<<m_currentToken.keyword<<"\n";
if (nextPrecedence()>pr_lowest){
//To make something like eturn (self.a + self.b) valid
return parseBinaryOperation(std::make_shared<DotExpression>(tok, left, referenced));
}
advance();
return parseBinaryOperation(std::make_shared<DotExpression>(tok, left, referenced));
}
return std::make_shared<DotExpression>(tok, left, referenced);
}
Expand Down
15 changes: 0 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,6 @@ If you create any new file make sure to comment your name in the file as shown `

![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)

## Testing

The project has automatic tests which will run on pull requests and pushes to the project.
Tests which require user input won't run but the code will still be compiled.
If you add new functionality to the project please run the appropriate tests for it, and create tests for your functionality if possible.

#### It is recommended to only use input when absolutely necessary (example: you test the `input()` function)

This is the case because tests which require user input will only be compiled and can only be checked for syntax errors, and not issues with the functionality of the given test subject.

#### [`/Peregrine/tests/ci`](./Peregrine/tests/ci) - Tests which require no user input.

#### [`/Peregrine/tests/manual`](./Peregrine/tests/manual) - Tests which require user input and also include the tests you write for CI

![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)

# License

Expand Down
20 changes: 10 additions & 10 deletions can_comp.pe
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def divide(int num1,int num2)->int:
case _:
return num1/num2
def decorator(a func)->g:
int h=9
h:int =9
def value(int c):
h=8
printf("%d\n",h)
printf("Answer is %d\n",func(c))
return value
int ggggggg=9
ggggggg:int=9
@decorator
def dec_test(int x)->int:
ggggggg=7#mutability test
Expand Down Expand Up @@ -73,7 +73,7 @@ static inline def static_inline_func():
inline def inline_func():
printf("Hello from inline function\n")
def main():
colours enum_test=colours.RED
enum_test:colours=colours.RED
static_inline_func()
inline_func()
staticfunc()
Expand All @@ -90,17 +90,17 @@ def main():
Cppcode(#endif)
scope:
printf("Hello from new scope\n")
bool x=False
x:bool =False
const bool cc=False
x=True
bool y
y:bool
y=True
if x==y:
pass
printf("%d\n",test(0))
int a=0
int b=7
int c=7
a:int =0
b:int =7
c:int =7
match a,b,c:
case 5,7,8:
printf("a is 5,b is 7 and c is 8")
Expand All @@ -119,14 +119,14 @@ def main():
printf("\nHello\n")
lambda_test(func)
assert 8==8
name var1
var1:name
var1.item1=8
printf("item1 of var1 is %d\n",var1.item1)
var1.item2=6.8
printf("item2 of var1 is %f\n",var1.item2)
#should throw an error
#assert 8==6
int cast_test=9
cast_test:int =9
printf("Value is %f\n",cast<float>(cast_test))
printf("%d\n",divide(6,2))
#should terminate the program
Expand Down

0 comments on commit 3f4ada2

Please sign in to comment.