Skip to content

Commit

Permalink
Fixed parser, problem was again in if statement, specifically in if_then
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanja-S committed Mar 16, 2023
1 parent 1ee98c4 commit a2f6921
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"request": "launch",
"mainClass": "Main",
"projectName": "PINS-compiler_7d951449",
"args": "PINS --exec SYN --dump SYN test3.pns"
"args": "PINS --exec SYN --dump SYN test4.pns"
}
]
}
15 changes: 14 additions & 1 deletion TestsRunner/tests/2-parser.tst
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,17 @@ expression_1 -> ε
definitions_1 -> ε
!end


!name: Function with while, for and if statement
!code:
fun prestejCrke (i:integer): integer = {
while (i < j[2]):
{
for i = 10, i < 100, i + 1:
{
if i == 69 then print(i)
}
}
}
!expected:
source -> definitions
definitions -> definition definitions_1
8 changes: 5 additions & 3 deletions src/compiler/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ private void parseAtomExpression(ListIterator<Symbol> lexicalSymbol) {
parseAtomExpressionLBrace(lexicalSymbol);
break;
default:
lexicalSymbol.previous();
break;
}
}
Expand All @@ -433,9 +434,9 @@ private void parseAtomExpressionLBrace(ListIterator<Symbol> lexicalSymbol) {
dump("if_else -> else expression");
lexicalSymbol.previous();
parseIfElse(lexicalSymbol);
} else
currentLexicalSym = lexicalSymbol.next();
} else
dump("if_else -> ε");
currentLexicalSym = lexicalSymbol.next();
if (currentLexicalSym.tokenType != TokenType.OP_RBRACE)
Report.error(currentLexicalSym.position, "The if statment should be closed with a right brace");
break;
Expand All @@ -447,7 +448,7 @@ private void parseAtomExpressionLBrace(ListIterator<Symbol> lexicalSymbol) {
Report.error(currentLexicalSym.position, "After while condition a colon should follow");
parseExpression(lexicalSymbol);
currentLexicalSym = lexicalSymbol.next();
if (currentLexicalSym.tokenType != TokenType.OP_LBRACE)
if (currentLexicalSym.tokenType != TokenType.OP_RBRACE)
Report.error(currentLexicalSym.position,
"After while body expression a right brace should close it");
break;
Expand Down Expand Up @@ -483,6 +484,7 @@ private void parseAtomExpressionLBrace(ListIterator<Symbol> lexicalSymbol) {
break;
default:
dump("atom_expression_lbrace_1 -> expression \'=\' expression \'}\'");
lexicalSymbol.previous();
parseExpression(lexicalSymbol);
currentLexicalSym = lexicalSymbol.next();
if (currentLexicalSym.tokenType != TokenType.OP_ASSIGN)
Expand Down
39 changes: 39 additions & 0 deletions test4.pns
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
typ prvic:string;
typ drugic : integer;
typ tretjic : besedilo;
typ cetrtic: arr[7] arr[7] logical;
var petic : arr [ 10 ] integer;

fun prvaFunkcija (prvic:string, drugic:integer, cetrtic:arr[7] logical) : integer =
5 + 3 - 2 == 10 & true | beseda / drugabeseda * 'danesjelepdanaaaaa' % cetrtic != petic + 5 - !e
- (-10) + (+(+(-10))) / (!cetrtic) + 100 - false | nekaj & nekaj == bla | nekaj >= blabla &
nekaj <= blablabla | nekaj + nekaj < bla & nekaj - nekaj > nekajbla { where
fun drugaFunkcija(nekaj:integer):integer=
{
{ if haha then {
if nekaj then 5+3-1-4+2 * true else {
while nekaj >= nekaj * (-5323223) + -44545 : {
for nekaj = 1, nekaj >= -9999999, nekajnekaj-1-1-1-1:nekaj
}
}
}
}
= celotenprogramtideluje69 { where
fun epicBubblesort(polje:arr[10]integer):void =
n == dolzinaPolja &
temp == 0 & {
for i=0,i<n,i + 1:
{ for j=0, j<(n-i),j + 1:
{
if polje[j-1] > polje[j] then
temp == polje[j-1] &
polje[j-1] == polje[j] &
polje[j] == temp &
blablabla #neki komentarji
}
}
}
}
}
}
#lololololol

0 comments on commit a2f6921

Please sign in to comment.