Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BrainBreak
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Pavel Kirilin
BrainBreak
Commits
2d9cc0dd
Unverified
Commit
2d9cc0dd
authored
5 years ago
by
Pavel Kirilin
Browse files
Options
Downloads
Patches
Plain Diff
Fixed language parser.
Signed-off-by:
Pavel Kirilin
<
win10@list.ru
>
parent
bee08683
Loading
Loading
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/CodeGenerator.hs
+10
-0
10 additions, 0 deletions
src/CodeGenerator.hs
src/Definitions.hs
+1
-0
1 addition, 0 deletions
src/Definitions.hs
src/LangParser.hs
+39
-0
39 additions, 0 deletions
src/LangParser.hs
src/Lib.hs
+3
-2
3 additions, 2 deletions
src/Lib.hs
with
53 additions
and
2 deletions
src/CodeGenerator.hs
+
10
−
0
View file @
2d9cc0dd
module
CodeGenerator
where
import
Definitions
data
State
=
State
{
parsed
::
BrainBreakBlock
,
unparsed
::
BrainBreakBlock
,
mainFunction
::
String
}
This diff is collapsed.
Click to expand it.
src/Definitions.hs
+
1
−
0
View file @
2d9cc0dd
...
@@ -6,6 +6,7 @@ data BrainBreakOperation = Increment
...
@@ -6,6 +6,7 @@ data BrainBreakOperation = Increment
|
MoveLeft
|
MoveLeft
|
Read
|
Read
|
Write
|
Write
|
Comment
|
Loop
BrainBreakBlock
|
Loop
BrainBreakBlock
deriving
(
Eq
,
Show
)
deriving
(
Eq
,
Show
)
...
...
This diff is collapsed.
Click to expand it.
src/L
ex
er.hs
→
src/L
angPars
er.hs
+
39
−
0
View file @
2d9cc0dd
module
L
ex
er
where
module
L
angPars
er
where
import
Control.Applicative
import
Control.Applicative
import
Text.Trifecta
import
Text.Trifecta
import
Data.Maybe
(
catMaybes
)
import
Definitions
import
Definitions
import
Text.Parser.Combinators
import
Text.Parser.Combinators
import
Text.Parser.Token
import
Text.Parser.Token
import
Data.Functor
import
Data.Functor
filterComments
::
BrainBreakBlock
->
BrainBreakBlock
filterComments
(
Comment
:
ops
)
=
[]
++
filterComments
ops
filterComments
(
Loop
ops
:
otherCode
)
=
Loop
(
filterComments
ops
)
:
filterComments
otherCode
filterComments
(
op
:
ops
)
=
op
:
filterComments
ops
filterComments
[]
=
[]
parseComments
::
Parser
BrainBreakOperation
parseComments
=
satisfy
(
not
.
(`
elem
`
"<+>-[],."
))
$>
Comment
parseLoop
::
Parser
BrainBreakOperation
parseLoop
=
do
expr
<-
brackets
parseBrainBreak
pure
$
Loop
expr
parseBrainBreak
::
Parser
BrainBreakBlock
parseBrainBreak
::
Parser
BrainBreakBlock
parseBrainBreak
=
many
$
parseLeft
parseBrainBreak
=
many
$
parseLeft
<|>
parseRight
<|>
parseRight
...
@@ -14,13 +29,11 @@ parseBrainBreak = many $ parseLeft
...
@@ -14,13 +29,11 @@ parseBrainBreak = many $ parseLeft
<|>
parseRead
<|>
parseRead
<|>
parseWrite
<|>
parseWrite
<|>
parseLoop
<|>
parseLoop
<|>
parseComments
where
where
parseRead
=
comma
$>
Read
parseRead
=
comma
$>
Read
parseWrite
=
dot
$>
Write
parseWrite
=
dot
$>
Write
parseLeft
=
symbolic
'<'
$>
MoveLeft
parseLeft
=
symbolic
'<'
$>
MoveLeft
parseRight
=
symbolic
'>'
$>
MoveRight
parseRight
=
symbolic
'>'
$>
MoveRight
parseIncrement
=
symbolic
'+'
$>
Increment
parseIncrement
=
symbolic
'+'
$>
Increment
parseDecrement
=
symbolic
'-'
$>
Decrement
parseDecrement
=
symbolic
'-'
$>
Decrement
parseLoop
=
do
\ No newline at end of file
expr
<-
brackets
parseBrainBreak
pure
$
Loop
expr
This diff is collapsed.
Click to expand it.
src/Lib.hs
+
3
−
2
View file @
2d9cc0dd
module
Lib
where
module
Lib
where
import
Lexer
import
LangParser
import
Definitions
import
Text.Trifecta
import
Text.Trifecta
parseLine
::
String
->
IO
()
parseLine
::
String
->
IO
()
parseLine
line
=
case
parseString
parseBrainBreak
mempty
line
of
parseLine
line
=
case
parseString
parseBrainBreak
mempty
line
of
Success
code
->
print
$
show
code
Success
code
->
print
$
show
$
filterComments
code
Failure
info
->
print
$
_errDoc
info
Failure
info
->
print
$
_errDoc
info
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