File: pvalue.c

package info (click to toggle)
yodl 4.04.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,720 kB
  • sloc: ansic: 7,803; perl: 683; cpp: 570; sh: 411; xml: 190; makefile: 164
file content (36 lines) | stat: -rw-r--r-- 939 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "parser.ih"

        // return value: separating operator
void p_value(register Parser *pp, Term *term)
{
    bool negative = false;

    while (*term->text == '-')              // skip unary minus operators
    {
        negative = !negative;
        ++term->text;
    }

    char *cp = strpbrk(term->text, "+-");   // find an operator

    if (cp == 0)                            // not found
        term->binop = 0;
    else
    {
        term->binop = *cp;              // save it for parser_value
        *cp = 0;                        // end the text for p_compute
    }

    p_compute(pp, term);

    if (negative)                       // negate a negative value
        term->value = -term->value;

    if (cp != 0)                        // found an operator
    {
        *cp = term->binop;              // reset the operator
        term->text = cp + 1;            // next term starts beyond the binop
    }
}