Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // -----------------------
- //
- // UNIVERSIDAD DE LOS ANDES
- //Juan Sebastian Prieto
- // -----------------------
- using gold.**
- var posCadena:int
- var longCadena:int
- procedure main(args:String[]) begin
- posCadena := 0
- longCadena := 0
- GAutomataFrame.show(createTransducer())
- testTransducer(createTransducer())
- end
- procedure testTransducer(M:ITransducer) begin
- var sc:java.util.Scanner(System.$in)
- while true do
- print "----------------------------"
- print "Digite la cadena de entrada:"
- string:=sc.nextLine()
- result:=M.acceptsString(string)
- print "La cadena fue "+(result?"aceptada":"rechazada")+". Resultado:"
- print M.getOutputString()
- end
- end
- function createTransducer():ITransducer begin
- //Definicion de un estado= ((longitudCadena%10)X(posCadena%3)X(Sigma_1))
- Q:={"inic", "error","v", "nombre", "variable", "n", "q", "q-", "<",
- "x", "y", "z", "f", "simbolo", "espacio", "a", "numero", "<-",
- "fa", "fai", "fail", "i", "is", "isV","isVa", "isVar", "isA",
- "isAt", "isAto", "isAtom", "isN", "isNu", "isNum", "isNum",
- "isNumb", "isNumbe", "isNumber"}
- Σ:=('a'‥'z')∪('A'‥'Z')∪('0'‥'9')∪{' ','.','(' ,')','[',']','?','-',',','!','<',':','|' }
- Σ´:=Σ
- q₀:="inic"
- F:=Q
- return GDeterministicTransducer(Q,Σ,Σ´,q₀,F,δ,g,h)
- end
- //Funcion de inicio de automata
- //(estado, símbolo leído.)
- function δ(q,σ) begin
- if q = "error" then
- return "error"
- elseif σ = 'i' && q!= "fa" then
- return "i"
- elseif (σ = 's' && q = "i") then
- return "is"
- elseif (σ = 'V' && q = "is") then
- return "isV"
- elseif (σ = 'a' && q = "isV") then
- return "isVa"
- elseif (σ = 'r' && q = "isVa") then
- return "isVar"
- elseif (σ = 'A' && q = "is") then
- return "isA"
- elseif (σ = 't' && q = "isA") then
- return "isAt"
- elseif (σ = 'o' && q = "isAt") then
- return "isAto"
- elseif (σ = 'm' && q = "isAto") then
- return "isAtom"
- elseif (σ = 'N' && q = "is") then
- return "isN"
- elseif (σ = 'u' && q = "isN") then
- return "isNu"
- elseif (σ = 'm' && q = "isNu") then
- return "isNum"
- elseif (σ = 'b' && q = "isNum") then
- return "isNumb"
- elseif (σ = 'e' && q = "isNumb") then
- return "isNumbe"
- elseif (σ = 'r' && q = "isNumbe") then
- return "isNumber"
- elseif σ = 'f' then
- return "f"
- elseif (σ = 'a' && q = "f") then
- return "fa"
- elseif (σ = 'i' && q = "fa") then
- return "fai"
- elseif (σ = 'l' && q = "fai") then
- return "fail"
- elseif (σ = '?') then
- return "q-"
- elseif (σ = '-' && q = "q-") then
- return "q"
- elseif (σ ∈('a'‥'z') && q ∉ {"nombre", "variable", "a", "v"} ) then
- return "nombre"
- elseif (σ ∈('a'‥'z')∪('A'‥'Z')∪('0'‥'9') && q = "nombre") then
- return "a"
- elseif (σ ∈('a'‥'z')∪('A'‥'Z')∪('0'‥'9') && q = "a") then
- return "a"
- elseif (σ ∈('A'‥'Z') && q != "variable") then
- return "variable"
- elseif (σ ∈('a'‥'z')∪('A'‥'Z')∪('0'‥'9') && q = "variable") then
- return "v"
- elseif (σ ∈('a'‥'z')∪('A'‥'Z')∪('0'‥'9') && q = "v") then
- return "v"
- elseif (σ =' ') then
- return "espacio"
- elseif (σ ∈ {'.','(',')','[',']',',','|','!'}) then
- return "simbolo"
- elseif q="numero" then
- return "numero"
- elseif (σ ∈ ('0'‥'9') && q!= "numero") then
- return "numero"
- elseif (σ = ':') then
- return "<-"
- elseif (σ = '-' && q="<-") then
- return "<"
- else
- return "error"
- end
- end
- function g(q) begin
- if q = "nombre" then
- return "a"
- elseif q="variable" then
- return "v"
- elseif (q="a") then
- return λ
- elseif (q="v") then
- return λ
- elseif q = "q" then
- return "q"
- elseif q="espacio" then
- return λ
- elseif q="numero" then
- return λ
- elseif q="<" then
- return "<"
- elseif q="isVar" then
- return "x"
- elseif q="isAtom" then
- return "y"
- elseif q="isNumber" then
- return "z"
- elseif q="fail" then
- return "f"
- else
- return λ
- end
- end
- function h(q,σ) begin
- if (σ ∈{'.','(',')','[',']',',','|','!'}) then
- return σ
- elseif (σ ∈ ('0'‥'9') && q != "numero") then
- return "n"
- else
- return λ
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement