parser: whitespaces ignorieren
authorBernhard Urban <lewurm@gmail.com>
Tue, 11 May 2010 11:41:48 +0000 (13:41 +0200)
committerBernhard Urban <lewurm@gmail.com>
Tue, 11 May 2010 11:41:48 +0000 (13:41 +0200)
src/parser.test
src/parser.vhd

index c1463740d519adeb3c906d514e7aaf8dba6341de..caee21e6a0688faaa6173d231967688b20a78ab7 100644 (file)
 # t15
 1000-4*100+5-300/2
 455
+# t16
+   10+  2
+12
+# t17
+9  +3
+12
+# t18
+   50          /     2      + 1   -3  
+23
+# t19
+50+1      
+51
index 22c733b1a972b1f11af484ac7aca0a94bb0ff14d..c622fc40082ad8e909837b30f88ad466e50aa751 100644 (file)
@@ -33,9 +33,10 @@ entity parser is
 end entity parser;
 
 architecture beh of parser is
-       type PARSER_STATE is (SIDLE, SREAD_NEWNUMBER, SREAD_NEXTBYTE,
-       SREAD_CALCNUMBER1, SREAD_CALCNUMBER2, SCALC_1, SCALC_14, SCALC_15, SCALC_2, SWRITE_CHAR1,
-       SWRITE_CHAR2, SDONE, SERROR1, SERROR2);
+       type PARSER_STATE is (SIDLE, SREAD_NEWNUMBER, SREAD_SPACE1_2,
+       SREAD_SPACE1_3, SREAD_SPACE2, SREAD_SPACE3, SREAD_OP1, SREAD_OP2,
+       SREAD_NEXTBYTE, SREAD_CALCNUMBER1, SREAD_CALCNUMBER2, SCALC_1, SCALC_14,
+       SCALC_15, SCALC_2, SWRITE_CHAR1, SWRITE_CHAR2, SDONE, SERROR1, SERROR2);
        signal state_int, state_next : PARSER_STATE;
        signal z_int, z_next, strich_int, strich_next, wtmp_int, wtmp_next : csigned;
        signal punkt_int, punkt_next : csigned;
@@ -50,6 +51,7 @@ architecture beh of parser is
        signal op1_int, op1_next : csigned;
        signal op2_int, op2_next : csigned;
        signal do_calc_int, do_calc_next : std_logic;
+       signal goto_calcn1, goto_op1, goto_space3 : std_logic;
 begin
        p_write <= p_write_int;
        p_rget <= p_rget_int;
@@ -108,7 +110,8 @@ begin
 
        -- next state
        process(state_int, do_it, p_rdone, p_wdone, p_read, aktop_int, strich_int,
-               punkt_int, calc_done, wtmp_int, opp_int)
+               punkt_int, calc_done, wtmp_int, opp_int, goto_calcn1, goto_op1,
+               goto_space3)
        begin
                state_next <= state_int;
 
@@ -118,21 +121,56 @@ begin
                                        state_next <= SREAD_NEWNUMBER;
                                end if;
                        when SREAD_NEWNUMBER =>
-                               state_next <= SREAD_NEXTBYTE;
+                               state_next <= SREAD_SPACE1_2;
+                       when SREAD_SPACE1_2 =>
+                               if p_rdone = '1' then
+                                       state_next <= SREAD_SPACE2;
+                               end if;
+                       when SREAD_SPACE1_3 =>
+                               if p_rdone = '1' then
+                                       state_next <= SREAD_SPACE3;
+                               end if;
+                       when SREAD_SPACE2 | SREAD_SPACE3 =>
+                               if p_rdone = '0' then
+                                       if goto_calcn1 = '0' then
+                                               case state_int is
+                                                       when SREAD_SPACE2 => state_next <= SREAD_SPACE1_2;
+                                                       when SREAD_SPACE3 => state_next <= SREAD_SPACE1_3;
+                                                       when others => assert(false) report "wtf @ state2";
+                                               end case;
+                                       end if;
+                               end if;
+                               if goto_calcn1 = '1' then
+                                       case state_int is
+                                               when SREAD_SPACE2 => state_next <= SREAD_NEXTBYTE;
+                                               when SREAD_SPACE3 => state_next <= SREAD_OP1;
+                                               when others => assert(false) report "wtf @ state1";
+                                       end case;
+                               end if;
                        when SREAD_NEXTBYTE =>
                                if p_rdone = '1' then
                                        state_next <= SREAD_CALCNUMBER1;
                                end if;
                        when SREAD_CALCNUMBER1 =>
