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

Commit

Permalink
Merge pull request #2 from MikaelFangel/setup-project
Browse files Browse the repository at this point in the history
Setup project
  • Loading branch information
cakarsubasi authored Jun 15, 2024
2 parents 3ea5623 + b848e9f commit 61ea361
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 10 deletions.
22 changes: 22 additions & 0 deletions CRN-Plus-Plus.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{EB2B5F05-AFDB-4255-8273-0158AA4053CF}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "crncc", "src\crncc\crncc.fsproj", "{75CE199E-EB55-4ACF-8471-80221F27E5D4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{91A3B1C7-4F31-4588-A095-92619F99C1CB}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "crncc_test", "test\crncc_test\crncc_test.fsproj", "{E1155307-1AB3-4536-AFFB-F889E9BF2451}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -11,4 +19,18 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{75CE199E-EB55-4ACF-8471-80221F27E5D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75CE199E-EB55-4ACF-8471-80221F27E5D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75CE199E-EB55-4ACF-8471-80221F27E5D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75CE199E-EB55-4ACF-8471-80221F27E5D4}.Release|Any CPU.Build.0 = Release|Any CPU
{E1155307-1AB3-4536-AFFB-F889E9BF2451}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E1155307-1AB3-4536-AFFB-F889E9BF2451}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1155307-1AB3-4536-AFFB-F889E9BF2451}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1155307-1AB3-4536-AFFB-F889E9BF2451}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{75CE199E-EB55-4ACF-8471-80221F27E5D4} = {EB2B5F05-AFDB-4255-8273-0158AA4053CF}
{E1155307-1AB3-4536-AFFB-F889E9BF2451} = {91A3B1C7-4F31-4588-A095-92619F99C1CB}
EndGlobalSection
EndGlobal
27 changes: 17 additions & 10 deletions Grammar.txt → notes/Grammar.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
<Crn〉 ::= 'crn = {'〈RootSList〉'}'
〈RootSList〉 ::= 〈RootS〉
| 〈RootS〉 ',' 〈RootSList〉
〈RootS〉 ::= 〈ConcS〉
| 〈StepS〉
〈ConcS〉 ::=
'conc ['〈species〉','〈number〉']'
Crn〉 ::= 'crn = {'〈RootSList〉'}'
〈RootSList〉 ::= 〈RootS〉| 〈RootS〉 ',' 〈RootSList〉

〈RootS〉 ::= 〈ConcS〉|〈StepS〉

〈ConcS〉 ::= 'conc ['〈species〉','〈number〉']'

〈StepS〉 ::= 'step ['CommandSList']'

〈CommandSList〉 ::= 〈CommandS〉
| 〈CommandS〉 ',' 〈CommandSList〉
〈CommandS〉 ::= 〈RxnS〉

〈CommandS〉 ::=
| 〈RxnS〉
| 〈ModuleS〉
| 〈ConditionalS〉
〈RxnS〉 ::= 'rxn['〈Expr〉','〈Expr〉','〈number〉']'
〈ModuleS〉 ::= 'ld ['〈species〉','〈species〉']'
〈ModuleS〉 ::=
| 'ld ['〈species〉','〈species〉']'
| 'add ['〈species〉','〈species〉','〈species〉']'
| 'sub ['〈species〉','〈species〉','〈species〉']'
| 'mul ['〈species〉','〈species〉','〈species〉']'
| 'div ['〈species〉','〈species〉','〈species〉']'
| 'sqrt ['〈species〉','〈species〉']'
| 'cmp ['〈species〉','〈species〉']'

〈ConditionalS〉 ::=
'ifGT ['〈CommandSList〉']'
| 'ifGT ['〈CommandSList〉']'
| 'ifGE ['〈CommandSList〉']'
| 'ifEQ ['〈CommandSList〉']'
| 'ifLT ['〈CommandSList〉']'
| 'ifLE ['〈CommandSList〉']'

〈Expr〉 ::= 〈species〉 { '+' 〈species〉 }
〈Expr〉 ::= 〈species〉('+' 〈species〉)+
〈number〉 ::= ([^0]([0-9])+)|0
〈species〉::= ([A-Za-z0-9])+
170 changes: 170 additions & 0 deletions scripts/AST.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#r "nuget:FParsec"

open FParsec

let test p str =
match run p str with
| Success(result, _, _) -> printfn "Success: %A" result
| Failure(errorMsg, _, _) -> printfn "Failure: %s" errorMsg

test pfloat "1.25"

type SpeciesS = string
type PNumberS = PNumber of float

type ConcS = Conc of SpeciesS * PNumberS

type ExprS = Expr of list<SpeciesS>

type ReactionS = Reaction of ExprS * ExprS * PNumberS

type ModuleS =
| Ld of SpeciesS * SpeciesS
| Add of SpeciesS * SpeciesS * SpeciesS
| Sub of SpeciesS * SpeciesS * SpeciesS
| Mul of SpeciesS * SpeciesS * SpeciesS
| Div of SpeciesS * SpeciesS * SpeciesS
| Sqrt of SpeciesS * SpeciesS
| Cmp of SpeciesS * SpeciesS

type ConditionS =
| Gt of CommandS list
| Ge of CommandS list
| Eq of CommandS list
| Lt of CommandS list
| Le of CommandS list

