瀏覽代碼

* add support for exclusive start conditions

Reintegrate fpcres-rc branch by Martok

git-svn-id: trunk@46371 -
svenbarth 5 年之前
父節點
當前提交
f91a5cfe25
共有 3 個文件被更改,包括 10 次插入4 次删除
  1. 2 1
      utils/tply/lexdfa.pas
  2. 4 0
      utils/tply/lextable.pas
  3. 4 3
      utils/tply/plex.pas

+ 2 - 1
utils/tply/lexdfa.pas

@@ -53,7 +53,8 @@ procedure makeDFATable;
   begin
     (* initialize start states: *)
     for i := 2 to 2*n_start_states+1 do
-      setunion(first_pos_table^[i]^, first_pos_table^[i mod 2]^);
+      if not start_excl^[i div 2] then
+        setunion(first_pos_table^[i]^, first_pos_table^[i mod 2]^);
     for i := 0 to 2*n_start_states+1 do
       act_state := newState(first_pos_table^[i]);
     act_state := -1;

+ 4 - 0
utils/tply/lextable.pas

@@ -105,6 +105,8 @@ FirstPosTable  = array [0..2*max_start_states+1] of IntSetPtr;
                       default, states 2..2*n_start_states+1 user-defined
                       start states) *)
 
+StartStateExclusive = array[0..max_start_states] of Boolean;
+
 StateTableEntry = record
                     state_pos : IntSetPtr;
                       (* positions covered by state *)
@@ -137,6 +139,7 @@ optimize          : Boolean;          (* status of the optimization option *)
 sym_table         : ^SymTable;        (* symbol table *)
 pos_table         : ^PosTable;        (* position table *)
 first_pos_table   : ^FirstPosTable;   (* first positions table *)
+start_excl        : ^StartStateExclusive; (* user-defined start state type *)
 state_table       : ^StateTable;      (* DFA state table *)
 trans_table       : ^TransTable;      (* DFA transition table *)
 
@@ -460,6 +463,7 @@ begin
   new(sym_table);
   new(pos_table);
   new(first_pos_table);
+  new(start_excl);
   new(state_table);
   new(trans_table);
 

+ 4 - 3
utils/tply/plex.pas

@@ -88,7 +88,7 @@ procedure next_section;
 
 var n_rules : Integer; (* current number of rules *)
 
-procedure define_start_state ( symbol : String; pos : Integer );
+procedure define_start_state ( symbol : String; pos : Integer; excl : Boolean );
   (* process start state definition *)
   begin
 {$ifdef fpc}
@@ -106,6 +106,7 @@ procedure define_start_state ( symbol : String; pos : Integer );
           writeln(yyout, 'const ', symbol, ' = ', 2*start_state, ';');
           first_pos_table^[2*start_state] := newIntSet;
           first_pos_table^[2*start_state+1] := newIntSet;
+          start_excl^[start_state] := excl;
         end
       else
         error(symbol_already_defined, pos)
@@ -505,12 +506,12 @@ procedure definitions;
     begin
       split(line, 2);
       com := upper(itemv(1));
-      if (com='%S') or (com='%START') then
+      if (com='%S') or (com='%START') or (com='%X') then
         begin
           split(line, max_items);
           for i := 2 to itemc do
             if check_id(itemv(i)) then
-              define_start_state(itemv(i), itempos[i])
+              define_start_state(itemv(i), itempos[i], com='%X')
             else
               error(syntax_error, itempos[i]);
         end