]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/parser.y
release: 0.1.10
[lilypond.git] / lily / parser.y
index ebec63fbefe15feddea069cc597865d552392508..288d1407f1219f2c62ef0de670f282bf4111f31f 100644 (file)
 %{ // -*-Fundamental-*-
+
+/*
+  parser.y -- YACC parser for mudela
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+           Jan Nieuwenhuizen <jan@digicash.com>
+*/
+
 #include <iostream.h>
 
+// mmm
+#define MUDELA_VERSION "0.1.1"
+
+#include "script-def.hh"
+#include "symtable.hh"
 #include "lookup.hh"
 #include "misc.hh"
-#include "lexer.hh"
+#include "my-lily-lexer.hh"
 #include "paper-def.hh"
 #include "midi-def.hh"
-#include "input-score.hh"
 #include "main.hh"
 #include "keyword.hh"
 #include "debug.hh"
 #include "parseconstruct.hh"
 #include "dimen.hh"
 #include "identifier.hh"
-#include "commandrequest.hh"
-#include "musicalrequest.hh"
-#include "voice-element.hh"
+#include "command-request.hh"
+#include "musical-request.hh"
+#include "my-lily-parser.hh"
+#include "text-def.hh"
+#include "input-translator.hh"
+#include "score.hh"
+#include "music-list.hh"
+#include "header.hh"
+#include "duration-convert.hh"
 
 #ifndef NDEBUG
 #define YYDEBUG 1
 #endif
 
-Array<Request*> pre_reqs, post_reqs;
-Array<const char *> define_spots;
-Paper_def*default_paper();
-char const* defined_ch_c_l;
-char const* req_defined_ch_c_l;
-int fatal_error_i = 0;
+#define YYERROR_VERBOSE 1
+
+#define YYPARSE_PARAM my_lily_parser_l
+#define YYLEX_PARAM my_lily_parser_l
+#define THIS ((My_lily_parser *) my_lily_parser_l)
+
+#define yyerror THIS->parser_error
 
 %}
 
 
 %union {
-    Request * request;
-    Real real;
+    Array<Melodic_req*> *melreqvec;/* should clean up naming */
+    Array<String> * strvec;
+    Array<int> *intvec;
+    Box *box;
+    Chord * chord;
+    Duration *duration;
     Identifier *id;    
-   Voice *voice;    
-    Voice_element *el; 
+    Input_translator* itrans;
+    Music *music;
+    Music_list *musiclist;
+    Score *score;
+    Header *header;
+    Interval *interval;
+    Lookup*lookup;
+    Melodic_req * melreq;
+    Midi_def* midi;
+    Moment *moment;
+    Note_req *notereq;
+    Paper_def *paper;
+    Real real;
+    Request * request;
+    General_script_def * script;
     String *string;
+    Symbol * symbol;
+    Symtable * symtable;
+    Symtables * symtables;
+    Text_def * textdef;
+    Tempo_req *tempo;
+    char c;
     const char *consstr;
-    Paper_def *paper;
-    Midi_def* midi;
-    Input_music *music;
-    Music_general_chord *chord;
-    Music_voice *mvoice; 
     int i;
-    char c;
     int ii[10];
-       Moment *moment;
+}
+%{
 
-    Array<String> * strvec;
-    Array<int> *intvec;
-    Array<Melodic_req*> *melreqvec;
-    Input_staff *staff;    
-    Input_score *score;
-    Symtables * symtables;
-    Symtable * symtable;
-    Symbol * symbol;
-    Lookup*lookup;
-    Interval *interval;
-    Box *box;
-    Notename_tab *notename_tab;
-    Script_def * script;
-    Text_def * textdef;
+int 
+yylex(YYSTYPE *s,  void * v_l)
+{
+       My_lily_parser   *pars_l = (My_lily_parser*) v_l;
+       My_lily_lexer * lex_l = pars_l->lexer_p_;
+       
+       lex_l->lexval_l = (void*) s;
+       return lex_l->yylex();
 }
 
-%token VOICE STAFF SCORE TITLE  BAR  OUTPUT MULTIVOICE DYNAMIC
-%token CM_T IN_T PT_T MM_T PAPER WIDTH METER UNITSPACE SKIP COMMANDS COMMAND
-%token GEOMETRIC START_T DURATIONCOMMAND OCTAVECOMMAND
-%token KEY CLEF  TABLE  VOICES STEM
-%token PARTIAL MUSIC GROUPING CADENZA
-%token END SYMBOLTABLES TEXID TABLE NOTENAMES SCRIPT TEXTSTYLE PLET
-%token  GOTO
-%token MIDI TEMPO
-
-%token <id>  IDENTIFIER REAL_IDENTIFIER REQUEST_IDENTIFIER 
-%token <string> PITCHMOD DURATION RESTNAME
-%token <ii> NOTENAME 
-%token <real> REAL 
-%token <string> STRING
-
-%token <i> DOTS INT
-%type <real> unit
-%type <melreqvec> pitch_list 
-%type <c> open_request_parens close_request_parens close_plet_parens
-%type <id> declaration
-%type <string> declarable_identifier
-%type <paper> paper_block paper_body
-%type <midi> midi_block midi_body
-%type <real> dim real
-%type <ii>  default_duration explicit_duration notemode_duration mudela_duration
-%type <ii> notename
-%type <moment> duration_length
-%type <el> voice_elt full_element lyrics_elt command_elt
-
-%type <score> score_block score_body
-%type <staff> staff_block staff_init staff_body
-%type <i> int
-%type <intvec> intastint_list
-%type <request> post_request pre_request command_req 
-%type <string> pitchmod
-%type <music> music 
-%type <chord> music_chord music_chord_body
-
-%type <mvoice>  music_voice_body music_voice 
-
-%type <interval> dinterval
-%type <box> box
-%type <symtable> symtable symtable_body
-%type <lookup> symtables symtables_body
-%type <symbol> symboldef
-%type <notename_tab> notename_tab notename_tab_body
-%type <i> script_dir
-%type <script> script_definition script_body mudela_script
-%type <request> script_req textscript_req dynamic_req basic_request
-%type <textdef> mudela_text
 
+%}
+
+%pure_parser
+
+/* tokens which are not keywords */
+
+%token ALIAS
+%token BAR
+%token CADENZA
+%token CLEAR
+%token CLEF
+%token CONTAINS
+%token CONSISTS
+%token ACCEPTS
+%token CM_T
+%token DURATION
+%token ABSDYNAMIC
+%token END
+%token GROUPING
+%token GROUP
+%token REQUESTTRANSLATOR
+%token HSHIFT
+%token HEADER
+%token IN_T
+%token ID
+%token LYRIC
+%token KEY
+%token MELODIC
+%token MIDI
+%token MELODIC_REQUEST
+%token METER
+%token MM_T
+%token MULTI
+%token NOTENAMES
+%token OCTAVE
+%token OUTPUT
+%token PAPER
+%token PARTIAL
+%token PLET
+%token PT_T
+%token SCORE
+%token SCRIPT
+%token SKIP
+%token SPANDYNAMIC
+%token STAFF
+%token START_T
+%token STEM
+%token SYMBOLTABLES
+%token TABLE
+%token TRANSPOSE
+%token TEMPO
+%token TEXID
+%token TEXTSTYLE
+%token TITLE
+%token VERSION
+
+/* escaped */
+%token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
+
+%type <i>      dots
+%token <i>     INT
+%token <melreq>        NOTENAME_ID
+%token <id>    DURATION_IDENTIFIER
+%token <id>    IDENTIFIER
+%token <id>    MELODIC_REQUEST_IDENTIFIER 
+%token <id>    MUSIC_IDENTIFIER
+%token <id>    VOICE_IDENTIFIER
+%token <id>    POST_REQUEST_IDENTIFIER
+%token <id>    SCRIPT_IDENTIFIER
+%token <id>    COMMAND_IDENTIFIER
+%token <id>    REAL_IDENTIFIER
+%token <id>    INPUT_TRANS_IDENTIFIER
+%token <id>    INT_IDENTIFIER
+%token <id>    SCORE_IDENTIFIER
+%token <id>    MIDI_IDENTIFIER
+%token <id>    PAPER_IDENTIFIER
+%token <id>    REQUEST_IDENTIFIER
+%token <real>  REAL 
+%token <string>        DURATION RESTNAME
+%token <string>        STRING 
+%token <string> FIELDNAME RECORDLINE
+%token <i>     POST_QUOTES 
+%token <i>     PRE_QUOTES
+
+
+%type <header>         mudela_header mudela_header_body
+%type <box>    box
+%type <c>      open_request_parens close_request_parens
+%type <c>      open_plet_parens close_plet_parens
+%type <music>  simple_element music_elt full_element lyrics_elt command_elt
+%type <i>      int
+%type <i>      script_dir
+%type <id>     identifier_init
+%type <duration> explicit_steno_duration notemode_duration 
+%type <duration> entered_notemode_duration explicit_duration
+%type <interval>       dinterval
+%type <intvec> intastint_list
+%type <lookup> symtables symtables_body
+%type <melreq> melodic_request steno_melodic_req
+%type <notereq>        steno_note_req
+%type <melreqvec>      pitch_list 
+%type <midi>   midi_block midi_body
+%type <moment> duration_length
+
+%type <music>  Music transposed_music
+%type <musiclist> Voice Voice_body 
+%type <chord>  Chord Chord_body
+%type <paper>  paper_block paper_body
+%type <real>   dim real
+%type <real>   unit
+%type <request>        post_request pre_request command_req verbose_command_req 
+%type <request> abbrev_command_req
+%type <request>        script_req  dynamic_req 
+%type <score>  score_block score_body
+%type <script> script_definition script_body mudela_script gen_script_def
+%type <textdef> text_def
+%type <string> script_abbreviation
+%type <symbol> symboldef
+%type <symtable>       symtable symtable_body
+%type <itrans> input_translator_spec input_translator_spec_body
+%type <tempo>  tempo_request
+%type <string> header_record
+
+%left PRIORITY
 
 %%
 
 mudela:        /* empty */
