Skip to content

Commit 4f569cb

Browse files
author
robertDurst
committed
Some parsing errors fixed and new lexemes accepted
1 parent 34c81a6 commit 4f569cb

File tree

11 files changed

+284
-148
lines changed

11 files changed

+284
-148
lines changed

examples/test2.fish

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
import foo : "foo.fish"
2+
import bar : "bar.fish"
3+
4+
(fun some_function(int i)(void){
5+
i = i + 1
6+
return i
7+
})
8+
19
start {
2-
f.f = f.f + 10
10+
f.f = f...foo() + (5 * 11 ** (4 and 6))
11+
z = 7
12+
13+
Tree (
14+
(|1 == 2| {
15+
z = 2
16+
})
17+
18+
(|1 != 2 and (!true)| {
19+
z = new Foo { z: 1, f: "hello from the otherside" }
20+
--z
21+
})
22+
)
323
}

src/lexar/Lexar2.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,20 @@ Lexar2::getNextToken()
240240
break;
241241

242242
case State::SUBTRACTION:
243-
return c == '='
244-
? makeToken(TokenKind::SUBFROM, buffer)
245-
: makeTokenPutback(TokenKind::SUBTRACTION, buffer, c);
243+
if (c == '=')
244+
return makeToken(TokenKind::SUBFROM, buffer);
245+
else if (c == '-')
246+
return makeToken(TokenKind::UNARYMINUS, buffer);
247+
else
248+
return makeTokenPutback(TokenKind::SUBTRACTION, buffer, c);
246249

247250
case State::ADDITION:
248-
return c == '=' ? makeToken(TokenKind::ADDTO, buffer)
249-
: makeTokenPutback(TokenKind::ADDITION, buffer, c);
251+
if (c == '=')
252+
return makeToken(TokenKind::ADDTO, buffer);
253+
else if (c == '+')
254+
return makeToken(TokenKind::UNARYADD, buffer);
255+
else
256+
return makeTokenPutback(TokenKind::ADDITION, buffer, c);
250257

251258
case State::ASSIGNMENT:
252259
return c == '='

src/lexar/Token2.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ displayKind(const TokenKind& k)
7575
return "ASSIGNMENT";
7676
case TokenKind::NEGATION:
7777
return "NEGATION";
78+
case TokenKind::UNARYADD:
79+
return "UNARYADD";
80+
case TokenKind::UNARYMINUS:
81+
return "UNARYMINUS";
7882
case TokenKind::COMMENT:
7983
return "COMMENT";
8084
case TokenKind::UNDERSCORE:

src/lexar/Token2.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ enum class TokenKind
4848
EQUIVALENCE,
4949
NONEQUIVALENCE,
5050
ASSIGNMENT,
51+
52+
// unaries
5153
NEGATION,
54+
UNARYADD,
55+
UNARYMINUS,
5256

5357
// Structure
5458
COMMENT,

src/main/CommandLine.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "../lexar/Lexar2.h"
99
#include "../parser/Parser.h"
1010
#include "../parser/Parser2.h"
11-
#include "../parser/display.h"
1211
#include "../semantics/SemanticAnalyzer.h"
1312
#include "../transpiler/Transpiler.h"
1413
#include <iostream>

src/parser/Lexeme.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ disp(OP o)
111111
return "UDT dec";
112112
case OP::UDTDECITEM:
113113
return "UDT dec item";
114+
case OP::UNARYADD:
115+
return "Unary add";
116+
case OP::UNARYMINUS:
117+
return "Unary minus";
118+
case OP::ADDTO:
119+
return "Add to";
120+
case OP::SUBFROM:
121+
return "Sub from";
122+
case OP::DIVFROM:
123+
return "Div from";
124+
case OP::MULTTO:
125+
return "Mult to";
114126
default:
115127
return "Unknown";
116128
}

src/parser/Lexeme.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ enum class OP
6060
FUNCTION_CALL,
6161
UDTDEC,
6262
UDTDECITEM,
63+
UNARYADD,
64+
UNARYMINUS,
65+
ADDTO,
66+
SUBFROM,
67+
DIVFROM,
68+
MULTTO,
6369
};
6470
std::string disp(OP o);
6571

0 commit comments

Comments
 (0)