Compiler/Verifying syntax: Difference between revisions

→‎{{header|Go}}: Another RE tweak and examples aligned with those of Phix entry.
(→‎{{header|C}}: Changed to <lang C> so syntax highlighting works properly.)
(→‎{{header|Go}}: Another RE tweak and examples aligned with those of Phix entry.)
Line 423:
re2 = regexp.MustCompile(`\b_\w*\b`)
re3 = regexp.MustCompile(`[=<+*/-]\s*not`)
re4 = regexp.MustCompile(`(=|<)\s*[^(=< ]+\s*([=<+*/-])`)
)
 
Line 458:
func main() {
exprs := []string{
"$",
"one",
"either or both",
"a + 1",
"a + b < c",
"a = b",
"a or b = c",
"3 + not 5",
"3 + (not 5)",
"(42 + 3",
"(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 < (3 < 4)",
"2 < foobar - 3 < 4",
"2 < foobar and 3 < 4",
Line 470 ⟶ 479:
"235 76 + 1",
"true or false = not true",
"true or false = (not true)",
"not true or false = false",
"not true = false",
"a + b = not c and false",
Line 480 ⟶ 491:
"j & k",
"l or _m",
}
 
for _, expr := range exprs {
fmt.Printf("Statement to verify: %q\n", expr)
Line 504 ⟶ 515:
{{out}}
<pre>
Statement to verify: "$"
"false" -> invalid character '$' found
 
Statement to verify: "one"
"true"
 
Statement to verify: "either or both"
"true"
 
Statement to verify: "a + 1"
"true"
 
Statement to verify: "a + b < c"
"true"
 
Statement to verify: "a = b"
"true"
 
Statement to verify: "a or b = c"
"true"
 
Statement to verify: "3 + not 5"
"false" -> expected operand, found 'not'
Line 512 ⟶ 544:
Statement to verify: "(42 + 3"
"false" -> expected ')', found newline
 
Statement to verify: "(42 + 3)"
"true"
 
Statement to verify: " not 3 < 4 or (true or 3 / 4 + 8 * 5 - 5 * 2 < 56) and 4 * 3 < 12 or not true"
Line 524 ⟶ 559:
Statement to verify: "2 < 3 < 4"
"false" -> operator '<' is non-associative
 
Statement to verify: "2 < (3 < 4)"
"true"
 
Statement to verify: "2 < foobar - 3 < 4"
Line 539 ⟶ 577:
Statement to verify: "true or false = not true"
"false" -> expected operand, found 'not'
 
Statement to verify: "true or false = (not true)"
"true"
 
Statement to verify: "not true or false = false"
"true"
 
Statement to verify: "not true = false"
9,485

edits