/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk

« back to all changes in this revision

Viewing changes to src/libvqdr/parser.vala

  • Committer: Gustav Hartvigsson
  • Date: 2022-05-26 16:14:23 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20220526161423-qsrrng3x3ykyp1ie
* woopes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
    INVALID_DATA;
7
7
  }
8
8
 
 
9
  enum CharType {
 
10
    NULL = 0,
 
11
    DIGIT,
 
12
    UOP,
 
13
    OP,
 
14
    ALPHA,
 
15
    DOT,
 
16
    POP,
 
17
    PCL,
 
18
    COM,
 
19
    UNKNOWN;
 
20
   
 
21
   
 
22
  /**
 
23
   * Determine character type.
 
24
   * @param ch Character to be checked.
 
25
   * @return The character type.
 
26
   */
 
27
    CharType from_char (char ch) {
 
28
      switch (ch) {
 
29
        case '0': case '1':
 
30
        case '2': case '3':
 
31
        case '4': case '5':
 
32
        case '6': case '7':
 
33
        case '8': case '9':
 
34
          return DIGIT;
 
35
        case '+': case '-':
 
36
          return UOP;
 
37
        case '*': case '/':
 
38
          return OP;
 
39
        case '.':
 
40
          return DOT;
 
41
        case '(':
 
42
          return POP;
 
43
        case ')':
 
44
          return PCL;
 
45
        case ',':
 
46
          return COM;
 
47
        case ' ': case 0:
 
48
          return NULL;
 
49
        default:
 
50
          if ((ch >= 'a' && ch <= 'z') || (ch>= 'A' && ch <= 'Z' )) {
 
51
            return ALPHA;
 
52
          }
 
53
        assert_not_reached ();
 
54
      }
 
55
    }
 
56
  }
 
57
 
9
58
  public string parser_error_to_string (ParserError e) {
10
59
    switch (e.code) {
11
60
      case (ParserError.NOT_READY):
21
70
    private class Lexer {
22
71
      private bool ready = false;
23
72
      private string? data = null;
 
73
      private size_t data_size = 0;
24
74
      private Array<Token> tokens = null;
 
75
      private char cur_char = 0;
 
76
      private int index = -1;
25
77
 
26
78
      public Lexer (string data) {
27
79
        assert (data.length != 0);
28
80
        this.data = data;
 
81
        this.data_size = data.length;
 
82
        this.cur_char = data[0];
 
83
        this.index = 0;
29
84
        tokens = new Array<Token> ();
 
85
 
30
86
      }
31
87
 
32
88
      public void lex () throws ParserError {
33
 
        
34
 
      }
 
89
        while (this.index <= this.data_size) {
 
90
          
 
91
        }
 
92
        this.ready = true;
 
93
      }
 
94
 
 
95
      private void advance () {
 
96
        if (this.index < this.data_size && this.cur_char != '\0') {
 
97
          this.index++;
 
98
          this.cur_char = this.data[this.index];
 
99
        } else {
 
100
          assert_not_reached ();
 
101
        }
 
102
      }
 
103
      
35
104
 
36
105
      public Array<Token>? get_tokens () throws ParserError {
37
106
        if (!ready) {