// Som grammar for LL(1) parser 11 Jan 2004
//   generate som code     27 Jan 2004

$ // parser Som-som generated from parse.txt 27 Jan 2004

$ // extern int lv, tok, tokvalue, nenum;

top -> tkTO fundef | ex #
fundef ->
  tkIDEN $'ypush tokvalue' args $'setfname' tkEQ ex $'dofun' #
args ->	
  @ tkIDEN $'enterLocal tokvalue' args |
  tkBAR $'ypush lv' local | 
  $'ypush lv' nil #
local -> @ tkIDEN $'enterLocal tokvalue' local | nil #

ex -> tkBB $'ypush MARK' exs tkBE $'doblock' | ex1 #
exs -> @ ex1 exs | nil #
ex1 ->
  tkIF ex0 ex exelse $'doif' |
  tkWHILE ex0 ex $'dowhile' |
  tkFOR tkIDEN $'ypush tokvalue' ex0 ex0 ex $'dofor' |
  tkCASE ex0 tkBB $'ypush MARK' caselist tkBE $'docase' |
  tkENUM tkBB elist tkBE $'ypush NIL' |
  tkBREAK $'ypush newatom OPER tkBREAK' |
  exas #

exelse -> tkELSE ex $'ypush MARK' | nil #
elist -> tkNUMBER $'nenum = tokvalue' elist2 | elist2 #
elist2 -> @ tkIDEN $'doenum' elist2 | nil #
caselist ->
  @ label tkCOLON ex caselist |
  tkELSE $'donum 0-1' tkCOLON ex |
  nil #

label -> 
  tkNUMBER $'donum tokvalue' |
  tkIDEN $'dolabel' #
ex0 -> term terms #
terms -> @ bop term $'dobop' terms | nil #
term [ a ] ->
  tkNUMBER $'donum tokvalue' |
  tkSTRING $'dostring' |
  tkIDEN $'a = tokvalue' $'doiden a' |
  tkNOT ex0 $'douop tkNOT' |
  tkARRAY ex0 $'douop tkARRAY' |
  tkSYSCALL tuple $'dosys' |
  tkLPAREN ex0 tkRPAREN #

// bug: doiden with wrong name because of lex
// correct: 21 Dec 2004
//  tkIDEN $'a = search tokvalue' $'doiden a' |

tuple ->
  tkBB tkNUMBER $'ypush MARK donum tokvalue' tuples tkBE #
tuples -> @ ex0 tuples | nil #

mod -> tkLBRACKET ex0 tkRBRACKET $'dovec' | nil #

bop ->
  tkPLUS $'ypush tok' | tkMINUS $'ypush tok' | 
  tkSTAR $'ypush tok' | tkSLASH $'ypush tok' |
  tkAND $'ypush tok'  | tkBAR $'ypush tok'   | 
  tkCARET $'ypush tok'| tkEQEQ $'ypush tok'  |
  tkNE $'ypush tok'   | tkLT $'ypush tok'    | 
  tkLE $'ypush tok'   | tkGE $'ypush tok'    |
  tkGT $'ypush tok'   | tkMOD $'ypush tok'   | 
  tkGTGT $'ypush tok' | tkLTLT $'ypush tok' #

END
