File: toy.nex

package info (click to toggle)
golang-github-blynn-nex 0.0.0%2Bgit.2021.03.30.1a3320dab9-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 232 kB
  • sloc: yacc: 60; makefile: 22; sh: 4
file content (22 lines) | stat: -rw-r--r-- 855 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/[0-9]+/          { println("An integer:", txt()) }
/[0-9]+\.[0-9]*/  { println("A float:", txt()) }
/if|then|begin|end|procedure|function/
                  { println("A keyword:", txt()) }
/[a-z][a-z0-9]*/  { println("An identifier:", txt()) }
/\+|-|\*|\//      { println("An operator:", txt()) }
/[ \t\n]+/        { /* eat up whitespace */ }
/./               { println("Unrecognized character:", txt()) }
/{[^\{\}\n]*}/    { /* eat up one-line comments */ }
//
package main
import "os"
func main() {
  lex := NewLexer(os.Stdin)
  txt := func() string { return lex.Text() }
  NN_FUN(lex)
  // I changed a regex because the original appears to be wrong:
  //   "{"[\^{}}\n]*"}"     /* eat up one-line comments */
  //
  // The original has a few other bugs, e.g. a missing '<' before "math.h",
  // and a missing noyywrap option prevents compilation.
}