-                               state_next <= SREAD_CALCNUMBER2;
-                       when SREAD_CALCNUMBER2 =>
+                               if goto_op1 = '1' then
+                                       state_next <= SREAD_OP1;
+                               elsif goto_space3 = '1' then
+                                       state_next <= SREAD_SPACE3;
+                               else
+                                       state_next <= SREAD_CALCNUMBER2;
+                               end if;
+                       when SREAD_OP1 =>
+                               state_next <= SREAD_OP2;
+                       when SREAD_OP2 =>
                                if p_rdone = '0' then
                                        if aktop_int /= ALU_NOP then
                                                state_next <= SCALC_1;
-                                       else
-                                               state_next <= SREAD_NEXTBYTE;
                                        end if;
                                end if;
+                       when SREAD_CALCNUMBER2 =>
+                               if p_rdone = '0' then
+                                       state_next <= SREAD_NEXTBYTE;
+                               end if;
                        when SCALC_1 =>
                                if calc_done = '1' then
                                        case opp_int is
@@ -250,6 +288,9 @@ begin
                op1_next <= op1_int;
                op2_next <= op2_int;
                do_calc_next <= '0';
+               goto_calcn1 <= '0';
+               goto_op1 <= '0';
+               goto_space3 <= '0';
 
                case state_int is
                        when SIDLE =>
@@ -261,9 +302,37 @@ begin
                                rbyte_next <= (others => '0');
                                p_write_next <= (others => '0');
                                aktop_next <= ALU_NOP;
-                       when SREAD_NEXTBYTE =>
+                       when SREAD_NEXTBYTE | SREAD_SPACE1_2 | SREAD_SPACE1_3 =>
                                p_rget_next <= '1';
+                       when SREAD_SPACE2 | SREAD_SPACE3 =>
+                               case p_read is
+                                       when x"20" =>
+                                               null;
+                                       when others =>
+                                               goto_calcn1 <= '1';
+                                               p_rget_next <= '1';
+                               end case;
+
                        when SREAD_CALCNUMBER1 =>
+                               case p_read is
+                                       -- '+', '-', '*', '/'
+                                       when x"2B" | x"2D" | x"2A" | x"2F" | x"00" =>
+                                               goto_op1 <= '1';
+                                               p_rget_next <= '1';
+
+                                       -- ' '
+                                       when x"20" =>
+                                               goto_space3 <= '1';
+                                               p_rget_next <= '1';
+
+                                       when others =>
+                                               -- TODO: check auf overflow
+                                               multmp := (z_int * 10) + hbyte2csigned(p_read);
+                                               z_next <= multmp((CBITS-1) downto 0);
+                               end case;
+                       when SREAD_CALCNUMBER2 | SREAD_OP2 =>
+                               null;
+                       when SREAD_OP1 =>
                                case p_read is
                                        -- '+'
                                        when x"2B" =>
@@ -283,13 +352,10 @@ begin
                                        when x"00" =>
                                                aktop_next <= ALU_DONE;
 
-                                       when others =>
-                                               -- TODO: check auf overflow
-                                               multmp := (z_int * 10) + hbyte2csigned(p_read);
-                                               z_next <= multmp((CBITS-1) downto 0);
+                                       -- TODO: err!
+                                       when others => assert(false) report "TODO: ...";
                                end case;
-                       when SREAD_CALCNUMBER2 =>
-                               null;
+
 
                        when SCALC_1 =>
                                case opp_int is