+       | mudela mudela_header {
+               delete THIS->default_header_p_ ;
+               THIS->default_header_p_ = $2;
+       }
        | mudela score_block {
                add_score($2);          
        }
        | mudela add_declaration { }
-       | mudela mudela_command  {}
+       | mudela error
+       | mudela check_version { } 
+       | mudela add_notenames { }
        ;
 
-mudela_command:
-       notename_tab                    { lexer->set($1); }
+check_version:
+       VERSION STRING ';'              {
+               if ( String( *$2 ) != MUDELA_VERSION) {
+                       if (THIS->ignore_version_b_) {
+                               THIS->here_input().error("Incorrect mudela version");
+                       } else {
+                               THIS->fatal_error_i_ = 1;
+                               THIS->parser_error("Incorrect mudela version");
+                       }
+               }
+       }
        ;
 
-/*
-       DECLARATIONS
-*/
-add_declaration: declaration   {
-               lexer->add_identifier($1);
+add_notenames:
+       NOTENAMES '{' notenames_body '}'
+       ;
+notenames_body:
+       /**/    {
+       }
+       | notenames_body CLEAR  {
+               THIS->clear_notenames();
+       }
+       | notenames_body STRING '=' melodic_request {
+               THIS->add_notename(*$2, $4);
+               delete $2;
        }
        ;
 
-declarable_identifier:
-       STRING { $$ = $1; }
-       | IDENTIFIER { $$ = new String($1->name); }
+mudela_header_body:
+               {
+               $$ = new Header;
+       }
+       | mudela_header_body FIELDNAME header_record {
+               (*$$)[*$2] = *$3;
+               delete $2;
+               delete $3;
+       }
        ;
 
-declaration:
-       declarable_identifier '=' staff_block  {
-               $$ = new Staff_id(*$1, $3, IDENTIFIER);
-               delete $1; 
+mudela_header:
+       HEADER  {
+               THIS->lexer_p_->push_header_state();
        }
-       | declarable_identifier '=' music_voice {
-               $$ = new M_voice_id(*$1, $3, IDENTIFIER);
-               delete $1;
+       
+       '{' mudela_header_body '}'      {
+               $$ = $4;
+               THIS->lexer_p_->pop_state();
        }
-       | declarable_identifier '=' script_definition {
-               $$ = new Script_id(*$1, $3, IDENTIFIER);
-               delete $1;
+       ;
+
+
+header_record:
+               {
+               $$ = new String;
        }
-       | declarable_identifier '=' music_chord  {
-               $$ = new M_chord_id(*$1, $3, IDENTIFIER);
-               delete $1;
+       | header_record RECORDLINE      {
+               *$$ += *$2;
+               delete $2;
        }
-       | declarable_identifier '=' symtables {
-               $$ = new Lookup_id(*$1, $3, IDENTIFIER);
-               delete $1;
+       ;
+
+/*
+       DECLARATIONS
+*/
+
+add_declaration:
+       STRING {
+               THIS->remember_spot();
        }
-       | declarable_identifier '=' notename_tab {
-               $$ = new Notetab_id(*$1, $3, IDENTIFIER);
-               delete $1;
+       /* cont */ '=' identifier_init {
+           THIS->lexer_p_->set_identifier(*$1, $4);
+           $4->init_b_ = THIS->init_parse_b_;
+           $4->set_spot(THIS->pop_spot());
        }
-       | declarable_identifier '=' real        {
-               $$ = new Real_id(*$1, new Real($3), REAL_IDENTIFIER);
-               delete $1;
+       ;
+identifier_init:
+       score_block {
+               $$ = new Score_id($1, SCORE_IDENTIFIER);
+               
        }
-       | declarable_identifier error '}' {
-
+       | paper_block {
+               $$ = new Paper_def_id($1, PAPER_IDENTIFIER);
+               
        }
-       | declarable_identifier '=' basic_request {
-               $$ = new Request_id(*$1, $3, REQUEST_IDENTIFIER);
-               delete $1;
+       | midi_block {
+               $$ = new Midi_def_id($1, MIDI_IDENTIFIER);
+               
+       }
+       | script_definition {
+               $$ = new Script_id($1, SCRIPT_IDENTIFIER);
+               
+       }
+       | Music  {
+               $$ = new Music_id($1, MUSIC_IDENTIFIER);
+               
+       }
+       | symtables {
+               $$ = new Lookup_id($1, IDENTIFIER);
+               
+       }
+       | real  {
+               $$ = new Real_id(new Real($1), REAL_IDENTIFIER);
+               
+       }
+       | int   {
+               $$ = new Int_id(new int($1), INT_IDENTIFIER);
+               
+       }
+       | post_request {
+               $$ = new Request_id($1, POST_REQUEST_IDENTIFIER);
+               
+       }
+       | melodic_request {
+               $$ = new Request_id($1, MELODIC_REQUEST_IDENTIFIER);
+               
+       }
+       | input_translator_spec {
+               $$ = new Input_translator_id ( $1, INPUT_TRANS_IDENTIFIER);
+       }
+       | explicit_duration {
+               $$ = new Duration_id( $1, DURATION_IDENTIFIER);
        }
        ;
 
-notename_tab:
-       NOTENAMES '{' notename_tab_body '}'     { $$ = $3; }
+
+
+input_translator_spec:
+       REQUESTTRANSLATOR '{' input_translator_spec_body '}'
+               { $$ = $3; }
        ;
 
-notename_tab_body:                             {
-               $$ = new Notename_tab;
-       }
-       | IDENTIFIER                            {
-               $$ = $1->notename_tab(true);
+input_translator_spec_body:
+       INPUT_TRANS_IDENTIFIER  {
+               $$ = $1->input_translator();
+               $$-> set_spot( THIS->here_input() );
        }
-       | notename_tab_body STRING int int                      {
-               $$->set($3, $4, *$2);
+       | STRING STRING { 
+               $$ = new Input_translator; 
+               $$->base_str_ = *$1;
+               $$->type_str_ =*$2;
+               $$->set_spot ( THIS->here_input() );
+               delete $1;
                delete $2;
        }
+       | input_translator_spec_body ID STRING ';' {
+               $$-> default_id_str_ = *$3;
+               delete $3;
+       }
+       | input_translator_spec_body ALIAS STRING ';' {
+               $$-> alias_str_arr_.push(*$3);
+               delete $3;
+       }
+       | input_translator_spec_body CONSISTS STRING ';'        {
+               $$-> consists_str_arr_.push(*$3);
+               delete $3;
+       }
+       | input_translator_spec_body CONTAINS input_translator_spec {
+               $$->add($3);
+       }
        ;
 
 /*
        SCORE
 */
 score_block:
-       SCORE { define_spots.push(lexer->here_ch_c_l()); }
+       SCORE { THIS->remember_spot();
+               THIS->error_level_i_ =0;
+       }
        /*cont*/ '{' score_body '}'     {
                $$ = $4;
-               $$->defined_ch_c_l_ = define_spots.pop();
+               $$->set_spot(THIS->pop_spot());
                if (!$$->paper_p_ && ! $$->midi_p_)
-                       $$->paper_p_ = default_paper();
+                       $$->paper_p_ = THIS->default_paper();
 
                /* handle error levels. */
-               $$->errorlevel_i_ = lexer->errorlevel_i_;
-               lexer->errorlevel_i_ = 0;
+               $$->errorlevel_i_ = THIS->error_level_i_;
+               THIS->error_level_i_ = 0;
+               if (!$$->header_p_ && THIS->default_header_p_)
+                       $$->header_p_ = new Header(*THIS->default_header_p_);
        }
        ;
 
 score_body:            { 
-               $$ = new Input_score; 
+               $$ = new Score; 
+       }
+       | SCORE_IDENTIFIER {
+               $$ = $1->score();
+       }
+       | score_body mudela_header      {
+               $$->header_p_ = $2;
+       }
+       | score_body Music      {
+               $$->music_p_ = $2;
        }
-       | score_body staff_block        { $$->add($2); }
-       | score_body COMMANDS '{' music_voice_body '}'          {
-               $$->set($4);
+       | score_body paper_block                {
+               $$->paper_p_ = $2;      
+       }
+       | score_body midi_block         { 
+               $$->midi_p_ = $2;
        }
-       | score_body paper_block                { $$->set($2);  }
-       | score_body midi_block         { $$->set($2);  }
        | score_body error {
 
        }
@@ -242,21 +458,29 @@ intastint_list:
 */
 paper_block:
        PAPER
-
        '{' paper_body '}'      { $$ = $3; }
        ;
 
 paper_body:
        /* empty */                     {
-               $$ = default_paper();
+               $$ = THIS->default_paper(); // paper / video / engrave
        }
-       | paper_body WIDTH dim          { $$->linewidth = $3;}
-       | paper_body OUTPUT STRING      { $$->outfile = *$3;
+       | PAPER_IDENTIFIER      {
+               $$ = $1->paperdef();
+       }
+       | paper_body OUTPUT STRING ';'  { $$->outfile_str_ = *$3;
                delete $3;
        }
        | paper_body symtables          { $$->set($2); }
-       | paper_body UNITSPACE dim      { $$->whole_width = $3; }
-       | paper_body GEOMETRIC REAL     { $$->geometric_ = $3; }
+       | paper_body STRING '=' dim ';'         { 
+               $$->set_var(*$2, $4);
+       }
+       | paper_body STRING '=' real ';' {
+               $$->set_var(*$2, $4);
+       }
+       | paper_body input_translator_spec      {
+               $$->set( $2 );
+       }
        | paper_body error {
 
        }
@@ -271,300 +495,401 @@ midi_block:
        '{' midi_body '}'       { $$ = $3; }
        ;
 
-midi_body: 
-               $$ = new Midi_def; 
+midi_body: /* empty */                 {
+               $$ = THIS->default_midi();
        }
-       | midi_body OUTPUT STRING       { 
+       | midi_body OUTPUT STRING ';'   { 
                $$->outfile_str_ = *$3; 
                delete $3; 
        }
-       | midi_body TEMPO mudela_duration ':' int {
-               $$->set_tempo( wholes( $3[0], $3[1] ), $5 );
-       }
-       | midi_body error {
-
+       | midi_body tempo_request ';' {
+               $$->set_tempo( $2->dur_.length(), $2->metronome_i_ );
+               delete $2;
        }
-       ;
-
-/*
-       STAFFs
-*/
-staff_block:
-       STAFF   { define_spots.push(lexer->here_ch_c_l()); }
-/*cont*/       '{' staff_body '}'      {
-               $$ = $4; 
-               $$-> defined_ch_c_l_ = define_spots.pop();
+       | midi_body input_translator_spec       {
+               $$->set( $2 );
        }
-       ;
-
-
+       | midi_body error {
 
-staff_init:
-       IDENTIFIER              { $$ = $1->staff(true); }
-       | STRING                {
-               $$ = new Input_staff(*$1);
-               delete $1;
        }
        ;
 
-staff_body:
-       staff_init
-       | staff_body COMMANDS '{' music_voice_body '}'  {
-               $$->set_score_wide($4);
-       }
-       | staff_body music      {
-               $2->set_default_group( "staff_music" + String($$->music_.size()));
-               $$->add($2);
-       }
-       | staff_body error {
+tempo_request:
+       TEMPO entered_notemode_duration '=' int         {
+               $$ = new Tempo_req;
+               $$->dur_ = *$2;
+               delete $2;
+               $$-> metronome_i_ = $4;
        }
        ;
 
 /*
        MUSIC
 */
-music:
-       music_voice     { $$ = $1; }
-       | music_chord   { $$ = $1; }
-       ;
 
-music_voice:  MUSIC '{' music_voice_body '}'   { $$ = $3; }
+Voice:
+       '{' Voice_body '}'      {
+               $$ = $2;
+       }
        ;
 
-music_voice_body:
-       IDENTIFIER {
-               $$ = $1->mvoice(true);
-       }
-       | /* */         {
-               $$ = new Music_voice;
-       }
-       | music_voice_body '+' IDENTIFIER {
-               $$->concatenate($3->mvoice(true));
+Voice_body:
+       /**/            {
+               $$ = new Voice;
        }
-       | music_voice_body full_element {
-               $$->add_elt($2);
-       }
-       | music_voice_body voice_command {
+       | Voice_body ID STRING STRING ';'       {
+               $$ = new Voice;
+               $$->type_str_ = *$3;    
+               $$->id_str_ = *$4;
+               delete $3;
+               delete $4;
        }
-       | music_voice_body music        {
+       | Voice_body Music              {
                $$->add($2);
        }
-       | music_voice_body error {
-       }
        ;
 
-music_chord:  '{' music_chord_body '}' { $$ = $2; }
+Music:
+       full_element            { $$ = $1; }
+       | Voice         { $$ = $1; }
+       | Chord                 { $$ = $1; }
+       | transposed_music      { $$ = $1; }
+       | MUSIC_IDENTIFIER      { $$ = $1->music(); }
+       | MELODIC 
+               { THIS->lexer_p_->push_note_state(); } 
+       Music
+               { $$=$3; THIS->lexer_p_->pop_state(); }
+
+       | LYRIC 
+               { THIS->lexer_p_->push_lyric_state(); } 
+       Music
+               { $$ = $3; THIS->lexer_p_->pop_state(); }
+       ; 
+
+Chord:
+       '<' Chord_body '>'      { $$  = $2; }
        ;
 
-music_chord_body:
-       IDENTIFIER {
-               $$=$1->mchord(true);
-       }
-       | /* */ {
-               $$ = new Voice_group_chord;
+Chord_body:
+       /**/    {
+               $$ = new Chord;
+               $$-> multi_level_i_ = 1;
        }
-       | MULTIVOICE {
-               $$ = new Multi_voice_chord;
+       | Chord_body MULTI INT ';' {
+               $$->multi_level_i_=$3;
        }
-       | music_chord_body '+' IDENTIFIER {
-               $$->concatenate($3->mchord(true));
+       | Chord_body ID STRING STRING ';'       {
+               $$->type_str_ = *$3;    
+               $$->id_str_ = *$4;
+               delete $4; 
+               delete $3;
        }
-       | music_chord_body music {
+       | Chord_body Music {
                $$->add($2);
        }
-       | music_chord_body full_element {
-               $$ ->add_elt($2);
-       }
-       | music_chord_body error {
-       }
        ;
 
-basic_request:
-       command_req
-       | pre_request
-       | post_request
+transposed_music:
+       TRANSPOSE steno_melodic_req Music {
+               $$ = $3;
+               $$ -> transpose($2);
+               delete $2;
+       }
        ;
 
+
 /*
        VOICE ELEMENTS
 */
-full_element:  pre_requests voice_elt post_requests {
-               add_requests($2, pre_reqs);
-               add_requests($2, post_reqs);
-               $$ = $2;
-       }
-       | pre_requests lyrics_elt post_requests {
-               add_requests($2, pre_reqs);
-               add_requests($2, post_reqs);
+full_element:
+       pre_requests simple_element post_requests       {
+               THIS->add_requests((Chord*)$2);//ugh
                $$ = $2;
-        }
+       }
        | command_elt
+       | voice_command ';'     { $$ = 0; }
+       ;       
+
+simple_element:
+       music_elt 
+       | lyrics_elt
        ;
 
 command_elt:
-/* empty */    {
-               $$ = new Voice_element;
-               $$-> defined_ch_c_l_ = lexer->here_ch_c_l();
-       }
-/* cont: */
-       command_req     {
-               $2-> defined_ch_c_l_ = $$->defined_ch_c_l_;
-               $$->add($2);
+       command_req {
+               $$ = new Request_chord;
+               $$-> set_spot( THIS->here_input());
+               $1-> set_spot( THIS->here_input());
+               ((Chord*)$$) ->add($1);//ugh
 
        }
        ;
 
 command_req:
+       abbrev_command_req      
+       | verbose_command_req ';'       { $$ = $1; }
+       ;
+
+abbrev_command_req:
         '|'                            { 
                $$ = new Barcheck_req;
        }
-       | BAR STRING                    {
+       | COMMAND_IDENTIFIER    {
+               $$ = $1->request();
+       }
+       ;
+
+verbose_command_req:
+       BAR STRING                      {
                $$ = new Bar_req(*$2);
                delete $2;
        }
-       | METER '{' int '*' int '}'     {
+       | METER int '/' int     {
                Meter_change_req *m = new Meter_change_req;
-               m->set($3,$5);
+               m->set($2,$4);
+               // sorry hw, i need meter at output of track,
+               // but don-t know where to get it... statics should go.
+               // HW : default: 4/4, meterchange reqs may change it.
+               
+               Midi_def::num_i_s = $2;
+               Midi_def::den_i_s = $4;
                $$ = m;
        }
-       | SKIP '{' duration_length '}' {
+       | SKIP duration_length {
                Skip_req * skip_p = new Skip_req;
-               skip_p->duration_ = *$3;
-               delete $3;
+               skip_p->duration_.set_plet($2->numerator().as_long(), 
+                       $2->denominator().as_long());
+               
+               delete $2;
                $$ = skip_p;
        }
-       | CADENZA '{' int '}'   {
-               $$ = new Cadenza_req($3);
+       | tempo_request {
+               $$ = $1;
+       }
+       | CADENZA int   {
+               $$ = new Cadenza_req($2);
        }
-       | PARTIAL '{' duration_length '}'       {
-               $$ = new Partial_measure_req(*$3);
-               delete $3;
+       | PARTIAL duration_length       {
+               $$ = new Partial_measure_req(*$2);
+               delete $2;
+       }
+       | STEM int      {
+               $$ = get_stemdir_req($2);
        }
-       | STEM '{' int '}'              {
-               $$ = get_stemdir_req($3);
+       | HSHIFT int    {
+               $$ = get_hshift_req($2);
        }
        | CLEF STRING {
                $$ = new Clef_change_req(*$2);
                delete $2;
        }
-       | KEY '{' pitch_list '}'        {       
+       | KEY pitch_list        {       
                Key_change_req *key_p= new Key_change_req;
-               key_p->melodic_p_arr_ = *$3;
+               key_p->melodic_p_arr_ = *$2;
                $$ = key_p;
-               delete $3;
+               delete $2;
        }
-       | GROUPING '{' intastint_list '}' {
-               $$ = get_grouping_req(*$3); delete $3;
+       | GROUPING intastint_list {
+               $$ = get_grouping_req(*$2); delete $2;
        }
        ;
 
 post_requests:
        {
-               assert(post_reqs.empty());
+               assert(THIS->post_reqs.empty());
        }
        | post_requests post_request {
-               $2->defined_ch_c_l_ = lexer->here_ch_c_l();
-               post_reqs.push($2);
-       }
-       | post_requests close_plet_parens INT '/' INT { 
-               post_reqs.push( get_request($2) ); 
-               req_defined_ch_c_l = lexer->here_ch_c_l();
-               post_reqs.push( get_plet_request( $2, $3, $5 ) ); 
+               $2->set_spot( THIS->here_input());
+               THIS->post_reqs.push($2);
        }
        ;
 
+
 post_request:
-       close_request_parens    { 
-               $$ = get_request($1); 
+       POST_REQUEST_IDENTIFIER {
+               $$ = (Request*)$1->request();
+       }
+       |close_request_parens   { 
+               $$ = THIS->get_parens_request($1); 
        }
        | script_req
-       | textscript_req
        | dynamic_req
-       | REQUEST_IDENTIFIER    {
-               $$ = $1->request(false)->clone();
+       ;
+
+
+
+/*
+       URG!!
+*/
+steno_melodic_req:
+       NOTENAME_ID     {
+               $$ = $1->clone()->musical()->melodic();
+               $$->octave_i_ += THIS->default_octave_i_;
+       }
+       | steno_melodic_req POST_QUOTES         {  
+               $$-> octave_i_ += $2;
+       }
+       | PRE_QUOTES steno_melodic_req   {  
+               $$ = $2;
+               $2-> octave_i_ -= $1;
+       }
+       ;
+
+steno_note_req:
+       steno_melodic_req       {
+               $$ = new Note_req;
+               * (Melodic_req *) $$ = *$1;
+               delete $1;
+       }
+       | steno_note_req   '!'          {
+               $$->forceacc_b_ = ! $$->forceacc_b_;
+       } 
+       /* have to duration here. */
+       ;
+
+melodic_request:
+       MELODIC_REQUEST '{' int int int '}'     {/* ugh */
+               $$ = new Melodic_req;
+               $$->octave_i_ = $3;
+               $$->notename_i_ = $4;
+               $$->accidental_i_ = $5;
+       }
+       ;
+
+explicit_duration:
+       DURATION '{' int int '}'        {
+               $$ = new Duration;
+               $$-> durlog_i_ = $3;
+               $$-> dots_i_ = $4;
        }
        ;
 
 dynamic_req:
-       DYNAMIC '{' int '}'     {
+       ABSDYNAMIC '{' int '}'  {
                Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
-               ad_p ->loudness_ = $3;
+               ad_p ->loudness_ = (Dynamic_req::Loudness)$3;
                $$ =ad_p;
        }
+       | SPANDYNAMIC '{' int int '}' {
+               Span_dynamic_req * sp_p = new Span_dynamic_req;
+               sp_p->spantype = $4;
+               sp_p-> dynamic_dir_i_  = $3;
+               $$ = sp_p;
+       }
        ;
 
 close_plet_parens:
-       ']' {
-               req_defined_ch_c_l = lexer->here_ch_c_l();
+       ']' INT '/' INT {
                $$ = ']';
+               THIS->plet_.type_i_ = $4;
+               THIS->plet_.iso_i_ = $2;
        }
        ;
 
 close_request_parens:
-       '('     { 
+       '~'     {
+               $$ = '~';
+       }
+       | '('   { 
                $$='(';
        }
        | ']'   { 
                $$ = ']';
        }
+       | close_plet_parens {
+               $$ = ']';
+       }
+       | E_SMALLER {
+               $$ = '<';
+       }
+       | E_BIGGER {
+               $$ = '>';
+       }
+       ;
+
+open_plet_parens:
+       '[' INT '/' INT {
+               $$ = '[';
+               THIS->plet_.type_i_ = $4;
+               THIS->plet_.iso_i_ = $2;
+       }
        ;
-  
+
 open_request_parens:
-       ')'     { 
+       E_EXCLAMATION   {
+               $$ = '!';
+       }
+       | ')'   { 
                $$=')';
        }
        | '['   {
                $$='[';
        }
+       | open_plet_parens {
+       }
        ;
 
+
+
 script_definition:
        SCRIPT '{' script_body '}'      { $$ = $3; }
        ;
 
 script_body:
-       STRING int int int              {
-               $$ = new Script_def(*$1,$2, $3,$4);
+       STRING int int int int int              {
+               Script_def *s = new Script_def;
+               s->set_from_input(*$1,$2, $3,$4,$5, $6);
+               $$  = s;
                delete $1;
        }       
        ;
 
-textscript_req:
-       script_dir mudela_text          { $$ = get_text_req($1,$2); }
+script_req:
+       script_dir gen_script_def               { 
+               Musical_script_req *m = new Musical_script_req;
+               $$ = m; 
+               m-> scriptdef_p_ = $2;
+               m-> set_spot ( THIS->here_input() );
+               m-> dir_i_  = $1;
+       }
        ;
 
-mudela_text:
-       STRING                  { 
-               defined_ch_c_l = lexer->here_ch_c_l();
-               $$ = get_text(*$1); 
-               delete $1;
+gen_script_def:
+       text_def        { $$ = $1; }
+       | mudela_script { $$ = $1; 
+               $$-> set_spot( THIS->here_input() );
        }
        ;
 
-script_req:
-       script_dir mudela_script        { 
-               $$ = get_script_req($1, $2);
+text_def:
+       STRING { 
+               Text_def *t  = new Text_def;
+               $$ = t;
+               t->text_str_ = *$1; 
+               delete $1;
+               t->style_str_ = THIS->textstyle_str_;
+               $$->set_spot( THIS->here_input() );
        }
        ;
 
-mudela_script:
-       IDENTIFIER              { $$ = $1->script(true); }
-       | script_definition             { $$ = $1; }
-       | '^'           { $$ = get_scriptdef('^'); }
+script_abbreviation:
+       '^'             { $$ = get_scriptdef('^'); }
        | '+'           { $$ = get_scriptdef('+'); }
        | '-'           { $$ = get_scriptdef('-'); }
        | '|'           { $$ = get_scriptdef('|'); }
        | 'o'           { $$ = get_scriptdef('o'); }
        | '>'           { $$ = get_scriptdef('>'); }
-       | '.'           { $$ = get_scriptdef('.'); }
-       | DOTS          {
-               if ( $1 > 1 ) 
-                   warning( "too many staccato dots", lexer->here_ch_c_l() );
+       | '.'           {
                $$ = get_scriptdef('.');
        }
-       | error {
-               $$ = get_scriptdef('.');
-               yyerrok;
+       ;
+       
+mudela_script:
+       SCRIPT_IDENTIFIER               { $$ = $1->script(); }
+       | script_definition             { $$ = $1; }
+       | script_abbreviation           { 
+               $$ = THIS->lexer_p_->lookup_identifier(*$1)->script();
+               delete $1;
        }
        ;
 
@@ -576,124 +901,129 @@ script_dir:
 
 pre_requests:
        | pre_requests pre_request {
-               pre_reqs.push($2);
-               $2->defined_ch_c_l_ = lexer->here_ch_c_l();
+               THIS->pre_reqs.push($2);
+               $2->set_spot( THIS->here_input());
        }
        ;
 
 pre_request: 
        open_request_parens     { 
-               defined_ch_c_l = lexer->here_ch_c_l();
-               $$ = get_request($1); 
+               $$ = THIS->get_parens_request($1); 
        }
        ;
 
 voice_command:
-       PLET    '{' INT '/' INT '}'             {
-               set_plet($3,$5);
+       PLET     INT '/' INT {
+               THIS->default_duration_.set_plet($2,$4);
        }
-       | DURATIONCOMMAND '{' STRING '}'        {
-               set_duration_mode(*$3);
-               delete $3;
+       | DURATION STRING {
+               THIS->set_duration_mode(*$2);
+               delete $2;
        }
-       | DURATIONCOMMAND '{' notemode_duration '}'     {
-               set_default_duration($3);
+       | DURATION entered_notemode_duration {
+               THIS->set_default_duration($2);
+               delete $2;
        }
-       | OCTAVECOMMAND '{' pitchmod '}'        {
-               set_default_octave(*$3);
+       | OCTAVE { 
+               /*
+                       This is weird, but default_octave_i_
+                       is used in steno_note_req too
+
+                       c' -> default_octave_i_ == 1
+               */
+               /* why can't we have \oct{0} iso \oct{c'}*/
+               THIS->default_octave_i_ = 1; }
+/* cont */
+       steno_melodic_req {
+               THIS->default_octave_i_ = $3->octave_i_;
                delete $3;
        }
        | TEXTSTYLE STRING      {
-               set_text_style(*$2);
+               THIS->textstyle_str_ = *$2;
                delete $2;
        }
        ;
 
 duration_length:       
-       mudela_duration         {
-               $$ = new Moment(wholes($1[0], $1[1]));
+       {
+               $$ = new Moment(0,1);
        }
-       |int '*' mudela_duration        {
-               $$ = new Moment(Rational($1) * wholes($3[0], $3[1]));
+       | duration_length explicit_steno_duration               {       
+               *$$ += $2->length();
        }
        ;
 
-notemode_duration:
-       explicit_duration
-       | default_duration
-       ;
-
-mudela_duration:
-       int             {
-               $$[0] = $1;
-               $$[1] = 0;
-       }
-       | int DOTS      {
-               $$[0] = $1;
-               $$[1] = $2;
-       }
+dots:
+       '.'             { $$ = 1; }
+       | dots '.'      { $$ ++; }
        ;
 
-
-explicit_duration:
-       INT             {
-               last_duration($1);
-               $$[0] = $1;
-               $$[1] = 0;
+entered_notemode_duration:
+       /* */           { 
+               $$ = new Duration(THIS->default_duration_);
        }
-       | INT DOTS      {
-               last_duration($1);
-               $$[0] = $1;
-               $$[1] = $2;
+       | dots          {
+               $$ = new Duration(THIS->default_duration_);             
+               $$->dots_i_  = $1;
        }
-       | DOTS  {
-                get_default_duration($$);
-                $$[1] = $1;
-       }
-       | INT '*' INT '/' INT {
-               // ugh, must use Duration
-               set_plet( $3, $5 );
-               $$[ 0 ] = $1;
-               $$[ 1 ] = 0;
-               set_plet( 1, 1 );
+       | explicit_steno_duration       {
+               THIS->set_last_duration($1);
+               $$ = $1;
        }
        ;
 
-default_duration:
-       {
-               get_default_duration($$);
+notemode_duration:
+       entered_notemode_duration {
+               $$ = $1;
+               $$->plet_.type_i_ *= THIS->plet_.type_i_;
+               $$->plet_.iso_i_ *= THIS->plet_.iso_i_;
        }
        ;
 
-pitchmod:              { 
-               defined_ch_c_l = lexer->here_ch_c_l();
-               $$ = new String; 
+explicit_steno_duration:
+       int             {
+               $$ = new Duration;
+               if ( !Duration::duration_type_b($1) )
+                       THIS->parser_error("Not a duration");
+               else {
+                       $$->durlog_i_ = Duration_convert::i2_type($1);
+                    }
        }
-       | PITCHMOD      { 
-               defined_ch_c_l = lexer->here_ch_c_l();
-               $$ = $1;
+       | DURATION_IDENTIFIER   {
+               $$ = $1->duration();
+       }
+       | explicit_steno_duration '.'   {
+               $$->dots_i_ ++;
+       }
+       | explicit_steno_duration '*' int  {
+               $$->plet_.iso_i_ *= $3; 
+       }
+       | explicit_steno_duration '/' int {
+               $$->plet_.type_i_ *= $3; 
        }
        ;
 
-notename:
-       NOTENAME
-       ;
 
-voice_elt:
-       pitchmod notename notemode_duration                     {
-               $$ = get_note_element(*$1, $2, $3);
-               delete $1;
+music_elt:
+       steno_note_req notemode_duration                {
+               if (!THIS->lexer_p_->note_state_b())
+                       THIS->parser_error("have to be in Note mode for notes");
+               $1->set_duration (*$2);
+               $$ = THIS->get_note_element($1, $2);
        }
        | RESTNAME notemode_duration            {
-               $$ = get_rest_element(*$1, $2);
+               $$ = THIS->get_rest_element(*$1, $2);
                delete $1;
-
        }
        ;
 
 lyrics_elt:
-       mudela_text notemode_duration                   {
-               $$ = get_word_element($1, $2);
+       text_def notemode_duration                      {
+       /* this sux! text-def should be feature of lyric-engraver. */
+               if (!THIS->lexer_p_->lyric_state_b())
+                       THIS->parser_error("Have to be in Lyric mode for lyrics");
+               $$ = THIS->get_word_element($1, $2);
+
        };
 
 /*
@@ -702,31 +1032,31 @@ lyrics_elt:
 pitch_list:                    {
                $$ = new Array<Melodic_req*>;
        }
-       | pitch_list NOTENAME   {
-               Melodic_req *m_p = new Melodic_req;
-               m_p->notename_i_ = $2[0];
-               m_p->accidental_i_ = $2[1];
-               $$->push(m_p);
+       | pitch_list NOTENAME_ID        {
+               $$->push($2->clone()->musical()->melodic());
        }
        ;
 
 int:
-       real                    {
-               $$ = int($1);
-               if ( distance($1,Real(int($$)) ) > 1e-8)
-                       error( "integer expected", lexer->here_ch_c_l() );
+       INT                     {
+               $$ = $1;
+       }
+       | INT_IDENTIFIER        {
+               int *i_p = $1->intid();
+               $$ = *i_p;
+               delete i_p;
        }
        ;
 
+
 real:
-       INT                     {
-               $$ = Real($1);
-       }
-       | REAL          {
+       REAL            {
                $$ = $1;
        }
        | REAL_IDENTIFIER               {
-               $$ = * $1->real(0);             
+               Real *r_p = $1->real();
+               $$ = * r_p;
+               delete r_p;
        }
        ;
        
@@ -755,7 +1085,7 @@ symtables_body:
                $$ = new Lookup;
        }
        | IDENTIFIER            {
-               $$ = new Lookup(*$1->lookup(true));
+               $$ = $1->lookup();
        }
        | symtables_body TEXID STRING           {
                $$->texsetting = *$3;
@@ -787,7 +1117,7 @@ symboldef:
                delete $2;
        }
        | STRING {
-               Box b;
+               Box b(Interval(0,0), Interval(0,0));
                $$ = new Symbol(*$1, b);
                delete $1;
        }
@@ -808,48 +1138,30 @@ dinterval: dim   dim             {
 
 %%
 
-void
-yyerror(const char *s)
+void 
+My_lily_parser::set_yydebug(bool b )
 {
-       lexer->LexerError(s);
-
-       if ( fatal_error_i )
-               exit( fatal_error_i );
+#ifdef YYDEBUG
+       yydebug = b;
+#endif
 }
-
 void
-parse_file(String init, String s)
+My_lily_parser::do_yyparse()
 {
-   *mlog << "Parsing ... ";
-   lexer = new My_flex_lexer;
-
-#ifdef YYDEBUG
-   yydebug = !monitor->silence("InitParser") && check_debug;
-   lexer->set_debug( !monitor->silence("InitLexer") && check_debug);
-#endif
-
-   lexer->new_input(init);
-   yyparse();
-
-#ifdef YYDEBUG
-   yydebug = !monitor->silence("Parser") && check_debug;
-   lexer->set_debug( !monitor->silence("Lexer") && check_debug);
-#endif
-
-   lexer->new_input(s);
-   yyparse();
-   delete lexer;
-   lexer = 0;
-
-   if(!define_spots.empty())
-       warning("Braces don't match.",0);
+       yyparse((void*)this);
 }
 
 Paper_def*
-default_paper()
+My_lily_parser::default_paper()
 {
-    return new Paper_def(
-       lexer->lookup_identifier("default_table")->lookup(true));
+       Identifier *id = lexer_p_->lookup_identifier( "default_paper" );
+       return id ? id->paperdef() : new Paper_def ;
 }
 
+Midi_def*
+My_lily_parser::default_midi()
+{
+       Identifier *id = lexer_p_->lookup_identifier( "default_midi" );
+       return id ? id->mididef() : new Midi_def ;
+}