Advertisement
Guest User

Untitled

a guest
Jan 27th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.04 KB | None | 0 0
  1. type Grammar() =
  2.     let mutable productionRules = []
  3.     let mutable startSymbol  = 'A'
  4.  
  5.     member this.Grammar() =
  6.         this.addProductionRule("A")
  7.         this.addProductionRule("A->a")
  8.         this.addProductionRule("A->aA")
  9.  
  10.         //this.addProductionRule("A -> ")
  11.  
  12.     member this.addProductionRule(line : string) =
  13.         if (line.Contains("->") = false) then
  14.            startSymbol <- line.[0]
  15.         else
  16.             productionRules <- List.append  [(new ProductionRule(line.[0],line.Substring(3) + "$"))]  productionRules
  17.  
  18.     member this.getRulesForSymbol(symbol : char) =
  19.         let mutable rulesForSymbol = []
  20.         let s = productionRules.Length - 1
  21.         for i in 0..s do
  22.             let rule : ProductionRule = productionRules.[i]
  23.             if (rule.getLeftHandSide() = symbol) then
  24.                 rulesForSymbol <- List.append [rule] rulesForSymbol
  25.         rulesForSymbol
  26.  
  27.     member this.getStartSymbol = startSymbol
  28.     member this.isNonTerminal (symbol : char) = symbol >= 'A' && symbol <= 'Z'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement