Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Abgabe4Java
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dominic Daniel Krämer
Abgabe4Java
Commits
2aca6157
Commit
2aca6157
authored
2 years ago
by
Dominic Daniel Krämer
Browse files
Options
Downloads
Plain Diff
Merge branch 'dominicsbranch' into 'main'
Dominicsbranch See merge request
!6
parents
ed911771
fd8638be
No related branches found
No related tags found
1 merge request
!6
Dominicsbranch
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
expressions.txt
+3
-1
3 additions, 1 deletion
expressions.txt
src/Application.java
+19
-0
19 additions, 0 deletions
src/Application.java
src/Parser.java
+4
-4
4 additions, 4 deletions
src/Parser.java
with
26 additions
and
5 deletions
expressions.txt
+
3
−
1
View file @
2aca6157
1 + xy^2 - (31 * x)y
1 + xy^2 - (31 * x)y
\ No newline at end of file
1 + x^2 - (3 * x)
2x + 0,5x^2 - 1
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/Application.java
+
19
−
0
View file @
2aca6157
import
java.io.BufferedReader
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
public
class
Application
{
public
class
Application
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
BufferedReader
reader
;
String
datapath
=
"expressions.txt"
;
try
{
System
.
out
.
println
(
"Reading the file:"
);
reader
=
new
BufferedReader
(
new
FileReader
(
datapath
));
String
line
=
reader
.
readLine
();
while
(
line
!=
null
)
{
System
.
out
.
println
(
line
);
line
=
reader
.
readLine
();
}
System
.
out
.
println
();
reader
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
//List with a fitting String to be parsed into multiple tokens
//List with a fitting String to be parsed into multiple tokens
List
<
String
>
test
=
Arrays
.
asList
(
"1 + xy^2 - (31 * x)y"
);
List
<
String
>
test
=
Arrays
.
asList
(
"1 + xy^2 - (31 * x)y"
);
//Iterates through every String
//Iterates through every String
...
...
This diff is collapsed.
Click to expand it.
src/Parser.java
+
4
−
4
View file @
2aca6157
...
@@ -84,7 +84,7 @@ public class Parser {
...
@@ -84,7 +84,7 @@ public class Parser {
//parses a list of tokens into a value
//parses a list of tokens into a value
private
Optional
<
Expression
>
parseValue
(
List
<
Lexer
.
Token
>
ts
)
throws
ParserException
{
private
Optional
<
Expression
>
parseValue
(
List
<
Lexer
.
Token
>
ts
)
throws
ParserException
{
if
(
ts
.
isEmpty
())
{
if
(
ts
.
isEmpty
())
{
throw
new
ParserException
(
"
SyntaxError: expected a number
"
);
throw
new
ParserException
(
"
RuntimeException: empty token list
"
);
}
}
if
(
ts
.
get
(
0
).
getType
()
!=
Lexer
.
TokenType
.
NUMBER
)
{
if
(
ts
.
get
(
0
).
getType
()
!=
Lexer
.
TokenType
.
NUMBER
)
{
return
Optional
.
empty
();
return
Optional
.
empty
();
...
@@ -114,13 +114,13 @@ public class Parser {
...
@@ -114,13 +114,13 @@ public class Parser {
//parses a decimal of a list of tokens & a string
//parses a decimal of a list of tokens & a string
private
Expression
parseDecimal
(
List
<
Lexer
.
Token
>
ts
,
String
data
)
throws
ParserException
{
private
Expression
parseDecimal
(
List
<
Lexer
.
Token
>
ts
,
String
data
)
throws
ParserException
{
if
(
ts
.
size
()<
1
)
{
if
(
ts
.
size
()<
1
)
{
throw
new
ParserException
(
"
SyntaxError:
"
);
throw
new
ParserException
(
"
RuntimeException: empty token list
"
);
}
}
if
(
ts
.
get
(
0
).
getType
()
!=
Lexer
.
TokenType
.
SPECIAL
)
{
if
(
ts
.
get
(
0
).
getType
()
!=
Lexer
.
TokenType
.
SPECIAL
)
{
throw
new
ParserException
(
""
);
throw
new
ParserException
(
"
SyntaxException: expected a comma
"
);
}
}
if
(
ts
.
get
(
1
).
getType
()
!=
Lexer
.
TokenType
.
NUMBER
)
{
if
(
ts
.
get
(
1
).
getType
()
!=
Lexer
.
TokenType
.
NUMBER
)
{
throw
new
ParserException
(
""
);
throw
new
ParserException
(
"
SyntaxException: expected a number after a comma
"
);
}
}
Number
beforeDot
=
(
Number
)
parseNumber
(
data
);
Number
beforeDot
=
(
Number
)
parseNumber
(
data
);
ts
.
remove
(
0
);
ts
.
remove
(
0
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment