Open main menu

Difference between revisions of "SCI/Specifications/SCI in action/Parser"

→‎Semantics: Fixed some pseudo code
(→‎Parser grammar example: fixed example formulas)
(→‎Semantics: Fixed some pseudo code)
Line 301: Line 301:
Where S is the set of possible semantic values, and V is the set of non-terminals as defined in the grammar. We will also use the sequence <i>&gamma;<sub>0</sub>,&gamma<sub>1</sub>,&gamma<sub>2</sub> &hellip; &gamma<sub>k-1</sub></i> which will represent the word groups the input tokens belonged to (in the exact order they were accepted), and the sequence <i>r<sub>0</sub>,r<sub>1</sub>,r<sub>2</sub> &hellip; r<sub>l-1</sub></i> , which will be the list of rules used to create the left derivation tree as described in the previous section.
Where S is the set of possible semantic values, and V is the set of non-terminals as defined in the grammar. We will also use the sequence <i>&gamma;<sub>0</sub>,&gamma<sub>1</sub>,&gamma<sub>2</sub> &hellip; &gamma<sub>k-1</sub></i> which will represent the word groups the input tokens belonged to (in the exact order they were accepted), and the sequence <i>r<sub>0</sub>,r<sub>1</sub>,r<sub>2</sub> &hellip; r<sub>l-1</sub></i> , which will be the list of rules used to create the left derivation tree as described in the previous section.


 
<pre>
<syntax type="?">
  Helper function sci_said_recursive: S &times; V &times; (V &cup; &Sigma;)* &rarr; NODE
              Helper function sci_said_recursive: S \times V \times (V \cup \Sigma)* \to \Node
  Parameters: s &isin; S, Rule r &isin; V &times; (V &cup; &Sigma;): v0 &rarr; v1 v2 ... vi
              Parameters: s \in S, Rule r \in V \times (V \cup \Sigma): v0 \to v1 v2 ... vi
  cnmr = cnr
              cnmr = cnr
  NODE n := s, v0
              \Node n := s, v0
  FOR j := 1 TO i
              FOR j := 1 TO i
    IF (vj &isin; &Sigma;) THEN
                        IF (vj \in \Sigma) THEN
      n := n, &gamma;cn&gamma;
                                n := n, \gammacn\gamma
      cn&gamma; := cn&gamma; + 1
                                cn\gamma := cn\gamma + 1
    ELSE
                        ELSE
      cnoldr := cnr
                                cnoldr := cnr
      cnr := cnr + 1
                                cnr := cnr + 1
      n := n, sci_said_recursive(&Sigma;rmr,j, rcnoldr)
                                n := n, sci_said_recursive(\sigmarmr,j, rcnoldr)
    FI
                        FI
  ROF
              ROF
  RETURN (n)
              RETURN (n)
 
 
  Helper function get_children: NODE &rarr; NODE*
 
          get_children((s, v, n0, n1 ... nm)) := n0, n1 ... nm
              Helper function get_children: \Node \to \Node*
 
                              get_children((s, v, n0, n1 ... nm)) := n0, n1 ... nm
 
 
  Algorithm SCI-SAID-TREE
 
  cn&gamma; := 0;
              Algorithm SCI-SAID-TREE
  cnr := 1;
              cn\gamma := 0;
  ntemp := ntemp, SCI-SAID-RECURSIVE(0, r0)
              cnr := 1;
  root(T&Pi;) := (141, 13f, get_children(ntemp))
              ntemp := ntemp, SCI-SAID-RECURSIVE(0, r0)
</pre>
              root(T\Pi) := (141, 13f, get_children(ntemp))
</syntax>


Here is an example, based on the previous one:
Here is an example, based on the previous one:
1,079

edits