
##########################################
# Definitions
##########################################

#Vowels
define Vowel  a | e | i | o | u | E | A | %@ ;
define Vowel0  a | e | i | o | u ;

#Cons
define Cons  b | c | d | f | g | h | j | k | l | m | n | 8 | p | q | r | s | t | v | x | w | z | N | R ;

#Sibilants
define Sibilant z | s | x ;

#Nasals
define Nasal  l | m | n ;

#morpheme bound
define MM %++ ;

#morpheme bound or finnish
define MorfEnd [ MM | .#. ] ;

#suffix for auxiliary verbs
define SuffAuxV  E [ l a | l a k o | n ] MorfEnd ;

##########################################
# Rules
##########################################

#### T

#R1#
define T0 t -> 0 ||  _ (Sibilant) MM t ;
       # lot+tu:lotu (R1)
       # erakuts+te+a:erakustea (R1)

#R2#
define TD t -> d ||  Nasal MM _ u MorfEnd ;
       # sal+tu:saldu (R2)


#### bait prefix
#R3#
define BAIT1 d  -> 0 ||  .#. b a i t MM _ ;
       # bait+da:baita (R3)

#R4#
define BAIT2 g  -> k ||  .#. b a i t MM _ ;
       # bait+gara:bait+kara:baikara (R4,R5)

#R5#
define BAIT3 t -> 0 ||  .#. b a i _ MM [ Nasal | k ] ;
       # bait+naiz:bainaiz (R5)
       # bait+lezake:bailezake (R5)
       # bait+gara:bait+kara:baikara (R4,R5)

#R6#
define BAIT BAIT1 .o. BAIT2 .o. BAIT3 ;


#### first person in auxiliary verbs

#R7#
define TDA  t -> d a || _ MM SuffAuxV ; 
       # dut+Ela:duda+Ela:dudala (R7,R22)
       # dute+Ela:dutela (R21)


#### ber prefix
#R8#
define H0 h -> 0 || .#. b e R MM _ Vowel ;
       # beR+has+i:beR+as+i:berrasi (R8,R10)

#R9#
define EI e -> i || .#. b _ R MM Cons ;
       # beR+lot+tu:beR+lo+tu:biR+lo+tu (R1,R9,R11)
       # beR+erakuts+i:berrerakutsi (R10)

##### hard R
#R10#
define R2 R -> r r || _ MM (Q) Vowel ;
       # zakuR+a:zakurra (R10)
       # itziaR+Qen:itziarr+Qen:itziarren (R10,R12)

#R11#
define RR R -> r ;
       # ekaR+tzen:ekartzen (R11)


##### epenthetical r (Q)
#R12#
define Q0 Q -> 0 || Cons MM _ ;
       #ur+Qen:uren (R12)

#R13#
define QR Q -> r ;
       # amA+Qen:amA+ren:amaren (R13,R16)

##### final special  A

#R14#

define A0 A -> 0 || _ MM Vowel0 ;

       # amA+en:amen (R14)

#R15#

define ABI0 %@ -> 0 || _ MM E ;

       # d@+En:d+En:den (R15,R21)
       # d@+Elako:d+Elako:delako (R15,R21)

#R16#

define AA A -> a ;

       # amA:ama (R16)

#R17#

define AA2 %@ -> a ;

       # d@:da (R17)


##### k:g

#R18#

define KG k -> g || N MM _ o .#. ; 

       #egiN+ko:egiN+go:egingo (R18,R24)
       #sal+tu+ko:salduko (R2)

#R19, optional rule

define KG2 E k (->) g || Nasal 1 MM _ o ; 

       #usurbil1+Eko:usurbil1+go:usurbilgo (R19, R20)


##### Place names (1)

#R20#

define BAT0 1 -> 0 ;

       #usurbil1+Eko:usurbileko (R19,R20)
       #irun1+Eko:irun1+go:irungo  (R19, R20)
       #orio1+Eko (R20,R22)


##### epenthetical e

#R21#

define EE E -> e || [ Cons | E ] MM _ ;

       #zakuR+Eko:zakurr+Eko:zakurreko (R10,R21)
       #duE+Ela:duE+ela:duela (R21,R22)
       #ur+Etako:uretako (R21)
       #uR+Etako:urr+Etako:urretako (R10,R21)

#R22#

define E0 E -> 0 ;

       #ate+Etako:atetako (R22)


##### epenthetical n

#R23#

define N0 N -> 0 || _ MM t ;

       #egiN+te:egite (R23)

#R24#

define NN N -> n ;

       # egiN+ko:egiN+go:egingo (R18,R24)


##### morpheme bound

#R25#

define PLUS %+ -> 0 ;

       #This rule is aplicated in most of the examples above. Not marked.


##########################################
# Composition
##########################################

define RULES T0 .o. TD .o. BAIT .o. TDA .o. H0 .o. EI .o. R2 .o. RR .o. Q0 .o. QR .o. A0 .o. ABI0 .o. AA .o. AA2 .o. KG .o. KG2 .o. BAT0 .o.  EE .o. E0 .o. N0 .o. NN .o. PLUS ;


##########################################
# LEXICON
##########################################

read lexc lex_eu
define LEX


##########################################
# TEST
##########################################

define MORPHO LEX .o. RULES ;

regex MORPHO ;