and CommandS =
| Reaction of ReactionS
| Module of ModuleS
| Condition of ConditionS

type StepS = Step of list<CommandS>

type RootS =
| Conc of ConcS
| Step of StepS

type CrnS = Crn of list<RootS>



let comment =
let anythingExceptNewline = isNoneOf [ '\n'; '\r' ]
skipString "//" >>. spaces >>. manySatisfy anythingExceptNewline

test comment "// hello world"

let ws = comment |>> ignore <|> spaces
let str_ws s = pstring s .>> ws

let float_ws = pfloat .>> ws

let identifier =
let isFirstChar c = isLetter c || c = '_'
let isChar c = isLetter c || isDigit c || c = '_'
many1Satisfy2L isFirstChar isChar "identifier" .>> ws

test identifier "_blahblah123 "

let pspecies = identifier .>> ws |>> SpeciesS
let pnumber = float_ws |>> PNumber

let pexpr = sepBy pspecies (str_ws "+") .>> ws |>> Expr

let start_bracket bcopen start =
str_ws start .>> str_ws bcopen

let end_bracket bcclose = str_ws bcclose

let comma = str_ws ","

let brackets2 popen pclose t1 t2 cons =
pipe2 (popen >>. t1) (comma >>. t2 .>> pclose) (fun v1 v2 -> cons (v1, v2))

let brackets3 popen pclose t1 t2 t3 cons =
pipe3 (popen >>. t1) (comma >>. t2) (comma >>. t3 .>> pclose) (fun v1 v2 v3 -> cons (v1, v2, v3))

let pconc =
brackets2 (start_bracket "[" "conc") (end_bracket "]") pspecies pnumber ConcS.Conc

let brackets3species name =
brackets3 (start_bracket "[" name) (end_bracket "]") pspecies pspecies pspecies

let brackets2species name =
brackets2 (start_bracket "[" name) (end_bracket "]") pspecies pspecies

let pmoduleld = brackets2species "ld" Ld
let pmoduleadd = brackets3species "add" Add
let pmodulesub = brackets3species "sub" Sub
let pmodulemul = brackets3species "mul" Mul
let pmodulediv = brackets3species "div" Div
let pmodulesqrt = brackets2species "sqrt" Sqrt
let pmodulecmp = brackets2species "cmp" Cmp

let pmodule =
choice
[ pmoduleld
pmoduleadd
pmodulesub
pmodulemul
pmodulediv
pmodulesqrt
pmodulecmp ]

let prxn =
brackets3 (start_bracket "[" "rxn") (end_bracket "]") pexpr pexpr pnumber ReactionS.Reaction

let listparser popen pclose listelem =
between popen pclose (sepBy listelem (str_ws ","))

let pcon, pconref = createParserForwardedToRef<'a, 'u> ()

let pcommand =
choice
[ pmodule |>> CommandS.Module
prxn |>> CommandS.Reaction
pcon |>> CommandS.Condition ]

let commandopen start =
str_ws start >>. str_ws "[" .>> str_ws "{"

let commandclose = str_ws "}" .>> str_ws "]"

let pcommandlist start =
listparser (commandopen start) commandclose pcommand

let pcmdif = pcommandlist "ifGT" |>> Gt
let pcmdge = pcommandlist "ifGE" |>> Ge
let pcmdeq = pcommandlist "ifEQ" |>> Eq
let pcmdlt = pcommandlist "ifLT" |>> Lt
let pcmdle = pcommandlist "ifLE" |>> Le

pconref.Value <- choice [ pcmdif; pcmdge; pcmdeq; pcmdlt; pcmdle ]

let pstep = pcommandlist "step" |>> StepS.Step

let proot = choice [ pstep |>> RootS.Step; pconc |>> RootS.Conc ]

let crnopen =
str_ws "crn" >>. str_ws "=" .>> str_ws "{"

let crnclose = str_ws "}"
let curlyparser = listparser crnopen crnclose
let pcrn = ws >>. curlyparser proot .>> eof |>> Crn

let example =
"crn = {
conc[c, 5.0], conc[cInitial, 4.0],
conc[one, 1], conc[zero, 0],
step[{
sub[c, one, cnext],
cmp[c, zero]
}],
step[{
ifGT[{ ld[cnext, c] }],
ifLE[{ ld[cInitial, c] }]
}]
}"

test pcrn example
2 changes: 2 additions & 0 deletions src/crncc/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// For more information see https://aka.ms/fsharp-console-apps
printfn "Hello from F#"
12 changes: 12 additions & 0 deletions src/crncc/crncc.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions test/crncc_test/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Program = let [<EntryPoint>] main _ = 0
8 changes: 8 additions & 0 deletions test/crncc_test/Tests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Tests

open System
open Xunit

[<Fact>]
let ``My test`` () =
Assert.True(true)
33 changes: 33 additions & 0 deletions test/crncc_test/crncc_test.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
<IsTestProject>true</IsTestProject>

<IsPublishable>false</IsPublishable>
</PropertyGroup>

<ItemGroup>
<Compile Include="Tests.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FsCheck" Version="2.16.*" />
<PackageReference Include="FsCheck.Xunit" Version="2.16.6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\crncc\crncc.fsproj" />
</ItemGroup>

</Project>

0 comments on commit 61ea361

Please sign in to comment.