Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Grammar() =
- let mutable productionRules = []
- let mutable startSymbol = 'A'
- member this.Grammar() =
- this.addProductionRule("A")
- this.addProductionRule("A->a")
- this.addProductionRule("A->aA")
- //this.addProductionRule("A -> ")
- member this.addProductionRule(line : string) =
- if (line.Contains("->") = false) then
- startSymbol <- line.[0]
- else
- productionRules <- List.append [(new ProductionRule(line.[0],line.Substring(3) + "$"))] productionRules
- member this.getRulesForSymbol(symbol : char) =
- let mutable rulesForSymbol = []
- let s = productionRules.Length - 1
- for i in 0..s do
- let rule : ProductionRule = productionRules.[i]
- if (rule.getLeftHandSide() = symbol) then
- rulesForSymbol <- List.append [rule] rulesForSymbol
- rulesForSymbol
- member this.getStartSymbol = startSymbol
- member this.isNonTerminal (symbol : char) = symbol >= 'A' && symbol <= 'Z'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement