Compiler/Verifying syntax: Difference between revisions
→{{header|Phix}}
(→{{header|Go}}: Further tweaks and examples.) |
|||
Line 511:
procedure cmp_expr()
if tok=={IDENT,"not"} then next_token() end if
next_token()▼
sum_expr()
▲ if not find(tok,{{SYMBOL,"="},{SYMBOL,"<"}}) then exit end if
▲ next_token()
▲ end while
end procedure
Line 548:
constant tests = {
"3 + not 5",
"3 + (not 5)",
"(42 + 3",
" not 3 < 4 or (true or 3 / 4 + 8 * 5 - 5 * 2 < 56) and 4 * 3 < 12 or not true",
" and 3 < 2",
"not 7 < 2",
"2 < 3 < 4",
"2 < foobar - 3 < 4",
"2 < foobar and 3 < 4",
"4 * (32 - 16) + 9 = 73",
"235 76 + 1",
"true or false = not true",
"not true = false",
"a + b = not c and false",
"a + b = (not c) and false",
"a + b = (not c and false)",
"ab_c / bd2 or < e_f7",
"g not = h",
"
"i++",
"j & k",
"l or _m"}
printf(1,"Verify Syntax:\n")
for i=1 to length(tests) do
verify_syntax(tests[i])
Line 569 ⟶ 578:
Note that "= not c" fails, whereas "= (not c)" passes, see talk page.
<pre>
Verify Syntax:
(42 + 3 ==> fail [tok={"ERROR",") expected"}]▼
3 +
not 3 < 4 or (true or 3 / 4 + 8 *
2 < foobar and 3 <
4 * (32 - 16) + 9 = 73 ==> true
â??®tâ??® = false ==> fail [tok={"ERROR",`invalid [{"ERROR","illegal char (â??/195)"}]`}]▼
235 76 +
true or false = not
not true = false ==> true
l or _m ==> fail [tok={"ERROR",`invalid [{"ERROR","identifiers may not start with _"}]`}]▼
a + b = not c and false ==> false [tok={"IDENT","c"}]
a + b = (not c) and false ==> true
a + b = (not c and false) ==> true
ab_c / bd2 or < e_f7 ==> false [tok={"ERROR",`invalid [{"SYMBOL","<"}]`}]
g not = h ==> false [tok={"IDENT","not"}]
▲
i++ ==> false [tok={"ERROR",`invalid [{"SYMBOL","+"}]`}]
</pre>
|